Commit 510afab3 authored by Jun Siang Cheah's avatar Jun Siang Cheah
Browse files

fix: catch any errors parsing openai sse events

parent e9ba8d74
......@@ -32,10 +32,14 @@ async function* openAIStreamToIterator(
if (line === 'data: [DONE]') {
yield { done: true, value: '' };
} else {
try {
const data = JSON.parse(line.replace(/^data: /, ''));
console.log(data);
yield { done: false, value: data.choices[0].delta.content ?? '' };
} catch (e) {
console.error('Error extracting delta from SSE event:', e);
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment