From 59658fb60c384e6cae18a8c9601d43e47af4f5bb Mon Sep 17 00:00:00 2001 From: Lingxu Date: Wed, 9 Sep 2026 21:27:48 +0800 Subject: [PATCH] fix(server): default `stream` to False to comply with OpenAI spec The OpenAI Chat Completions API defaults `stream` to false, but ChatRequest.stream was defaulting to True. As a result, any standard OpenAI-compatible client that omits the `stream` field receives a `text/event-stream` response where it expects plain JSON, and fails with: AttributeError: 'str' object has no attribute 'choices' Reproduce (openai==1.59.6): from openai import OpenAI c = OpenAI(base_url='http://localhost:8998/v1', api_key='none') c.chat.completions.create(model='minimind', messages=[{'role':'user','content':'hi'}]) curl with an explicit "stream": false returns correct JSON, confirming the handler logic is fine and only the default value is at fault. Explicit `stream=True` requests are unaffected. --- scripts/serve_openai_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/serve_openai_api.py b/scripts/serve_openai_api.py index adf2212..b562c8e 100644 --- a/scripts/serve_openai_api.py +++ b/scripts/serve_openai_api.py @@ -53,7 +53,7 @@ class ChatRequest(BaseModel): temperature: float = 0.7 top_p: float = 0.92 max_tokens: int = 8192 - stream: bool = True + stream: bool = False # 对齐 OpenAI 规范:默认非流式,避免标准客户端不传 stream 时误收 SSE tools: list = Field(default_factory=list) open_thinking: bool = False chat_template_kwargs: dict = None