Skip to content

server: include content key in final streaming delta when empty - #2090

Open
Knight-XMUM wants to merge 1 commit into
ml-explore:mainfrom
Knight-XMUM:fix/streaming-final-delta-content
Open

Knight-XMUM wants to merge 1 commit into
ml-explore:mainfrom
Knight-XMUM:fix/streaming-final-delta-content

Conversation

@Knight-XMUM

@Knight-XMUM Knight-XMUM commented Nov 22, 2026 •

Copy link
Copy Markdown
  • I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: used AI for reading the server code and drafting the unit tests; I checked the diff and ran the tests locally on M4 Air.

Fixes #2084

In mlx_lm/server.py, streaming responses skipped the content field on the final chunk when text is empty (for example when a thinking model hits max_tokens). Updated generate_response to include "content": text if text else None when finish_reason is not None, while keeping intermediate streaming deltas unchanged, and added 4 unit tests in tests/test_server.py (all passed locally).

Signed-off-by: Knight <2210620249@qq.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chat.completion streaming: content key missing when thinking model exhausts token budget

1 participant