diff --git a/ollama/__init__.py b/ollama/__init__.py index 92bba280..32af645a 100644 --- a/ollama/__init__.py +++ b/ollama/__init__.py @@ -1,44 +1,49 @@ +from importlib.metadata import version as _pkg_version from ollama._client import AsyncClient, Client from ollama._types import ( - ChatResponse, - EmbeddingsResponse, - EmbedResponse, - GenerateResponse, - Image, - ListResponse, - Message, - Options, - ProcessResponse, - ProgressResponse, - RequestError, - ResponseError, - ShowResponse, - StatusResponse, - Tool, - WebFetchResponse, - WebSearchResponse, + ChatResponse, + EmbeddingsResponse, + EmbedResponse, + GenerateResponse, + Image, + ListResponse, + Message, + Options, + ProcessResponse, + ProgressResponse, + RequestError, + ResponseError, + ShowResponse, + StatusResponse, + Tool, + WebFetchResponse, + WebSearchResponse, ) +__version__ = _pkg_version('ollama') + __all__ = [ - 'AsyncClient', - 'ChatResponse', - 'Client', - 'EmbedResponse', - 'EmbeddingsResponse', - 'GenerateResponse', - 'Image', - 'ListResponse', - 'Message', - 'Options', - 'ProcessResponse', - 'ProgressResponse', - 'RequestError', - 'ResponseError', - 'ShowResponse', - 'StatusResponse', - 'Tool', - 'WebFetchResponse', - 'WebSearchResponse', + 'AsyncClient', + 'ChatResponse', + 'Client', + 'EmbedResponse', + 'EmbeddingsResponse', + 'GenerateResponse', + 'Image', + 'ListResponse', + 'Message', + 'Options', + 'ProcessResponse', + 'ProgressResponse', + 'RequestError', + 'ResponseError', + 'ShowResponse', + 'StatusResponse', + 'Tool', + 'WebFetchResponse', + 'WebSearchResponse', + '__version__', + 'version', ] _client = Client() @@ -52,8 +57,7 @@ create = _client.create delete = _client.delete list = _client.list -copy = _client.copy show = _client.show +copy = _client.copy ps = _client.ps -web_search = _client.web_search -web_fetch = _client.web_fetch +version = _client.version # Expose the version method for users to check the Ollama version diff --git a/ollama/_client.py b/ollama/_client.py index 18cb0fb4..5215ae2d 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -670,6 +670,9 @@ def ps(self) -> ProcessResponse: 'GET', '/api/ps', ) + def version(self) -> str: + response = self._request_raw('GET', '/api/version') + return response.json().get('version', '') def web_search(self, query: str, max_results: int = 3) -> WebSearchResponse: """ @@ -1311,6 +1314,9 @@ async def ps(self) -> ProcessResponse: 'GET', '/api/ps', ) + async def version(self) -> str: + response = await self._request_raw('GET', '/api/version') + return response.json().get('version', '') def _copy_images(images: Optional[Sequence[Union[Image, Any]]]) -> Iterator[Image]: