diff --git a/examples/README.md b/examples/README.md index f6b435d..dbe480b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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) diff --git a/examples/thinking-generate.py b/examples/thinking-generate.py new file mode 100644 index 0000000..17e9e41 --- /dev/null +++ b/examples/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) diff --git a/ollama/_client.py b/ollama/_client.py index 2d34fec..4555a93 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -190,6 +190,7 @@ def generate( 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 @@ def generate( 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 @@ def generate( 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 @@ def generate( template=template, context=context, stream=stream, + think=think, raw=raw, format=format, images=list(_copy_images(images)) if images else None,