Skip to content

Commit 74834d5

Browse files
committed
fully add thinking support to generate()
#521 missed some calls
1 parent f8c6cd5 commit 74834d5

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

examples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ Requirement: `pip install tqdm`
6565

6666
### Thinking - Enable thinking mode for a model
6767
- [thinking.py](thinking.py)
68+
69+
### Thinking (generate) - Enable thinking mode for a model
70+
- [thinking-generate.py](thinking-generate.py)

examples/thinking-generate.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from ollama import generate
2+
3+
messages = [
4+
{
5+
'role': 'user',
6+
'content': 'What is 10 + 23?',
7+
},
8+
]
9+
10+
response = generate('deepseek-r1', "why is the sky blue", think=True)
11+
12+
print('Thinking:\n========\n\n' + response.thinking)
13+
print('\nResponse:\n========\n\n' + response.response)

ollama/_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def generate(
190190
template: str = '',
191191
context: Optional[Sequence[int]] = None,
192192
stream: Literal[False] = False,
193+
think: Optional[bool] = None,
193194
raw: bool = False,
194195
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
195196
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
@@ -208,6 +209,7 @@ def generate(
208209
template: str = '',
209210
context: Optional[Sequence[int]] = None,
210211
stream: Literal[True] = True,
212+
think: Optional[bool] = None,
211213
raw: bool = False,
212214
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
213215
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
@@ -225,6 +227,7 @@ def generate(
225227
template: Optional[str] = None,
226228
context: Optional[Sequence[int]] = None,
227229
stream: bool = False,
230+
think: Optional[bool] = None,
228231
raw: Optional[bool] = None,
229232
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
230233
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
@@ -253,6 +256,7 @@ def generate(
253256
template=template,
254257
context=context,
255258
stream=stream,
259+
think=think,
256260
raw=raw,
257261
format=format,
258262
images=list(_copy_images(images)) if images else None,
@@ -684,8 +688,10 @@ async def inner():
684688
yield cls(**part)
685689

686690
return inner()
691+
print("$$$ abcdef")
687692

688693
return cls(**(await self._request_raw(*args, **kwargs)).json())
694+
# TODO(!!!)(drifkin)
689695

690696
@overload
691697
async def generate(

0 commit comments

Comments
 (0)