mirror of
https://github.com/open-webui/open-webui
synced 2024-11-22 08:07:55 +00:00
Merge pull request #1780 from cheahjs/fix/harden-streaming
fix: harden openai streaming parsing
This commit is contained in:
commit
81fb53e757
@ -36,10 +36,14 @@ async function* openAIStreamToIterator(
|
|||||||
// OpenRouter sends heartbeats like ": OPENROUTER PROCESSING"
|
// OpenRouter sends heartbeats like ": OPENROUTER PROCESSING"
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
const data = JSON.parse(line.replace(/^data: /, ''));
|
const data = JSON.parse(line.replace(/^data: /, ''));
|
||||||
console.log(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 New Issue
Block a user