From 0ac4aa31c8c2c816abda44fc323114d3c5ce9862 Mon Sep 17 00:00:00 2001 From: pulsareonbot Date: Mon, 6 Jul 2026 10:24:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(M2.1):=20Web=20=E5=AF=B9=E8=AF=9D=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E7=AB=AF=20(/chat=20=E9=A1=B5=E9=9D=A2=20-=20?= =?UTF-8?q?=E6=96=87=E5=AD=97=E5=AF=B9=E8=AF=9D+=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=88=87=E6=8D=A2+=E6=A8=A1=E5=9E=8B=E7=AE=A1=E7=90=86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/ai/backend.rs | 16 +-- src/plugins/http/chat.html | 284 +++++++++++++++++++++++++++++++++++++ src/plugins/http/routes.rs | 9 ++ 3 files changed, 299 insertions(+), 10 deletions(-) create mode 100644 src/plugins/http/chat.html diff --git a/src/plugins/ai/backend.rs b/src/plugins/ai/backend.rs index fc5c11b..8371d77 100644 --- a/src/plugins/ai/backend.rs +++ b/src/plugins/ai/backend.rs @@ -154,16 +154,12 @@ impl AiBackend for LocalCliBackend { // --single-turn 单轮模式,生成完即退出(否则进交互模式等待 stdin,永远不退出) // --no-warmup 跳过预热(减少延迟) // -sys system prompt(角色人设) - // -p 用户输入(只传当前消息,历史通过 context 另传,V1 简化) + // -p 用户当前消息(V1 不带历史,避免模型回显历史内容) // - // 历史上下文 V1 简化处理:拼到 -p 里(小模型 ctx 1024 有限,只保留最近 2 轮) - let mut prompt = String::new(); - for (role, content) in history.iter().rev().take(4) { - // 逆序取最近 2 轮(4 条消息),正序拼接 - prompt.insert_str(0, &format!("{content}\n")); - } - prompt.push_str(user_message); - + // V1 边界:会话内上下文由 ChatPipeline 的 sessions 维护, + // 但 llama-cli --single-turn 模式每次是独立调用, + // 历史拼接会导致模型把历史当输入回显。V1 简化为无历史单轮对话。 + let _ = history; // V1 不使用历史,参数保留供未来扩展 let tokens = if max_tokens == 0 { 128 } else { max_tokens as u32 }; let output = Command::new(self.llama_cli()) @@ -174,7 +170,7 @@ impl AiBackend for LocalCliBackend { .arg("-sys") .arg(persona) .arg("-p") - .arg(&prompt) + .arg(user_message) .arg("-n") .arg(tokens.to_string()) .arg("-t") diff --git a/src/plugins/http/chat.html b/src/plugins/http/chat.html new file mode 100644 index 0000000..917cd4e --- /dev/null +++ b/src/plugins/http/chat.html @@ -0,0 +1,284 @@ + + + + + +Showen AI 对话 + + + +
+

Showen AI 对话控制端

+
+
对话
+
角色
+
模型
+
+ + +
+
+
+ + +
+
+
+ + +
+
加载中...
+
+ + +
+
+
加载中...
+
+
+ + + + diff --git a/src/plugins/http/routes.rs b/src/plugins/http/routes.rs index de74f5e..f8cacb7 100644 --- a/src/plugins/http/routes.rs +++ b/src/plugins/http/routes.rs @@ -156,6 +156,7 @@ pub(crate) fn build_routes( let api = core_api.or(media_api).or(plugin_api).or(file_api).or(ai_api); root_route() + .or(chat_page_route()) .or(download_route(Arc::clone(&state))) .or(ws_route(tx.clone(), Arc::clone(&state))) .or(api) @@ -179,6 +180,14 @@ fn root_route() -> impl Filter + ) } +/// GET /chat — AI 对话控制端页面 +fn chat_page_route() -> impl Filter + Clone { + warp::path("chat") + .and(warp::path::end()) + .and(warp::get()) + .map(|| warp::reply::html(include_str!("chat.html"))) +} + fn ws_route( tx: mpsc::Sender, state: Arc,