Add support for Ollama's OpenAI-compatible API reasoning field #5057
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.
When using Ollama's OpenAI-compatible /api/chat endpoint with think: true and stream: true, some models (e.g., qwen3, deepseek-r1) emit reasoning tokens in the thinking field instead of the standard OpenAI reasoning_content field.
This causes the reasoning trace to be lost in the current implementation, as ChatCompletionMessage.reasoningContent only deserializes the standard field name.
Example (Ollama 0.13.1, 0.12.11)
Streamed chunks contain:
{"model":"qwen3","created_at":"2025-12-08T06:23:02.518809Z","message":{"role":"assistant","content":"","thinking":"Okay"},"done":false} {"model":"qwen3","created_at":"2025-12-08T06:23:02.562574Z","message":{"role":"assistant","content":"","thinking":","},"done":false} {"model":"qwen3","created_at":"2025-12-08T06:23:02.606487Z","message":{"role":"assistant","content":"","thinking":" so"},"done":false} {"model":"qwen3","created_at":"2025-12-08T06:23:02.650708Z","message":{"role":"assistant","content":"","thinking":" I"},"done":false}In this format, the reasoning trace is emitted in the thinking field, not reasoning_content, so ChatCompletionMessage currently does not capture it.
This PR adds @JsonAlias("reasoning") to the reasoningContent field in ChatCompletionMessage to ensure compatibility with both field names.