mirror of
https://github.com/ollama/ollama-python.git
synced 2026-06-18 22:23:24 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ce6846e4fc | |||
| e0253ab627 | |||
| 756bd8f31a | |||
| f8c6cd5131 | |||
| eaad6df5ef |
@@ -62,3 +62,9 @@ Requirement: `pip install tqdm`
|
||||
### Ollama Embed - Generate embeddings with a model
|
||||
- [embed.py](embed.py)
|
||||
|
||||
|
||||
### 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)
|
||||
|
||||
@@ -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)
|
||||
@@ -0,0 +1,13 @@
|
||||
from ollama import chat
|
||||
|
||||
messages = [
|
||||
{
|
||||
'role': 'user',
|
||||
'content': 'What is 10 + 23?',
|
||||
},
|
||||
]
|
||||
|
||||
response = chat('deepseek-r1', messages=messages, think=True)
|
||||
|
||||
print('Thinking:\n========\n\n' + response.message.thinking)
|
||||
print('\nResponse:\n========\n\n' + response.message.content)
|
||||
@@ -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,
|
||||
@@ -270,6 +274,7 @@ class Client(BaseClient):
|
||||
*,
|
||||
tools: Optional[Sequence[Union[Mapping[str, Any], Tool, Callable]]] = None,
|
||||
stream: Literal[False] = False,
|
||||
think: Optional[bool] = None,
|
||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||
options: Optional[Union[Mapping[str, Any], Options]] = None,
|
||||
keep_alive: Optional[Union[float, str]] = None,
|
||||
@@ -283,6 +288,7 @@ class Client(BaseClient):
|
||||
*,
|
||||
tools: Optional[Sequence[Union[Mapping[str, Any], Tool, Callable]]] = None,
|
||||
stream: Literal[True] = True,
|
||||
think: Optional[bool] = None,
|
||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||
options: Optional[Union[Mapping[str, Any], Options]] = None,
|
||||
keep_alive: Optional[Union[float, str]] = None,
|
||||
@@ -295,6 +301,7 @@ class Client(BaseClient):
|
||||
*,
|
||||
tools: Optional[Sequence[Union[Mapping[str, Any], Tool, Callable]]] = None,
|
||||
stream: bool = False,
|
||||
think: Optional[bool] = None,
|
||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||
options: Optional[Union[Mapping[str, Any], Options]] = None,
|
||||
keep_alive: Optional[Union[float, str]] = None,
|
||||
@@ -341,6 +348,7 @@ class Client(BaseClient):
|
||||
messages=list(_copy_messages(messages)),
|
||||
tools=list(_copy_tools(tools)),
|
||||
stream=stream,
|
||||
think=think,
|
||||
format=format,
|
||||
options=options,
|
||||
keep_alive=keep_alive,
|
||||
@@ -694,6 +702,7 @@ class AsyncClient(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,
|
||||
@@ -712,6 +721,7 @@ class AsyncClient(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,
|
||||
@@ -729,6 +739,7 @@ class AsyncClient(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,
|
||||
@@ -756,6 +767,7 @@ class AsyncClient(BaseClient):
|
||||
template=template,
|
||||
context=context,
|
||||
stream=stream,
|
||||
think=think,
|
||||
raw=raw,
|
||||
format=format,
|
||||
images=list(_copy_images(images)) if images else None,
|
||||
@@ -773,6 +785,7 @@ class AsyncClient(BaseClient):
|
||||
*,
|
||||
tools: Optional[Sequence[Union[Mapping[str, Any], Tool, Callable]]] = None,
|
||||
stream: Literal[False] = False,
|
||||
think: Optional[bool] = None,
|
||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||
options: Optional[Union[Mapping[str, Any], Options]] = None,
|
||||
keep_alive: Optional[Union[float, str]] = None,
|
||||
@@ -786,6 +799,7 @@ class AsyncClient(BaseClient):
|
||||
*,
|
||||
tools: Optional[Sequence[Union[Mapping[str, Any], Tool, Callable]]] = None,
|
||||
stream: Literal[True] = True,
|
||||
think: Optional[bool] = None,
|
||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||
options: Optional[Union[Mapping[str, Any], Options]] = None,
|
||||
keep_alive: Optional[Union[float, str]] = None,
|
||||
@@ -798,6 +812,7 @@ class AsyncClient(BaseClient):
|
||||
*,
|
||||
tools: Optional[Sequence[Union[Mapping[str, Any], Tool, Callable]]] = None,
|
||||
stream: bool = False,
|
||||
think: Optional[bool] = None,
|
||||
format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None,
|
||||
options: Optional[Union[Mapping[str, Any], Options]] = None,
|
||||
keep_alive: Optional[Union[float, str]] = None,
|
||||
@@ -845,6 +860,7 @@ class AsyncClient(BaseClient):
|
||||
messages=list(_copy_messages(messages)),
|
||||
tools=list(_copy_tools(tools)),
|
||||
stream=stream,
|
||||
think=think,
|
||||
format=format,
|
||||
options=options,
|
||||
keep_alive=keep_alive,
|
||||
|
||||
@@ -207,6 +207,9 @@ class GenerateRequest(BaseGenerateRequest):
|
||||
images: Optional[Sequence[Image]] = None
|
||||
'Image data for multimodal models.'
|
||||
|
||||
think: Optional[bool] = None
|
||||
'Enable thinking mode (for thinking models).'
|
||||
|
||||
|
||||
class BaseGenerateResponse(SubscriptableBaseModel):
|
||||
model: Optional[str] = None
|
||||
@@ -248,6 +251,9 @@ class GenerateResponse(BaseGenerateResponse):
|
||||
response: str
|
||||
'Response content. When streaming, this contains a fragment of the response.'
|
||||
|
||||
thinking: Optional[str] = None
|
||||
'Thinking content. Only present when thinking is enabled.'
|
||||
|
||||
context: Optional[Sequence[int]] = None
|
||||
'Tokenized history up to the point of the response.'
|
||||
|
||||
@@ -263,6 +269,9 @@ class Message(SubscriptableBaseModel):
|
||||
content: Optional[str] = None
|
||||
'Content of the message. Response messages contains message fragments when streaming.'
|
||||
|
||||
thinking: Optional[str] = None
|
||||
'Thinking content. Only present when thinking is enabled.'
|
||||
|
||||
images: Optional[Sequence[Image]] = None
|
||||
"""
|
||||
Optional list of image data for multimodal models.
|
||||
@@ -345,6 +354,9 @@ class ChatRequest(BaseGenerateRequest):
|
||||
tools: Optional[Sequence[Tool]] = None
|
||||
'Tools to use for the chat.'
|
||||
|
||||
think: Optional[bool] = None
|
||||
'Enable thinking mode (for thinking models).'
|
||||
|
||||
|
||||
class ChatResponse(BaseGenerateResponse):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user