🐛 fix(ai-chat): 修复 DeepSeek 回显引导提示词并优化收敛策略

- 删除 ≥5 轮注入 system 提示的逻辑(部分模型会将其当作对话内容输出)
- 改为 ≥10 轮时移除 tools 参数,从物理层面终止工具调用循环
This commit is contained in:
Syngnat
2026-04-02 11:04:57 +08:00
parent b022cd63e5
commit fbda6917f7
4 changed files with 5 additions and 9 deletions

View File

@@ -1057,19 +1057,15 @@ SELECT * FROM users WHERE status = 1;
const allMessages = [...sysMessages, ...finalMessagesPayload];
// 【轮次感知引导】当工具调用轮次较多时,注入 system 提示引导模型尽快给出答案
if (totalToolRoundRef.current >= 5) {
allMessages.push({
role: 'system',
content: `注意:你已经进行了 ${totalToolRoundRef.current} 轮工具调用。如果你已经获得了足够的信息来回答用户的问题,请立即给出最终答案,不要继续调用工具。只有在确实缺少关键信息时才继续调用工具。`
});
}
// 【软收敛】超过 10 轮工具调用后,不再传递 tools 参数,从物理层面强制模型只能用文本回答
const SOFT_LIMIT_ROUNDS = 10;
const chainTools = totalToolRoundRef.current >= SOFT_LIMIT_ROUNDS ? [] : LOCAL_TOOLS;
const Service = (window as any).go?.aiservice?.Service;
if (Service?.AIChatStream) {
await Service.AIChatStream(sid, allMessages, LOCAL_TOOLS);
await Service.AIChatStream(sid, allMessages, chainTools);
} else if (Service?.AIChatSend) {
const result = await Service.AIChatSend(allMessages, LOCAL_TOOLS);
const result = await Service.AIChatSend(allMessages, chainTools);
const errR = result?.error || '未知错误';
const errC = sanitizeErrorMsg(errR);
useStore.getState().addAIChatMessage(sid, {

0
frontend/wailsjs/runtime/package.json Executable file → Normal file
View File

0
frontend/wailsjs/runtime/runtime.d.ts vendored Executable file → Normal file
View File

0
frontend/wailsjs/runtime/runtime.js Executable file → Normal file
View File