mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-09 03:26:38 +08:00
feture: update request timeout setting
This commit is contained in:
parent
03b3f16472
commit
9b99e177f5
@ -423,6 +423,24 @@ export function Settings(props: { closeSettings: () => void }) {
|
||||
></input>
|
||||
</SettingItem>
|
||||
|
||||
<SettingItem
|
||||
title={Locale.Settings.RequestTimeOut.Title}
|
||||
subTitle={Locale.Settings.RequestTimeOut.SubTitle}
|
||||
>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={600}
|
||||
value={config.requestTimeOut}
|
||||
onChange={(e) =>
|
||||
updateConfig(
|
||||
(config) =>
|
||||
(config.requestTimeOut = e.currentTarget.valueAsNumber),
|
||||
)
|
||||
}
|
||||
></input>
|
||||
</SettingItem>
|
||||
|
||||
<SettingItem
|
||||
title={Locale.Settings.CompressThreshold.Title}
|
||||
subTitle={Locale.Settings.CompressThreshold.SubTitle}
|
||||
|
@ -102,6 +102,10 @@ const cn = {
|
||||
Title: "历史消息长度压缩阈值",
|
||||
SubTitle: "当未压缩的历史消息超过该值时,将进行压缩",
|
||||
},
|
||||
RequestTimeOut: {
|
||||
Title: "请求响应超时时间(单位/秒)",
|
||||
SubTitle: "在设置时间内未获取响应将停止请求",
|
||||
},
|
||||
Token: {
|
||||
Title: "API Key",
|
||||
SubTitle: "使用自己的 Key 可绕过密码访问限制",
|
||||
|
@ -105,6 +105,11 @@ const en: LocaleType = {
|
||||
SubTitle:
|
||||
"Will compress if uncompressed messages length exceeds the value",
|
||||
},
|
||||
RequestTimeOut: {
|
||||
Title: "Request Response Timeout(unit/seconds)",
|
||||
SubTitle:
|
||||
"If no response is received within the set time, the request will be stopped",
|
||||
},
|
||||
Token: {
|
||||
Title: "API Key",
|
||||
SubTitle: "Use your key to ignore access code limit",
|
||||
|
@ -105,6 +105,11 @@ const es: LocaleType = {
|
||||
SubTitle:
|
||||
"Se comprimirán los mensajes si la longitud de los mensajes no comprimidos supera el valor",
|
||||
},
|
||||
RequestTimeOut: {
|
||||
Title: "Tiempo de espera de respuesta de solicitud(unidad/segundos)",
|
||||
SubTitle:
|
||||
"Si no se recibe respuesta dentro del tiempo establecido, la solicitud se detendrá",
|
||||
},
|
||||
Token: {
|
||||
Title: "Clave de API",
|
||||
SubTitle: "Utiliza tu clave para ignorar el límite de código de acceso",
|
||||
|
@ -105,6 +105,11 @@ const it: LocaleType = {
|
||||
SubTitle:
|
||||
"Comprimerà se la lunghezza dei messaggi non compressi supera il valore",
|
||||
},
|
||||
RequestTimeOut: {
|
||||
Title: "Tempo limite di risposta della richiesta(unità/secondi)",
|
||||
SubTitle:
|
||||
"La richiesta si interromperà se non viene ricevuta risposta entro il tempo stabilito",
|
||||
},
|
||||
Token: {
|
||||
Title: "Chiave API",
|
||||
SubTitle:
|
||||
|
@ -102,6 +102,10 @@ const tw: LocaleType = {
|
||||
Title: "歷史訊息長度壓縮閾值",
|
||||
SubTitle: "當未壓縮的歷史訊息超過該值時,將進行壓縮",
|
||||
},
|
||||
RequestTimeOut: {
|
||||
Title: "請求響應超時時間(單位/秒)",
|
||||
SubTitle: "若在設定時間內未取得響應,將停止該請求",
|
||||
},
|
||||
Token: {
|
||||
Title: "API Key",
|
||||
SubTitle: "使用自己的 Key 可規避授權訪問限制",
|
||||
|
@ -2,8 +2,6 @@ import type { ChatRequest, ChatReponse } from "./api/openai/typing";
|
||||
import { Message, ModelConfig, useAccessStore, useChatStore } from "./store";
|
||||
import { showToast } from "./components/ui-lib";
|
||||
|
||||
const TIME_OUT_MS = 30000;
|
||||
|
||||
const makeRequestParam = (
|
||||
messages: Message[],
|
||||
options?: {
|
||||
@ -135,8 +133,10 @@ export async function requestChatStream(
|
||||
console.log("[Request] ", req);
|
||||
|
||||
const controller = new AbortController();
|
||||
const reqTimeoutId = setTimeout(() => controller.abort(), TIME_OUT_MS);
|
||||
|
||||
const reqTimeoutId = setTimeout(
|
||||
() => controller.abort(),
|
||||
useChatStore.getState().config.requestTimeOut * 1000,
|
||||
);
|
||||
try {
|
||||
const res = await fetch("/api/chat-stream", {
|
||||
method: "POST",
|
||||
@ -165,7 +165,10 @@ export async function requestChatStream(
|
||||
|
||||
while (true) {
|
||||
// handle time out, will stop if no response in 10 secs
|
||||
const resTimeoutId = setTimeout(() => finish(), TIME_OUT_MS);
|
||||
const resTimeoutId = setTimeout(
|
||||
() => finish(),
|
||||
useChatStore.getState().config.requestTimeOut * 1000,
|
||||
);
|
||||
const content = await reader?.read();
|
||||
clearTimeout(resTimeoutId);
|
||||
const text = decoder.decode(content?.value);
|
||||
|
@ -45,6 +45,7 @@ export enum Theme {
|
||||
export interface ChatConfig {
|
||||
historyMessageCount: number; // -1 means all
|
||||
compressMessageLengthThreshold: number;
|
||||
requestTimeOut: number;
|
||||
sendBotMessages: boolean; // send bot's message or not
|
||||
submitKey: SubmitKey;
|
||||
avatar: string;
|
||||
@ -136,6 +137,7 @@ const DEFAULT_CONFIG: ChatConfig = {
|
||||
sendBotMessages: true as boolean,
|
||||
submitKey: SubmitKey.CtrlEnter as SubmitKey,
|
||||
avatar: "1f603",
|
||||
requestTimeOut: 30,
|
||||
fontSize: 14,
|
||||
theme: Theme.Auto as Theme,
|
||||
tightBorder: false,
|
||||
|
Loading…
Reference in New Issue
Block a user