fix(llm): accept reasoning field in OpenAI-compatible streams#35284
Open
mickaeldamatha wants to merge 1 commit into
Open
fix(llm): accept reasoning field in OpenAI-compatible streams#35284mickaeldamatha wants to merge 1 commit into
reasoning field in OpenAI-compatible streams#35284mickaeldamatha wants to merge 1 commit into
Conversation
Some OpenAI-compatible providers (Scaleway, vLLM/SGLang, OpenRouter, ...) stream chain-of-thought under a `reasoning` delta field instead of the `reasoning_content` field emitted by DeepSeek et al. The OpenAI Chat protocol only declared and read `reasoning_content`, so `reasoning` was stripped by the delta schema and the model's thinking was silently dropped for those providers. Declare `reasoning` on the delta schema and fall back to it when `reasoning_content` is absent, preferring `reasoning_content` when both are present. Adds streaming tests for both cases.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #35283
Type of change
What does this PR do?
The OpenAI Chat streaming delta schema (
OpenAIChatDeltainpackages/llm/src/protocols/openai-chat.ts) only declaresreasoning_content. Each SSE chunk is decoded viaProtocol.jsonEvent→Schema.fromJsonString, which strips any key that isn't on the struct. So when a provider streams its thinking underreasoninginstead ofreasoning_content, that key is dropped during decoding andstep()never sees it — the reasoning is silently lost.I hit this with Scaleway; it also affects self-hosted vLLM / SGLang deployments and OpenRouter's
reasoningfield. The model was clearly reasoning but nothing surfaced in the stream. I had been working around it by rewritingreasoning→reasoning_contentin a proxy in front ofopencode serve; this makes that workaround unnecessary.Two changes:
reasoningtoOpenAIChatDeltaso the decoder keeps the fieldstep(), readdelta.reasoning_content ?? delta.reasoning, soreasoning_contentstill takes precedence when a provider sends bothIt's additive to the wire schema — providers that only send
reasoning_content(DeepSeek etc.) take the exact same path as before.How did you verify your code works?
Added two streaming tests in
packages/llm/test/provider/openai-chat.test.ts, next to the existingreasoning_contentone:reasoningemits the expected reasoning-start / reasoning-delta / reasoning-end eventsreasoning_contentwinsbun testinpackages/llm: 29 pass / 0 fail.bun typecheckclean (the pre-push hook also runs the full monorepo typecheck, 30/30).Screenshots / recordings
N/A — not a UI change.
Checklist