From fe3654a0306bc215b0b69ab9b45bc4e1f4c24421 Mon Sep 17 00:00:00 2001 From: yorkeking <34937020+yorkeking@users.noreply.github.com> Date: Tue, 4 Apr 2023 01:57:05 +0800 Subject: [PATCH] Update route.ts --- app/api/chat-stream/route.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/api/chat-stream/route.ts b/app/api/chat-stream/route.ts index e7bdfc5fb..f33175543 100644 --- a/app/api/chat-stream/route.ts +++ b/app/api/chat-stream/route.ts @@ -8,6 +8,15 @@ async function createStream(req: NextRequest) { const res = await requestOpenai(req); + const contentType = res.headers.get("Content-Type") ?? ""; + if (!contentType.includes("stream")) { + const content = await ( + await res.text() + ).replace(/provided:.*. You/, "provided: ***. You"); + console.log("[Stream] error ", content); + return "```json\n" + content + "```"; + } + const stream = new ReadableStream({ async start(controller) { function onParse(event: any) {