fix: AI 请求加 170 秒超时保护,防止服务端无响应时无限挂起

This commit is contained in:
yu 2026-10-29 11:39:50 +08:00
parent a4cccbc858
commit 6f008ed8c0

View File

@ -19,6 +19,7 @@ export async function chatCompletion(messages: ChatMessage[], options: { tempera
const config = requireAiConfig();
const base = config.baseUrl.replace(/\/+$/, "");
const response = await fetch(base + "/chat/completions", {
signal: AbortSignal.timeout(170000),
method: "POST",
headers: { "Content-Type": "application/json", Authorization: "Bearer " + config.apiKey },
body: JSON.stringify({ model: config.model, messages, temperature: options.temperature ?? 0.3 })