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 <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-02-28 12:16:38 +08:00
committed by GitHub
parent 0110151e12
commit 54094771a3

View File

@@ -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")