Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
JYC0413 committed Jan 17, 2024
1 parent 3571227 commit 7e6b01b
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
});

Expand Down

0 comments on commit 7e6b01b

Please sign in to comment.