From 6bfaba97e4030ac46beb52115afa54a08b46025b Mon Sep 17 00:00:00 2001 From: thivy Date: Mon, 12 Feb 2024 13:13:06 +1100 Subject: [PATCH] close stream on error and abort --- src/features/chat-page/chat-services/chat-api/open-ai-stream.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/features/chat-page/chat-services/chat-api/open-ai-stream.ts b/src/features/chat-page/chat-services/chat-api/open-ai-stream.ts index 54f0b7363..55f2805f6 100644 --- a/src/features/chat-page/chat-services/chat-api/open-ai-stream.ts +++ b/src/features/chat-page/chat-services/chat-api/open-ai-stream.ts @@ -70,6 +70,7 @@ export const OpenAIStream = (props: { response: "Chat aborted", }; streamResponse(response.type, JSON.stringify(response)); + controller.close(); }) .on("error", async (error) => { console.log("🔴 error", error); @@ -87,6 +88,7 @@ export const OpenAIStream = (props: { }); streamResponse(response.type, JSON.stringify(response)); + controller.close(); }) .on("finalContent", async (content: string) => { await CreateChatMessage({