From 9b99e177f53f750af7f1cc1bb8f8006210d191b0 Mon Sep 17 00:00:00 2001 From: jimengdie Date: Thu, 6 Apr 2023 15:47:38 +0800 Subject: [PATCH] feture: update request timeout setting --- app/components/settings.tsx | 18 ++++++++++++++++++ app/locales/cn.ts | 4 ++++ app/locales/en.ts | 5 +++++ app/locales/es.ts | 5 +++++ app/locales/it.ts | 5 +++++ app/locales/tw.ts | 4 ++++ app/requests.ts | 13 ++++++++----- app/store/app.ts | 2 ++ 8 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index a14f6473d..05c757771 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -423,6 +423,24 @@ export function Settings(props: { closeSettings: () => void }) { > + + + updateConfig( + (config) => + (config.requestTimeOut = e.currentTarget.valueAsNumber), + ) + } + > + + 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); diff --git a/app/store/app.ts b/app/store/app.ts index c63fa9d4f..f59b25172 100644 --- a/app/store/app.ts +++ b/app/store/app.ts @@ -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,