feat: expose __version__ and top-level version() function

This commit is contained in:
Susan Dhungana 2026-04-30 10:16:23 +05:45
parent dbccf192ac
commit 5ecfaab50a
2 changed files with 49 additions and 39 deletions

View File

@ -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 @@ push = _client.push
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

View File

@ -670,6 +670,9 @@ class Client(BaseClient):
'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 @@ class AsyncClient(BaseClient):
'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]: