perf: AI 支持引用文件

This commit is contained in:
kuaifan 2025-02-25 20:30:50 +08:00
parent c128c58110
commit a8be330baa

View File

@ -14,7 +14,6 @@ use App\Module\Base;
use App\Module\Doo; use App\Module\Doo;
use App\Module\Ihttp; use App\Module\Ihttp;
use App\Module\TextExtractor; use App\Module\TextExtractor;
use Cache;
use Carbon\Carbon; use Carbon\Carbon;
use DB; use DB;
@ -453,30 +452,35 @@ class BotReceiveMsgTask extends AbstractTask
if (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.41.11", $this->client['version'])) { if (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.41.11", $this->client['version'])) {
$errorContent = '当前客户端版本低所需版本≥v0.41.11)。'; $errorContent = '当前客户端版本低所需版本≥v0.41.11)。';
} }
$attachments = Base::json2array(Cache::get("bot:{$msg->id}:attachments"));
foreach ($attachments as $attachment) {
$command = str_replace($attachment['search'], $attachment['replace'], $command);
$command .= "\n\n" . $attachment['context'];
}
if ($msg->reply_id > 0) { if ($msg->reply_id > 0) {
$replyMsg = WebSocketDialogMsg::find($msg->reply_id); $replyMsg = WebSocketDialogMsg::find($msg->reply_id);
$replyCommand = ''; $replyCommand = null;
if ($replyMsg) { if ($replyMsg) {
$replyCommand = $this->extractCommand($replyMsg, true); switch ($replyMsg->type) {
if ($replyCommand) { case 'text':
$replyCommand = Base::cutStr($replyCommand, 2000); $replyCommand = $this->extractCommand($replyMsg, true);
$replyCommand = <<<EOF if ($replyCommand) {
<quoted_content> $replyCommand = Base::cutStr($replyCommand, 20000);
{$replyCommand} }
</quoted_content> break;
case 'file':
The content within the above quoted_content tags is a citation. $msgData = Base::json2array($replyMsg->getRawOriginal('msg'));
$replyCommand = TextExtractor::getFileContent(public_path($msgData['path']));
EOF; break;
} }
} }
$command = $replyCommand . $command; if ($replyCommand) {
$command = <<<EOF
<quoted_content>
{$replyCommand}
</quoted_content>
The content within the above quoted_content tags is a citation.
{$command}
EOF;
}
} }
$this->AIGenerateSystemMessageOrBeforeText($msg->userid, $dialog, $extras); $this->AIGenerateSystemMessageOrBeforeText($msg->userid, $dialog, $extras);
$webhookUrl = "{$serverUrl}/ai/chat"; $webhookUrl = "{$serverUrl}/ai/chat";