You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: document reasoning content support for Ollama via OpenAI compatibility
Add documentation for accessing Ollama's reasoning content through the
OpenAI-compatible endpoint using the reasoningContent metadata field.
Fixes#3383
Signed-off-by: SenreySong <25841017+SenreySong@users.noreply.github.com>
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/ollama-chat.adoc
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -520,6 +520,50 @@ This allows you to leverage Ollama's full capabilities while using the OpenAI cl
520
520
521
521
image::spring-ai-ollama-over-openai.jpg[Ollama OpenAI API compatibility, 800, 600, align="center"]
522
522
523
+
=== Reasoning Content via OpenAI Compatibility
524
+
525
+
Ollama's OpenAI-compatible endpoint supports the `reasoning_content` field for thinking-capable models (such as `qwen3:*-thinking`, `deepseek-r1`, `deepseek-v3.1`).
526
+
When using the Spring AI OpenAI client with Ollama, the model's reasoning process is automatically captured and made available through the response metadata.
527
+
528
+
NOTE: This is an alternative to using Ollama's native thinking mode API (documented in <<Thinking Mode (Reasoning)>> above).
529
+
Both approaches work with Ollama's thinking models, but the OpenAI-compatible endpoint uses the `reasoning_content` field name instead of `thinking`.
530
+
531
+
Here's an example of accessing reasoning content from Ollama through the OpenAI client:
532
+
533
+
[source,java]
534
+
----
535
+
// Configure Spring AI OpenAI client to point to Ollama
536
+
@Configuration
537
+
class OllamaConfig {
538
+
@Bean
539
+
OpenAiChatModel ollamaChatModel() {
540
+
var openAiApi = new OpenAiApi("http://localhost:11434", "ollama");
541
+
return new OpenAiChatModel(openAiApi,
542
+
OpenAiChatOptions.builder()
543
+
.model("deepseek-r1") // or qwen3, deepseek-v3.1, etc.
544
+
.build());
545
+
}
546
+
}
547
+
548
+
// Use the model with thinking-capable models
549
+
ChatResponse response = chatModel.call(
550
+
new Prompt("How many letter 'r' are in the word 'strawberry'?"));
TIP: Thinking-capable models in Ollama (0.12+) automatically enable thinking mode when accessed through the OpenAI-compatible endpoint.
565
+
The reasoning content is captured automatically without requiring additional configuration.
566
+
523
567
Check the link:https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/proxy/OllamaWithOpenAiChatModelIT.java[OllamaWithOpenAiChatModelIT.java] tests for examples of using Ollama over Spring AI OpenAI.
0 commit comments