From 54094771a3ffcb4880646b7df45e91999f28c05f Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Sat, 28 Feb 2026 12:16:38 +0800 Subject: [PATCH] Fix streaming chat on web API (#13275) ### What problem does this PR solve? This pull request makes a small but important fix to how streaming requests are handled in the `completion` endpoint of `conversation_app.py`. The main change ensures that the `stream` argument is not passed twice, which could cause errors. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: Jin Hai --- api/apps/conversation_app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/apps/conversation_app.py b/api/apps/conversation_app.py index 204d8f7ee5..482d6d0756 100644 --- a/api/apps/conversation_app.py +++ b/api/apps/conversation_app.py @@ -218,6 +218,8 @@ async def completion(): dia.llm_setting = chat_model_config is_embedded = bool(chat_model_id) + # Remove stream from req to avoid duplicate argument error + stream_mode = req.pop("stream", True) async def stream(): nonlocal dia, msg, req, conv try: @@ -231,7 +233,7 @@ async def completion(): yield "data:" + json.dumps({"code": 500, "message": str(e), "data": {"answer": "**ERROR**: " + str(e), "reference": []}}, ensure_ascii=False) + "\n\n" yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" - if req.get("stream", True): + if stream_mode: resp = Response(stream(), mimetype="text/event-stream") resp.headers.add_header("Cache-control", "no-cache") resp.headers.add_header("Connection", "keep-alive")