Unverified Commit 81fb53e7 authored by Timothy Jaeryang Baek's avatar Timothy Jaeryang Baek Committed by GitHub
Browse files

Merge pull request #1780 from cheahjs/fix/harden-streaming

fix: harden openai streaming parsing
parents add5269b 615e9e34
......@@ -36,10 +36,14 @@ async function* openAIStreamToIterator(
// OpenRouter sends heartbeats like ": OPENROUTER PROCESSING"
continue
} else {
const data = JSON.parse(line.replace(/^data: /, ''));
console.log(data);
try {
const data = JSON.parse(line.replace(/^data: /, ''));
console.log(data);
yield { done: false, value: data.choices[0].delta.content ?? '' };
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