This commit is contained in:
Heiko Joerg Schick
2023-12-14 19:58:35 +01:00
parent 023a8a202b
commit 909ae9a233
+13 -12
View File
@@ -89,22 +89,23 @@ export const OpenAIStream = async (
const onParse = (event: ParsedEvent | ReconnectInterval) => {
if (event.type === 'event') {
const data = event.data;
try {
const json = JSON.parse(data);
if (json.choices[0].finish_reason != null) {
controller.close();
return;
if (data !== '[DONE]') {
try {
const json = JSON.parse(data);
if (json.choices[0].finish_reason != null || json.choices[0].finish_details != null) {
controller.close();
return;
}
const text = json.choices[0].delta.content;
const queue = encoder.encode(text);
controller.enqueue(queue);
} catch (e) {
controller.error(e);
}
const text = json.choices[0].delta.content;
const queue = encoder.encode(text);
controller.enqueue(queue);
} catch (e) {
controller.error(e);
}
}
};
const parser = createParser(onParse);
for await (const chunk of res.body as any) {