From 30d88761b49aa63f1daca991b6698c7c4953047d Mon Sep 17 00:00:00 2001 From: kuaifan Date: Mon, 10 Feb 2025 12:39:36 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20AI=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/DialogController.php | 6 ++++++ app/Models/UserBot.php | 11 +++++++++-- app/Models/WebSocketDialogMsg.php | 4 ++-- ...3329_web_socket_dialog_msgs_add_session_id.php} | 8 ++++---- language/original-api.txt | 2 ++ language/original-web.txt | 3 +++ .../js/pages/manage/components/DialogWrapper.vue | 14 ++++++++++++++ 7 files changed, 40 insertions(+), 8 deletions(-) rename database/migrations/{2025_02_07_163329_web_socket_dialog_msgs_add_session.php => 2025_02_07_163329_web_socket_dialog_msgs_add_session_id.php} (71%) diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index ee3cf5446..ae9ec458c 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -489,6 +489,8 @@ class DialogController extends AbstractController * @apiName msg__list * * @apiParam {Number} dialog_id 对话ID + * @apiParam {Number} [session_id] 会话ID + * - 此参数目前仅和AI的对话有效,AI对话支持新建对话,此参数为会话ID * @apiParam {Number} [msg_id] 消息ID * @apiParam {Number} [position_id] 此消息ID前后的数据 * @apiParam {Number} [prev_id] 此消息ID之前的数据 @@ -514,6 +516,7 @@ class DialogController extends AbstractController $user = User::auth(); // $dialog_id = intval(Request::input('dialog_id')); + $session_id = intval(Request::input('session_id')); $msg_id = intval(Request::input('msg_id')); $position_id = intval(Request::input('position_id')); $prev_id = intval(Request::input('prev_id')); @@ -536,6 +539,9 @@ class DialogController extends AbstractController ->on('read.msg_id', '=', 'web_socket_dialog_msgs.id'); })->where('web_socket_dialog_msgs.dialog_id', $dialog_id); // + if ($session_id > 0) { + $builder->whereSessionId($session_id); + } if ($msg_type) { if ($msg_type === 'tag') { $builder->where('tag', '>', 0); diff --git a/app/Models/UserBot.php b/app/Models/UserBot.php index bedeafb5d..7ec881550 100644 --- a/app/Models/UserBot.php +++ b/app/Models/UserBot.php @@ -205,8 +205,15 @@ class UserBot extends AbstractModel ] ], [ - 'key' => '%3A.clear', - 'label' => Doo::translate('清空上下文') + 'key' => '~ai-chat-new', + 'label' => Doo::translate('开启新对话'), + 'config' => [ + 'model' => $aibotSetting[$match[1] . '_model'] + ] + ], + [ + 'key' => '~ai-chat-history', + 'label' => Doo::translate('历史对话'), ] ]; } diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index c95f215ca..907eb87e5 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -27,7 +27,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property int|null $read 已阅数量 * @property int|null $send 发送数量 * @property int|null $tag 标注会员ID - * @property string|null $session 会话标识符 + * @property int|null $session_id 会话ID * @property int|null $todo 设为待办会员ID * @property int|null $link 是否存在链接 * @property int|null $modify 是否编辑 @@ -70,7 +70,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereReplyId($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereReplyNum($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereSend($value) - * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereSession($value) + * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereSessionId($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereTag($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereTodo($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereType($value) diff --git a/database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session.php b/database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session_id.php similarity index 71% rename from database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session.php rename to database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session_id.php index 9ed726398..4149ddca7 100644 --- a/database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session.php +++ b/database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session_id.php @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class WebSocketDialogMsgsAddSession extends Migration +class WebSocketDialogMsgsAddSessionId extends Migration { /** * Run the migrations. @@ -14,8 +14,8 @@ class WebSocketDialogMsgsAddSession extends Migration public function up() { Schema::table('web_socket_dialog_msgs', function (Blueprint $table) { - if (!Schema::hasColumn('web_socket_dialog_msgs', 'session')) { - $table->string('session', 36)->nullable()->default('')->after('tag')->comment('会话标识符'); + if (!Schema::hasColumn('web_socket_dialog_msgs', 'session_id')) { + $table->bigInteger('session_id')->index()->nullable()->default(0)->after('dialog_type')->comment('会话ID'); } }); } @@ -28,7 +28,7 @@ class WebSocketDialogMsgsAddSession extends Migration public function down() { Schema::table('web_socket_dialog_msgs', function (Blueprint $table) { - $table->dropColumn('session'); + $table->dropColumn('session_id'); }); } } diff --git a/language/original-api.txt b/language/original-api.txt index 6e148d7d1..04469cbac 100644 --- a/language/original-api.txt +++ b/language/original-api.txt @@ -805,3 +805,5 @@ AI机器人不存在 内容不存在 长文本 + +选择模型 diff --git a/language/original-web.txt b/language/original-web.txt index 2718a1229..f486d6f96 100644 --- a/language/original-web.txt +++ b/language/original-web.txt @@ -1927,3 +1927,6 @@ API请求的基础URL路径,如果没有请留空 思考过程 隐藏翻译 重新翻译 + +当前客户端不支持该指令 +默认模型 diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 895722682..f9f382c54 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -1922,6 +1922,20 @@ export default { } break; + // 开启新对话 + case "~ai-chat-new": + if (!this.isAiBot) { + return + } + break; + + // 历史对话 + case "~ai-chat-history": + if (!this.isAiBot) { + return + } + break; + // 发送快捷指令 default: if (/^~/.test(item.key)) {