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