Fix stream error parsing when using Smooth Streaming
This commit is contained in:
parent
ecc638a76d
commit
813476d72a
|
@ -227,7 +227,7 @@ async function* parseStreamData(json) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
yield null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,6 +243,12 @@ export class SmoothEventSourceStream extends EventSourceStream {
|
||||||
const data = event.data;
|
const data = event.data;
|
||||||
try {
|
try {
|
||||||
const hasFocus = document.hasFocus();
|
const hasFocus = document.hasFocus();
|
||||||
|
|
||||||
|
if (data === '[DONE]') {
|
||||||
|
lastStr = '';
|
||||||
|
return controller.enqueue(event);
|
||||||
|
}
|
||||||
|
|
||||||
const json = JSON.parse(data);
|
const json = JSON.parse(data);
|
||||||
|
|
||||||
if (!json) {
|
if (!json) {
|
||||||
|
@ -261,7 +267,8 @@ export class SmoothEventSourceStream extends EventSourceStream {
|
||||||
lastStr = parsed.chunk;
|
lastStr = parsed.chunk;
|
||||||
hasFocus && await eventSource.emit(event_types.SMOOTH_STREAM_TOKEN_RECEIVED, parsed.chunk);
|
hasFocus && await eventSource.emit(event_types.SMOOTH_STREAM_TOKEN_RECEIVED, parsed.chunk);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.error('Smooth Streaming parsing error', error);
|
||||||
controller.enqueue(event);
|
controller.enqueue(event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue