From 28a9cddb3d627192817901ee8370797416e47506 Mon Sep 17 00:00:00 2001 From: zgs225 Date: Thu, 6 Apr 2023 10:24:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E6=88=AA=E6=96=AD=E5=AF=BC=E8=87=B4=E7=9A=84=E5=AE=BD=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B9=B1=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/requests.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/requests.ts b/app/requests.ts index 8462f2694..f72b6f43c 100644 --- a/app/requests.ts +++ b/app/requests.ts @@ -159,7 +159,10 @@ export async function requestChatStream( if (res.ok) { const reader = res.body?.getReader(); - const decoder = new TextDecoder(); + const decoder = new TextDecoder("utf-8", { + fatal: true, + ignoreBOM: true, + }); options?.onController?.(controller); @@ -168,13 +171,12 @@ export async function requestChatStream( const resTimeoutId = setTimeout(() => finish(), TIME_OUT_MS); const content = await reader?.read(); clearTimeout(resTimeoutId); - const text = decoder.decode(content?.value); + const text = decoder.decode(content?.value, { stream: !content?.done }); responseText += text; - const done = !content || content.done; options?.onMessage(responseText, false); - if (done) { + if (content?.done) { break; } }