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)
This commit is contained in:
as-ondewo
2026-02-24 12:18:12 +01:00
committed by GitHub
parent 5de92e57d3
commit 0a7c520579

View File

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