-
Notifications
You must be signed in to change notification settings - Fork 0
ReasoningContent not forwarded in streaming responses despite ReasoningFormat being set #17
Description
Summary
When using the SDK with ReasoningFormat: "parsed" for reasoning models (e.g., deepseek/deepseek-reasoner), the reasoning content is not being forwarded to the client application despite the underlying API correctly providing reasoning content in the stream.
Environment
- SDK Version: Latest from main branch
- Go Version: 1.24+
- Model:
deepseek/deepseek-reasoner - Request Type: Streaming chat completion with
ReasoningFormat: "parsed"
Expected Behavior
When setting ReasoningFormat: "parsed" for reasoning models, the SDK should forward the reasoning_content field from the API response to the client application through the ChatCompletionStreamChoice.Delta or provide it through a dedicated field.
Actual Behavior
The SDK does not forward any reasoning content to the client application. All ChatChunkEvent objects have empty ReasoningContent fields, even though the underlying API stream contains reasoning content.
Evidence
1. Direct API Test (Working)
curl -X POST http://localhost:8080/v1/chat/completions -d '{
"model": "deepseek/deepseek-reasoner",
"messages": [{"role": "user", "content": "Hi"}],
"stream": true,
"reasoning_format": "parsed"
}'Result: Returns chunks with "reasoning_content": "Hmm, the user starts with..." ✅
2. SDK Implementation (Not Working)
reasoningFormat := "parsed"
options := &sdk.CreateChatCompletionRequest{
ReasoningFormat: &reasoningFormat,
}
client.WithOptions(options).GenerateContentStream(ctx, provider, model, messages)Result: All chunks have empty reasoning content ❌
Despite receiving regular content chunks correctly.
Code Analysis
The issue appears to be in the SDK's stream processing logic where:
- ✅ Request Setup:
ReasoningFormatparameter is correctly set and sent to the API - ❌ Response Processing: The reasoning content from the API response is not being extracted or forwarded
- ✅ Regular Content: Normal content chunks are processed correctly
Impact
This prevents client applications from implementing reasoning model features like:
- Showing "Thinking..." status during reasoning phases
- Displaying reasoning steps to users
- Proper UX flow for reasoning models
Reproduction Steps
- Set up SDK with reasoning model (
deepseek/deepseek-reasoner) - Set
ReasoningFormat: "parsed"in request options - Create streaming chat completion
- Observe that no reasoning content is received in stream chunks
- Compare with direct API call which shows reasoning content is available
Suggested Investigation Areas
- Stream parsing logic: Check if
reasoning_contentfield is being parsed from API response - Delta creation: Verify reasoning content is included when creating
ChatCompletionStreamChoice.Delta - Event forwarding: Ensure reasoning content is properly forwarded to client event handlers