Skip to content

fix(openai): add reasoning_content to StreamingDelta for OpenAI-compatible providers#1441

Merged
joshua-mo-143 merged 3 commits into0xPlaygrounds:mainfrom
Fromsko:fix/openai-streaming-reasoning-content
Mar 4, 2026
Merged

fix(openai): add reasoning_content to StreamingDelta for OpenAI-compatible providers#1441
joshua-mo-143 merged 3 commits into0xPlaygrounds:mainfrom
Fromsko:fix/openai-streaming-reasoning-content

Conversation

@Fromsko
Copy link
Copy Markdown
Contributor

@Fromsko Fromsko commented Feb 25, 2026

Fixes #1440

Summary

The generic OpenAI Chat Completions streaming parser (StreamingDelta) does not parse the reasoning_content field from SSE chunks, causing reasoning/thinking content to be silently dropped for all OpenAI-compatible providers.

This is a 2-line fix that adds reasoning_content support to send_compatible_streaming_request, matching the existing pattern in the DeepSeek-specific provider.

Changes

File: rig-core/src/providers/openai/completion/streaming.rs

  1. Add reasoning_content field to StreamingDelta struct (line 38-39)
  2. Yield RawStreamingChoice::ReasoningDelta when reasoning content is present in the stream (lines 250-256)

Context

Affected Providers

All models using reasoning_content via the standard Chat Completions streaming format:

  • GLM-4.7 (Zhipu AI) — verified: 193 reasoning deltas now captured correctly
  • DeepSeek via OpenAI-compatible endpoints
  • Qwen with thinking mode (DashScope)
  • vLLM / Ollama serving reasoning models

Testing

Verified end-to-end with GLM-4.7:

  • Before fix: 0 ReasoningDelta events (reasoning silently dropped)
  • After fix: 193 ReasoningDelta events captured, full thinking chain preserved

Existing tests pass — the new reasoning_content field uses #[serde(default)] so it's backward-compatible (absent field → None).

…tible providers

The OpenAI Chat Completions streaming parser (StreamingDelta) does not
parse the 
easoning_content field from SSE chunks, causing reasoning/
thinking content from OpenAI-compatible providers to be silently dropped.

This affects all models that send 
easoning_content via the standard
Chat Completions streaming format, including:
- GLM-4.7 (Zhipu AI)
- DeepSeek models via OpenAI-compatible endpoints
- Qwen with thinking mode
- vLLM / Ollama OpenAI-compatible endpoints

The fix adds 
easoning_content: Option<String> to StreamingDelta and
yields RawStreamingChoice::ReasoningDelta events when present, matching
the existing pattern in the DeepSeek-specific provider.

Note: RawStreamingChoice::ReasoningDelta was already defined in
streaming.rs (added in PR 0xPlaygrounds#1395), but the generic OpenAI streaming
parser never utilized it.
Copy link
Copy Markdown
Contributor

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK to me. See my comment

Comment on lines +38 to +39
#[serde(default)]
reasoning_content: Option<String>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add docstring to state that this is not part of the official OpenAI API, it's for compliant providers

Copy link
Copy Markdown
Contributor Author

@Fromsko Fromsko Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He should look like this; I've already changed it.
Because the change has already been marked in another location.
Thanks for the review.

#[serde(default)]
reasoning_content: Option<String>, // This is not part of the official OpenAI API

Added a comment to clarify that reasoning_content is not part of the official OpenAI API.
Copy link
Copy Markdown
Contributor

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK to me I think. Thanks for contributing this change!

@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Mar 4, 2026
Merged via the queue into 0xPlaygrounds:main with commit 6a15d9f Mar 4, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 3, 2026
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.

bug(openai): StreamingDelta missing reasoning_content — reasoning silently dropped for OpenAI-compatible providers

2 participants