From 043dbf437bd2fdee76719b57aae0e6ad01203b9b Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 5 Aug 2026 18:06:20 +0530 Subject: [PATCH 1/5] feat: expose __version__ via importlib.metadata --- ollama/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ollama/__init__.py b/ollama/__init__.py index 92bba280..c0bb46db 100644 --- a/ollama/__init__.py +++ b/ollama/__init__.py @@ -1,4 +1,5 @@ from ollama._client import AsyncClient, Client +from importlib.metadata import version, PackageNotFoundError from ollama._types import ( ChatResponse, EmbeddingsResponse, @@ -57,3 +58,9 @@ ps = _client.ps web_search = _client.web_search web_fetch = _client.web_fetch + + +try: + __version__ = version("ollama") +except PackageNotFoundError: + __version__ = "unknown" \ No newline at end of file From 0bc5c0171d1172bc792404390f1a346bb4ced10a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 5 Aug 2026 18:37:07 +0530 Subject: [PATCH 2/5] feat: add exists() method to check if model is available locally --- ollama/__init__.py | 1 + ollama/_client.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/ollama/__init__.py b/ollama/__init__.py index c0bb46db..90b66711 100644 --- a/ollama/__init__.py +++ b/ollama/__init__.py @@ -58,6 +58,7 @@ ps = _client.ps web_search = _client.web_search web_fetch = _client.web_fetch +exists = _client.exists try: diff --git a/ollama/_client.py b/ollama/_client.py index 8dfce824..3198c9fe 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -670,6 +670,12 @@ def ps(self) -> ProcessResponse: 'GET', '/api/ps', ) + def exists(self, model: str) -> bool: + try: + self.show(model) + return True + except Exception: + return False def web_search(self, query: str, max_results: int = 3) -> WebSearchResponse: """ From 27433250027f0fa017c5d87acae8f2b6beace638 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 6 Aug 2026 11:21:06 +0530 Subject: [PATCH 3/5] fix: make model_info optional in ShowResponse to handle cloud models --- ollama/_types.py | 2 +- tests/test_show.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/test_show.py diff --git a/ollama/_types.py b/ollama/_types.py index 96529d63..2afb8ee2 100644 --- a/ollama/_types.py +++ b/ollama/_types.py @@ -572,7 +572,7 @@ class ShowResponse(SubscriptableBaseModel): details: Optional[ModelDetails] = None - modelinfo: Optional[Mapping[str, Any]] = Field(alias='model_info') + modelinfo: Optional[Mapping[str, Any]] = Field(default=None, alias='model_info') parameters: Optional[str] = None diff --git a/tests/test_show.py b/tests/test_show.py new file mode 100644 index 00000000..8f7433d0 --- /dev/null +++ b/tests/test_show.py @@ -0,0 +1,13 @@ +import sys +sys.path.insert(0, '.') # force Python to use local folder first + +from ollama._types import ShowResponse + +test_data = { + "template": "test template", + "details": None, +} + +response = ShowResponse(**test_data) +print(f"modelinfo: {response.modelinfo}") +print("✓ Fix works — no ValidationError") \ No newline at end of file From 2874041bc83d09497fd6ae88dd6eafb65e627f5c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 6 Aug 2026 11:42:55 +0530 Subject: [PATCH 4/5] feat: add tool_choice parameter to chat() and ChatRequest --- ollama/_client.py | 2 ++ ollama/_types.py | 3 +++ tests/test_tool_choice.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/test_tool_choice.py diff --git a/ollama/_client.py b/ollama/_client.py index 3198c9fe..b4337dd6 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -349,6 +349,7 @@ def chat( top_logprobs: Optional[int] = None, format: Optional[Union[Literal['', 'json'], JsonSchemaValue]] = None, options: Optional[Union[Mapping[str, Any], Options]] = None, + tool_choice: Optional[Literal['auto', 'none', 'required']] = None, keep_alive: Optional[Union[float, str]] = None, ) -> Union[ChatResponse, Iterator[ChatResponse]]: """ @@ -396,6 +397,7 @@ def add_two_numbers(a: int, b: int) -> int: think=think, logprobs=logprobs, top_logprobs=top_logprobs, + tool_choice=tool_choice, format=format, options=options, keep_alive=keep_alive, diff --git a/ollama/_types.py b/ollama/_types.py index 2afb8ee2..5be31a1f 100644 --- a/ollama/_types.py +++ b/ollama/_types.py @@ -400,6 +400,9 @@ def serialize_model(self, nxt): tools: Optional[Sequence[Tool]] = None 'Tools to use for the chat.' + tool_choice: Optional[str] = None + 'Controls which tool the model should use. Options: "auto", "none", "required".' + think: Optional[Union[bool, Literal['low', 'medium', 'high']]] = None 'Enable thinking mode (for thinking models).' diff --git a/tests/test_tool_choice.py b/tests/test_tool_choice.py new file mode 100644 index 00000000..16c803b0 --- /dev/null +++ b/tests/test_tool_choice.py @@ -0,0 +1,17 @@ +import sys +sys.path.insert(0, '.') + +from ollama._types import ChatRequest + +# Test that tool_choice is accepted +req = ChatRequest( + model="llama3.2", + tool_choice="auto" +) +print(f"tool_choice: {req.tool_choice}") +print("✓ tool_choice parameter works") + +# Test default is None +req2 = ChatRequest(model="llama3.2") +print(f"tool_choice default: {req2.tool_choice}") +print("✓ default is None") \ No newline at end of file From 621266d24a114b3228b61b017416a99d17e76ff7 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 6 Aug 2026 11:57:21 +0530 Subject: [PATCH 5/5] fix: add optional id field to Message.ToolCall for OpenAI compatibility --- ollama/_types.py | 1 + tests/test_toolcall_id.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/test_toolcall_id.py diff --git a/ollama/_types.py b/ollama/_types.py index 5be31a1f..e0c2558e 100644 --- a/ollama/_types.py +++ b/ollama/_types.py @@ -334,6 +334,7 @@ class ToolCall(SubscriptableBaseModel): """ Model tool calls. """ + id: Optional[str] = None class Function(SubscriptableBaseModel): """ diff --git a/tests/test_toolcall_id.py b/tests/test_toolcall_id.py new file mode 100644 index 00000000..e3546644 --- /dev/null +++ b/tests/test_toolcall_id.py @@ -0,0 +1,25 @@ +import sys +sys.path.insert(0, '.') + +from ollama._types import Message + +# Test with id +tc1 = Message.ToolCall( + id="call_abc123", + function=Message.ToolCall.Function( + name="get_weather", + arguments={"city": "Hyderabad"} + ) +) +print(f"id: {tc1.id}") +print(f"function: {tc1.function.name}") + +# Test without id (backward compatibility) +tc2 = Message.ToolCall( + function=Message.ToolCall.Function( + name="get_weather", + arguments={"city": "Hyderabad"} + ) +) +print(f"id default: {tc2.id}") +print("✓ Both work") \ No newline at end of file