Skip to content

Added support for the "think" for Ollama #3386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sunyuhan1998
Copy link
Contributor

@sunyuhan1998 sunyuhan1998 commented May 30, 2025

Fixes #3383
As mentioned in issue: #3383 , Ollama added support for "think" in its latest 0.9.0 version:
https://github.com/ollama/ollama/releases
https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-chat-completion.

This PR implements support for that attribute and includes the following key changes:

  1. Added the think field to Ollama's ChatRequest
  2. Added the thinking field to Ollama's Message
  3. Added the think property to OllamaOptions, allowing users to specify whether to enable or disable thinking

Actually, there is currently another issue:

As stated in Ollama's API documentation here, during requests to Ollama, the message field supports sending the model's own reasoning (thoughts) back to it. However, AssistantMessage does not currently support transmitting this field, which means the model will not be aware of its previous thoughts.

Therefore, perhaps we need to add a specialized Message implementation for Ollama, such as OllamaAssistantMessage. I'm not sure whether this would be considered a significant change.

      1. Added the `think` field to Ollama's `ChatRequest`
      2. Added the `thinking` field to Ollama's `Message`
      3. Added the `think` property to `OllamaOptions`, allowing users to specify whether to enable or disable thinking

Signed-off-by: Sun Yuhan <[email protected]>
…fault behavior, thereby ensuring compatibility with older versions of Ollama calls.

Signed-off-by: Sun Yuhan <[email protected]>
@sunyuhan1998
Copy link
Contributor Author

@tzolov @ilayaperumalg @markpollack Could you please help review this PR? Thank you.

…tainer image version of ollama to 0.9.0

Signed-off-by: Sun Yuhan <[email protected]>
@markpollack
Copy link
Member

Yes, we will review. Thanks

…tionMetadata`, and added corresponding unit tests.

Signed-off-by: Sun Yuhan <[email protected]>
@TonyReggae
Copy link

可以考虑加一个可自由扩展参数的字段,可以灵活应对兼容参数并避免延迟于ollama的更新。

@sunyuhan1998
Copy link
Contributor Author

Hi @markpollack , I hope you're doing well!

I just wanted to check in and see if there are any further changes needed for this PR. Let me know if there's anything else I should address — happy to make adjustments if needed!

Thanks again for your time and review!

@hbsjz-swl
Copy link

I would like to ask: If this PR is merged, will this feature be included in the snapshot version library? Then how can developers who are currently using the GA version use this feature?

@sunyuhan1998
Copy link
Contributor Author

sunyuhan1998 commented Jun 24, 2025

I would like to ask: If this PR is merged, will this feature be included in the snapshot version library? Then how can developers who are currently using the GA version use this feature?

It seems to me that this feature should be included in 1.1.x, as well as being backport to 1.0.x. By the time the 1.0.x version is officially released, users currently using the 1.0.0 GA version will be able to use it by upgrading to the 1.0.x version

…-thinking

# Conflicts:
#	models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/api/OllamaApi.java
#	models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaImage.java
@markpollack
Copy link
Member

yes, I will backport it. Sorry about the delay. Only now getting my project mgmt hat on full time @sunyuhan1998

@sunyuhan1998
Copy link
Contributor Author

yes, I will backport it. Sorry about the delay. Only now getting my project mgmt hat on full time @sunyuhan1998

no problem at all! Please feel free to let me know if any changes are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessing the New "Thought" Field from Ollama in the Spring AI Framework
4 participants