mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-25 17:42:24 +08:00
Fix: default OpenAI chat completions to non-stream (#15394)
### What problem does this PR solve? default OpenAI chat completions to non-stream when `stream` is omitted https://github.com/infiniflow/ragflow/issues/15356 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@@ -163,7 +163,7 @@ async def openai_chat_completions(chat_id):
|
||||
|
||||
tools = None
|
||||
toolcall_session = None
|
||||
stream_mode = req.get("stream", True)
|
||||
stream_mode = bool(req.get("stream", False))
|
||||
|
||||
if stream_mode:
|
||||
async def streamed_response_generator():
|
||||
|
||||
@@ -140,6 +140,26 @@ def test_openai_compatible_nonstream_shape(rest_client, create_chat):
|
||||
assert usage["total_tokens"] == usage["prompt_tokens"] + usage["completion_tokens"], usage
|
||||
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_openai_compatible_defaults_to_nonstream_when_stream_is_missing(rest_client, create_chat):
|
||||
chat_id = create_chat("restful_openai_default_nonstream_chat")
|
||||
res = rest_client.post(
|
||||
f"/openai/{chat_id}/chat/completions",
|
||||
json={
|
||||
"model": "model",
|
||||
"messages": [{"role": "user", "content": "hello"}],
|
||||
},
|
||||
timeout=60,
|
||||
)
|
||||
assert res.status_code == 200
|
||||
assert "application/json" in res.headers.get("Content-Type", ""), res.headers.get("Content-Type", "")
|
||||
|
||||
payload = res.json()
|
||||
assert payload["object"] == "chat.completion", payload
|
||||
assert isinstance(payload["choices"], list) and payload["choices"], payload
|
||||
assert payload["choices"][0].get("finish_reason") == "stop", payload
|
||||
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_openai_compatible_nonstream_with_reference_output_shape(rest_client, create_chat):
|
||||
chat_id = create_chat("restful_openai_reference_chat")
|
||||
|
||||
Reference in New Issue
Block a user