From 368fae5f32d21f07675786070858e932265d481b Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sat, 22 Feb 2025 20:27:10 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=94=AF=E6=8C=81=E5=9C=A8AI=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E4=B8=AD=E7=9B=B4=E6=8E=A5=E5=BC=95=E7=94=A8=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8F=90=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Tasks/BotReceiveMsgTask.php | 47 +++++++++++++++------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/app/Tasks/BotReceiveMsgTask.php b/app/Tasks/BotReceiveMsgTask.php index 03e9f3ebd..d577df61a 100644 --- a/app/Tasks/BotReceiveMsgTask.php +++ b/app/Tasks/BotReceiveMsgTask.php @@ -452,13 +452,10 @@ class BotReceiveMsgTask extends AbstractTask if (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.41.11", $this->client['version'])) { $errorContent = '当前客户端版本低(所需版本≥v0.41.11)。'; } - $attachments = Cache::get("bot:{$msg->id}:attachments"); - if ($attachments) { - $command = <<id}:attachments")); + foreach ($attachments as $attachment) { + $command = str_replace($attachment['search'], $attachment['replace'], $command); + $command .= "\n\n" . $attachment['context']; } if ($msg->reply_id > 0) { @@ -469,11 +466,11 @@ class BotReceiveMsgTask extends AbstractTask if ($replyCommand) { $replyCommand = Base::cutStr($replyCommand, 2000); $replyCommand = << + {$replyCommand} - + - 上述 quoted 标签内的内容为引用。 + The content within the above quoted_content tags is a citation. EOF; } @@ -586,24 +583,23 @@ class BotReceiveMsgTask extends AbstractTask foreach ($taskIds as $index => $taskId) { $taskInfo = ProjectTask::with(['content'])->whereId($taskId)->first(); if ($taskInfo) { + $taskName = addslashes($taskInfo->name) . " (ID:{$taskId})"; $taskContext = implode("\n", $taskInfo->AIContext()); - $attachments[] = <<name}】 - {$taskContext} - EOF; } else { - $attachments[] = << $replName, + 'replace' => "{$replName} (see below for task_content tag)", + 'context' => "\n{$taskContext}\n", + ]; + $original = str_replace($match[0][$index], $replName, $original); } } if ($attachments) { - Cache::put("bot:{$msg->id}:attachments", implode("\n\n", $attachments), 60); + Cache::put("bot:{$msg->id}:attachments", Base::array2json($attachments), 60); } $command = trim(strip_tags($original)); } @@ -666,12 +662,13 @@ class BotReceiveMsgTask extends AbstractTask case 'task': $taskInfo = ProjectTask::with(['content'])->whereDialogId($dialog->id)->first(); if ($taskInfo) { - $taskText = "当前我在任务【{$taskInfo->name}】中"; + $taskName = addslashes($taskInfo->name) . " (ID:{$taskInfo->id})"; $taskContext = implode("\n", $taskInfo->AIContext()); if ($taskContext) { - $taskText .= "\n{$taskContext}"; + $before_text[] = "当前我在任务 '{$taskName}' (see below for task_content tag) 对话中\n\n\n{$taskContext}\n"; + } else { + $before_text[] = "当前我在任务 '{$taskName}' 对话中"; } - $before_text[] = $taskText; $before_text[] = <<