This commit is contained in:
Heiko Joerg Schick
2023-12-14 19:58:35 +01:00
parent 023a8a202b
commit 909ae9a233
+3 -2
View File
@@ -89,10 +89,10 @@ export const OpenAIStream = async (
const onParse = (event: ParsedEvent | ReconnectInterval) => { const onParse = (event: ParsedEvent | ReconnectInterval) => {
if (event.type === 'event') { if (event.type === 'event') {
const data = event.data; const data = event.data;
if (data !== '[DONE]') {
try { try {
const json = JSON.parse(data); const json = JSON.parse(data);
if (json.choices[0].finish_reason != null) { if (json.choices[0].finish_reason != null || json.choices[0].finish_details != null) {
controller.close(); controller.close();
return; return;
} }
@@ -103,6 +103,7 @@ export const OpenAIStream = async (
controller.error(e); controller.error(e);
} }
} }
}
}; };
const parser = createParser(onParse); const parser = createParser(onParse);