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: """