forked from open-webui/open-webui
Merge pull request #1780 from cheahjs/fix/harden-streaming
fix: harden openai streaming parsing
This commit is contained in:
commit
81fb53e757
1 changed files with 7 additions and 3 deletions
|
@ -36,10 +36,14 @@ async function* openAIStreamToIterator(
|
|||
// OpenRouter sends heartbeats like ": OPENROUTER PROCESSING"
|
||||
continue
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue