fix: AI 请求加 170 秒超时保护,防止服务端无响应时无限挂起
This commit is contained in:
1 parent
a4cccbc858
commit
6f008ed8c0
1 file changed
+1
@@ -19,6 +19,7 @@ export async function chatCompletion(messages: ChatMessage[], options: { tempera
|
|||||||
const config = requireAiConfig();
|
const config = requireAiConfig();
|
||||||
const base = config.baseUrl.replace(/\/+$/, "");
|
const base = config.baseUrl.replace(/\/+$/, "");
|
||||||
const response = await fetch(base + "/chat/completions", {
|
const response = await fetch(base + "/chat/completions", {
|
||||||
|
signal: AbortSignal.timeout(170000),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json", Authorization: "Bearer " + config.apiKey },
|
headers: { "Content-Type": "application/json", Authorization: "Bearer " + config.apiKey },
|
||||||
body: JSON.stringify({ model: config.model, messages, temperature: options.temperature ?? 0.3 })
|
body: JSON.stringify({ model: config.model, messages, temperature: options.temperature ?? 0.3 })
|
||||||
|
|||||||
Reference in new issue
Block a user