diff --git a/ollama/__init__.py b/ollama/__init__.py index 92bba280..90b66711 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,10 @@ ps = _client.ps web_search = _client.web_search web_fetch = _client.web_fetch +exists = _client.exists + + +try: + __version__ = version("ollama") +except PackageNotFoundError: + __version__ = "unknown" \ No newline at end of file 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: """ 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