From e00652ce86c5ac09192de255e5a8863651d7a73e Mon Sep 17 00:00:00 2001 From: "ShengYan, Zhang" Date: Wed, 17 May 2023 08:50:50 +0800 Subject: [PATCH] fix: #1533 handle non-stream type --- app/client/platforms/openai.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index cc8b5b6f..63587440 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -3,7 +3,10 @@ import { useAccessStore, useAppConfig, useChatStore } from "@/app/store"; import { ChatOptions, getHeaders, LLMApi, LLMUsage } from "../api"; import Locale from "../../locales"; -import { fetchEventSource } from "@microsoft/fetch-event-source"; +import { + EventStreamContentType, + fetchEventSource, +} from "@microsoft/fetch-event-source"; import { prettyObject } from "@/app/utils/format"; export class ChatGPTApi implements LLMApi { @@ -79,6 +82,13 @@ export class ChatGPTApi implements LLMApi { ...chatPayload, async onopen(res) { clearTimeout(requestTimeoutId); + if ( + res.ok && + res.headers.get("content-type") !== EventStreamContentType + ) { + responseText += await res.clone().json(); + return finish(); + } if (res.status === 401) { let extraInfo = { error: undefined }; try {