|
@@ -2,7 +2,7 @@ import type { ChatRequest, ChatResponse } 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 TIME_OUT_MS = 60000;
|
|
|
|
|
|
const makeRequestParam = (
|
|
const makeRequestParam = (
|
|
messages: Message[],
|
|
messages: Message[],
|
|
@@ -167,15 +167,14 @@ export async function requestChatStream(
|
|
options?.onController?.(controller);
|
|
options?.onController?.(controller);
|
|
|
|
|
|
while (true) {
|
|
while (true) {
|
|
- // handle time out, will stop if no response in 10 secs
|
|
|
|
const resTimeoutId = setTimeout(() => finish(), TIME_OUT_MS);
|
|
const resTimeoutId = setTimeout(() => finish(), TIME_OUT_MS);
|
|
const content = await reader?.read();
|
|
const content = await reader?.read();
|
|
clearTimeout(resTimeoutId);
|
|
clearTimeout(resTimeoutId);
|
|
-
|
|
|
|
|
|
+
|
|
if (!content || !content.value) {
|
|
if (!content || !content.value) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
const text = decoder.decode(content.value, { stream: true });
|
|
const text = decoder.decode(content.value, { stream: true });
|
|
responseText += text;
|
|
responseText += text;
|
|
|
|
|
|
@@ -235,6 +234,14 @@ export const ControllerPool = {
|
|
controller?.abort();
|
|
controller?.abort();
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ stopAll() {
|
|
|
|
+ Object.values(this.controllers).forEach((v) => v.abort());
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ hasPending() {
|
|
|
|
+ return Object.values(this.controllers).length > 0;
|
|
|
|
+ },
|
|
|
|
+
|
|
remove(sessionIndex: number, messageId: number) {
|
|
remove(sessionIndex: number, messageId: number) {
|
|
const key = this.key(sessionIndex, messageId);
|
|
const key = this.key(sessionIndex, messageId);
|
|
delete this.controllers[key];
|
|
delete this.controllers[key];
|