feat: stop all stale messages
This commit is contained in:
parent
98b699c483
commit
736c66f46a
@ -25,10 +25,6 @@ export async function requestOpenai(req: NextRequest) {
|
||||
console.log("[Org ID]", process.env.OPENAI_ORG_ID);
|
||||
}
|
||||
|
||||
if (!authValue || !authValue.startsWith("Bearer sk-")) {
|
||||
console.error("[OpenAI Request] invalid api key provided", authValue);
|
||||
}
|
||||
|
||||
return fetch(`${baseUrl}/${openaiPath}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -53,7 +53,7 @@ import chatStyle from "./chat.module.scss";
|
||||
|
||||
import { ListItem, Modal, showModal } from "./ui-lib";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { LAST_INPUT_KEY, Path } from "../constant";
|
||||
import { LAST_INPUT_KEY, Path, REQUEST_TIMEOUT_MS } from "../constant";
|
||||
import { Avatar } from "./emoji";
|
||||
import { MaskAvatar, MaskConfig } from "./mask";
|
||||
import { useMaskStore } from "../store/mask";
|
||||
@ -487,6 +487,16 @@ export function Chat() {
|
||||
|
||||
// stop response
|
||||
const onUserStop = (messageId: number) => {
|
||||
chatStore.updateCurrentSession((session) => {
|
||||
const stopTiming = Date.now() - REQUEST_TIMEOUT_MS;
|
||||
session.messages.forEach((m) => {
|
||||
// check if should stop all stale messages
|
||||
if (m.streaming && new Date(m.date).getTime() < stopTiming) {
|
||||
m.isError = false;
|
||||
m.streaming = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
ChatControllerPool.stop(sessionIndex, messageId);
|
||||
};
|
||||
|
||||
|
@ -7,7 +7,7 @@ import Locale from "../locales";
|
||||
import { showToast } from "../components/ui-lib";
|
||||
import { ModelType } from "./config";
|
||||
import { createEmptyMask, Mask } from "./mask";
|
||||
import { StoreKey } from "../constant";
|
||||
import { REQUEST_TIMEOUT_MS, StoreKey } from "../constant";
|
||||
import { api, RequestMessage } from "../client/api";
|
||||
import { ChatControllerPool } from "../client/controller";
|
||||
import { prettyObject } from "../utils/format";
|
||||
|
Loading…
x
Reference in New Issue
Block a user