From 0a7c520579f7d4d8f6d59ece739387c12e9deb24 Mon Sep 17 00:00:00 2001 From: as-ondewo Date: Tue, 24 Feb 2026 12:18:12 +0100 Subject: [PATCH] Fix: empty response from OpenAI chat completion endpoint (#13166) ### What problem does this PR solve? When using a chat assistant that has a hardcoded `empty_response`, that response was not returned correctly in streaming mode when no information is found in the knowledge base. In this case only one response with `"content": null` was yielded. If `"references": true`, then the `empty_response` is still put into the `final_content` so there is technically some content returned, but when `"references": false` no content at all is returned. I update the OpenAI chat completion endpoint to yield an additional response with the `empty_response` in the content. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/sdk/session.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py index 2644a03ef..249a8e133 100644 --- a/api/apps/sdk/session.py +++ b/api/apps/sdk/session.py @@ -369,7 +369,10 @@ async def chat_completion_openai_like(tenant_id, chat_id): if ans.get("final"): if ans.get("answer"): full_content = ans["answer"] - final_answer = ans.get("answer") or full_content + response["choices"][0]["delta"]["content"] = full_content + response["choices"][0]["delta"]["reasoning_content"] = None + yield f"data:{json.dumps(response, ensure_ascii=False)}\n\n" + final_answer = full_content final_reference = ans.get("reference", {}) continue if ans.get("start_to_think"):