mirror of
https://github.com/ollama/ollama-python.git
synced 2026-10-28 19:43:36 +00:00
Merge pull request #524 from ollama/drifkin/thinking-support
fully add thinking support to `generate()`
This commit is contained in:
@@ -65,3 +65,6 @@ Requirement: `pip install tqdm`
|
|||||||
|
|
||||||
### Thinking - Enable thinking mode for a model
|
### Thinking - Enable thinking mode for a model
|
||||||
- [thinking.py](thinking.py)
|
- [thinking.py](thinking.py)
|
||||||
|
|
||||||
|
### Thinking (generate) - Enable thinking mode for a model
|
||||||
|
- [thinking-generate.py](thinking-generate.py)
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -190,6 +190,7 @@ class Client(BaseClient):
|
|||||||
template: str = '',
|
template: str = '',
|
||||||
context: Optional[Sequence[int]] = None,
|
context: Optional[Sequence[int]] = None,
|
||||||
stream: Literal[False] = False,
|
stream: Literal[False] = False,
|
||||||
|
think: Optional[bool] = None,
|
||||||
raw: bool = False,
|
raw: bool = False,
|
||||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||||
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
|
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
|
||||||
@@ -208,6 +209,7 @@ class Client(BaseClient):
|
|||||||
template: str = '',
|
template: str = '',
|
||||||
context: Optional[Sequence[int]] = None,
|
context: Optional[Sequence[int]] = None,
|
||||||
stream: Literal[True] = True,
|
stream: Literal[True] = True,
|
||||||
|
think: Optional[bool] = None,
|
||||||
raw: bool = False,
|
raw: bool = False,
|
||||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||||
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
|
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
|
||||||
@@ -225,6 +227,7 @@ class Client(BaseClient):
|
|||||||
template: Optional[str] = None,
|
template: Optional[str] = None,
|
||||||
context: Optional[Sequence[int]] = None,
|
context: Optional[Sequence[int]] = None,
|
||||||
stream: bool = False,
|
stream: bool = False,
|
||||||
|
think: Optional[bool] = None,
|
||||||
raw: Optional[bool] = None,
|
raw: Optional[bool] = None,
|
||||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||||
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
|
images: Optional[Sequence[Union[str, bytes, Image]]] = None,
|
||||||
@@ -253,6 +256,7 @@ class Client(BaseClient):
|
|||||||
template=template,
|
template=template,
|
||||||
context=context,
|
context=context,
|
||||||
stream=stream,
|
stream=stream,
|
||||||
|
think=think,
|
||||||
raw=raw,
|
raw=raw,
|
||||||
format=format,
|
format=format,
|
||||||
images=list(_copy_images(images)) if images else None,
|
images=list(_copy_images(images)) if images else None,
|
||||||
|
|||||||
Reference in New Issue
Block a user