Skip to content

Commit 008bc40

Browse files
Copilothiyouga
andcommitted
Fix SSE newline escaping for proper streaming
Co-authored-by: hiyouga <16256802+hiyouga@users.noreply.github.com>
1 parent dc3b1f5 commit 008bc40

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src_py/integration/web_ui.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,9 @@ async def stream_events():
541541
client.history = history.copy()
542542

543543
async for event in client.streaming_response_stateful(message=message, config=client_config):
544-
yield f"data: {json.dumps(event)}\\n\\n"
544+
yield f"data: {json.dumps(event)}\n\n"
545545

546-
yield "data: [DONE]\\n\\n"
546+
yield "data: [DONE]\n\n"
547547

548548
# Run the async generator
549549
async_gen = stream_events()
@@ -562,8 +562,8 @@ async def stream_events():
562562
"content_items": [{"type": "text", "text": f"Error: {str(e)}"}],
563563
"finish_reason": "error",
564564
}
565-
yield f"data: {json.dumps(error_event)}\\n\\n"
566-
yield "data: [DONE]\\n\\n"
565+
yield f"data: {json.dumps(error_event)}\n\n"
566+
yield "data: [DONE]\n\n"
567567

568568
return Response(generate(), mimetype="text/event-stream")
569569

0 commit comments

Comments
 (0)