Merge pull request #524 from ollama/drifkin/thinking-support
Some checks are pending
test / test (push) Waiting to run
test / lint (push) Waiting to run

fully add thinking support to `generate()`
This commit is contained in:
Devon Rifkin 2025-05-30 14:32:05 -07:00 committed by GitHub
commit ce6846e4fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 0 deletions

View File

@ -65,3 +65,6 @@ Requirement: `pip install tqdm`
### Thinking - Enable thinking mode for a model
- [thinking.py](thinking.py)
### Thinking (generate) - Enable thinking mode for a model
- [thinking-generate.py](thinking-generate.py)

View File

@ -0,0 +1,13 @@
from ollama import generate
messages = [
{
'role': 'user',
'content': 'What is 10 + 23?',
},
]
response = generate('deepseek-r1', 'why is the sky blue', think=True)
print('Thinking:\n========\n\n' + response.thinking)
print('\nResponse:\n========\n\n' + response.response)

View File

@ -190,6 +190,7 @@ class Client(BaseClient):
template: str = '',
context: Optional[Sequence[int]] = None,
stream: Literal[False] = False,
think: Optional[bool] = None,
raw: bool = False,
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
@ -208,6 +209,7 @@ class Client(BaseClient):
template: str = '',
context: Optional[Sequence[int]] = None,
stream: Literal[True] = True,
think: Optional[bool] = None,
raw: bool = False,
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
@ -225,6 +227,7 @@ class Client(BaseClient):
template: Optional[str] = None,
context: Optional[Sequence[int]] = None,
stream: bool = False,
think: Optional[bool] = None,
raw: Optional[bool] = None,
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
@ -253,6 +256,7 @@ class Client(BaseClient):
template=template,
context=context,
stream=stream,
think=think,
raw=raw,
format=format,
images=list(_copy_images(images)) if images else None,