Description
When using OpenAI-compatible providers that return reasoning content through streaming deltas, the reasoning data is lost during Spring AI's chunk aggregation process.
I reproduced this with DashScope Qwen3.6 Plus and deepseek-v4-flash.
The provider returns:
{
"choices": [
{
"delta": {
"reasoning_content": "thinking..."
}
}
]
}
The OpenAI Java SDK correctly parses it into:
cccc.delta()._additionalProperties()
Example:
Choice{
delta=Delta{
additionalProperties={
reasoning_content='thinking...'
}
}
}
However, in:
ChunkMerger.chunkToChatCompletion(...)
only content, refusal and toolCalls are copied into ChatCompletionMessage.
The delta additional properties are discarded.
Current code:
ChatCompletionMessage.Builder msgBuilder =
ChatCompletionMessage.builder()
.content(cccc.delta().content())
.refusal(cccc.delta().refusal());
Later Spring AI tries to read:
choice.message()._additionalProperties()
inside:
but the properties are already lost.
Suggested Fix
Copy delta additional properties into ChatCompletionMessage.
Example:
cccc.delta()
._additionalProperties()
.forEach(msgBuilder::putAdditionalProperty);
This allows existing reasoning_content support in:
to work correctly.
Verified locally. After preserving delta additional properties,
reasoningContent is correctly populated.
Version
** Spring AI 2.0.0-RC2**
I have already submitted a pull request containing the fix.
#6483
Description
When using OpenAI-compatible providers that return reasoning content through streaming deltas, the reasoning data is lost during Spring AI's chunk aggregation process.
I reproduced this with DashScope Qwen3.6 Plus and deepseek-v4-flash.
The provider returns:
{ "choices": [ { "delta": { "reasoning_content": "thinking..." } } ] }The OpenAI Java SDK correctly parses it into:
Example:
However, in:
only content, refusal and toolCalls are copied into ChatCompletionMessage.
The delta additional properties are discarded.
Current code:
Later Spring AI tries to read:
inside:
getReasoningContent(...)but the properties are already lost.
Suggested Fix
Copy delta additional properties into ChatCompletionMessage.
Example:
This allows existing reasoning_content support in:
getReasoningContent(...)to work correctly.
Verified locally. After preserving delta additional properties,
reasoningContent is correctly populated.
Version
** Spring AI 2.0.0-RC2**
I have already submitted a pull request containing the fix.
#6483