Browse Source

fix: #507 break cjk chars in stream mode

Yidadaa 1 year ago
parent
commit
7aee53ea05
2 changed files with 2 additions and 2 deletions
  1. 1 1
      app/api/chat-stream/route.ts
  2. 1 1
      app/requests.ts

+ 1 - 1
app/api/chat-stream/route.ts

@@ -40,7 +40,7 @@ async function createStream(req: NextRequest) {
 
       const parser = createParser(onParse);
       for await (const chunk of res.body as any) {
-        parser.feed(decoder.decode(chunk));
+        parser.feed(decoder.decode(chunk, { stream: true }));
       }
     },
   });

+ 1 - 1
app/requests.ts

@@ -171,7 +171,7 @@ 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: true });
         responseText += text;
 
         const done = !content || content.done;