Merge pull request #1773 from Rmaan/fix-openrouter-streaming

Fixed OpenRouter heart beats breaking streaming
This commit is contained in:
Timothy Jaeryang Baek 2024-04-26 11:05:52 -07:00 committed by GitHub
commit add5269b89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,10 @@ async function* openAIStreamToIterator(
console.log(line); console.log(line);
if (line === 'data: [DONE]') { if (line === 'data: [DONE]') {
yield { done: true, value: '' }; yield { done: true, value: '' };
} else if (line.startsWith(':')) {
// Events starting with : are comments https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format
// OpenRouter sends heartbeats like ": OPENROUTER PROCESSING"
continue
} else { } else {
const data = JSON.parse(line.replace(/^data: /, '')); const data = JSON.parse(line.replace(/^data: /, ''));
console.log(data); console.log(data);