From 7e6b01b5fe8ba9def0309c93bab8d179f5112064 Mon Sep 17 00:00:00 2001 From: JYC0413 Date: Wed, 17 Jan 2024 23:33:03 +0800 Subject: [PATCH] revert --- components/Chat/Chat.tsx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index 916bc63..b0733c0 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -145,25 +145,36 @@ export const Chat = memo(({stopConversationRef}: Props) => { let isShowFirst = true; let queue: any[] = []; let text = ''; + let notFinishData = "" while (!done || queue.length !== 0) { const {value} = await reader.read(); let chunkValue = decoder.decode(value); - const regex = /(}(?={"id":"))/; + const regex = /}(?={)/g; const parts = chunkValue.split(regex); - console.log(parts) let objects: any[] = [] parts.forEach(part => { + let isError = false part = part.trim(); if (!part.startsWith('{')) { - part = '{' + part; + if(notFinishData){ + part = notFinishData + part + notFinishData = "" + }else { + isError = true + } } if (!part.endsWith('}')) { - part = part + '}'; + notFinishData = part + isError = true } - try { - objects.push(JSON.parse(part)); - }catch (e) { - console.log("error JSON",part); + if(!isError){ + try { + objects.push(JSON.parse(part)); + }catch (e) { + console.log("error JSON",part); + } + }else { + console.log("isError",part) } });