retry
This commit is contained in:
parent
422a4b9d71
commit
9ad61eef3b
@ -70,6 +70,7 @@ async function log(level: string, category: string, data: any) {
|
|||||||
try {
|
try {
|
||||||
if (!existsSync(LOG_DIR)) await mkdir(LOG_DIR, { recursive: true });
|
if (!existsSync(LOG_DIR)) await mkdir(LOG_DIR, { recursive: true });
|
||||||
await appendFile(`${LOG_DIR}/chat-${ts.slice(0, 10)}.log`, line, "utf-8");
|
await appendFile(`${LOG_DIR}/chat-${ts.slice(0, 10)}.log`, line, "utf-8");
|
||||||
|
await appendFile(`${LOG_DIR}/global.log`, line, "utf-8");
|
||||||
} catch {
|
} catch {
|
||||||
/* 忽略日志写入失败 */
|
/* 忽略日志写入失败 */
|
||||||
}
|
}
|
||||||
@ -457,8 +458,9 @@ async function runConversation(initialMessages: ChatMsg[], res: any, fromApprova
|
|||||||
messages: messages.map((m) => ({ role: m.role, content: clip(m.content, 800) })),
|
messages: messages.map((m) => ({ role: m.role, content: clip(m.content, 800) })),
|
||||||
});
|
});
|
||||||
|
|
||||||
// 工具循环(最多 5 轮避免死循环)
|
// 工具循环(最多 10 轮避免死循环)
|
||||||
for (let round = 0; round < 5; round++) {
|
for (let round = 0; round < 10; round++) {
|
||||||
|
log("debug", "round_start", { round: round + 1, pendingMessages: messages.length });
|
||||||
const gen = streamLLM(messages);
|
const gen = streamLLM(messages);
|
||||||
let content = "";
|
let content = "";
|
||||||
let toolCall: any = null;
|
let toolCall: any = null;
|
||||||
@ -475,6 +477,7 @@ async function runConversation(initialMessages: ChatMsg[], res: any, fromApprova
|
|||||||
sseSend(res, { type: "token", content: "\n\n⚠️ " + ev.content });
|
sseSend(res, { type: "token", content: "\n\n⚠️ " + ev.content });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log("debug", "assistant_round", { round: round + 1, content: clip(content, 1000), wantsTool: !!toolCall });
|
||||||
|
|
||||||
if (errored) { sseSend(res, { type: "done" }); res.end(); return; }
|
if (errored) { sseSend(res, { type: "done" }); res.end(); return; }
|
||||||
|
|
||||||
@ -526,6 +529,7 @@ async function runConversation(initialMessages: ChatMsg[], res: any, fromApprova
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log("warn", "round_limit", { round: 10 });
|
||||||
sseSend(res, { type: "token", content: "\n[达到最大工具调用轮数]" });
|
sseSend(res, { type: "token", content: "\n[达到最大工具调用轮数]" });
|
||||||
sseSend(res, { type: "done" });
|
sseSend(res, { type: "done" });
|
||||||
res.end();
|
res.end();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user