Skip to content

add support for thinking #521

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

Merged
merged 2 commits into from
May 29, 2025
Merged

add support for thinking #521

merged 2 commits into from
May 29, 2025

Conversation

drifkin
Copy link
Contributor

@drifkin drifkin commented May 27, 2025

To support ollama/ollama#10584

@drifkin drifkin requested a review from jmorganca May 27, 2025 07:29
@drifkin drifkin force-pushed the drifkin/thinking-support branch from aada745 to eaad6df Compare May 27, 2025 07:35
@jmorganca jmorganca requested review from mxyng and ParthSareen May 27, 2025 16:12

response = chat('deepseek-r1', messages=messages, think=True)

print('Thinking:\n========\n\n' + response.message.thinking)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print('Thinking:\n========\n\n' + response.message.thinking)
print('Thinking:')
print(response.message.thinking)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and can do the same below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha turns out I did have a version like that before, but I really wanted to highlight that there are two fields now, so having two print lines total feels like it slightly helps with that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool yeah that makes sense - could we just get rid of the === portion then and just do newline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ===== is very intentional to do a markdown style header that's much more noticeable in its plaintext form, like

Thinking:
========

<Here is the thinking content>

Response:
========

<Here is the response>

@@ -0,0 +1,13 @@
from ollama import chat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add this example to the examples/README.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh thank you! I totally didn't see that file

@drifkin drifkin merged commit 756bd8f into main May 29, 2025
2 checks passed
@drifkin drifkin deleted the drifkin/thinking-support branch May 29, 2025 23:02
@saddy001
Copy link

What's with ollama.generate? That should get the think parameter too.

drifkin added a commit that referenced this pull request May 30, 2025
@drifkin
Copy link
Contributor Author

drifkin commented May 30, 2025

What's with ollama.generate? That should get the think parameter too.

apologies, should be fixed in #524, will try to get that published soon

drifkin added a commit that referenced this pull request May 30, 2025
drifkin added a commit that referenced this pull request May 30, 2025
@saddy001
Copy link

saddy001 commented Jun 2, 2025

In the meantime I switched to .chat and I wonder what may be the purpose of .generate when there is .chat with stream=True.

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

Successfully merging this pull request may close these issues.

5 participants