From 7449634290cc9b508067c0d1d843797328a0c4bc Mon Sep 17 00:00:00 2001 From: Arman Ordookhani Date: Fri, 26 Apr 2024 15:37:18 +0200 Subject: [PATCH] Fix OpenRouter hearbeats breaking streaming --- src/lib/apis/streaming/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/apis/streaming/index.ts b/src/lib/apis/streaming/index.ts index 5b89a4668..a0d12c31a 100644 --- a/src/lib/apis/streaming/index.ts +++ b/src/lib/apis/streaming/index.ts @@ -31,6 +31,10 @@ async function* openAIStreamToIterator( console.log(line); if (line === 'data: [DONE]') { yield { done: true, value: '' }; + } 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 { const data = JSON.parse(line.replace(/^data: /, '')); console.log(data);