mirror of
https://github.com/ollama/ollama-python.git
synced 2026-05-01 11:48:17 +08:00
feat: expose __version__ and top-level version() helper
Closes #646 Adds two things to the public API: 1. `ollama.__version__` — the installed package version, resolved via `importlib.metadata` (same mechanism already used in `_client.py`). Now exported in `__all__` so it's part of the documented public API. 2. `ollama.version()` / `ollama.async_version()` — thin top-level wrappers around `Client.version()` so callers can check the running Ollama server version without instantiating a client. Also wires up `exists = _client.exists` to expose the new method at the top level, consistent with all other module-level shortcuts.
This commit is contained in:
parent
dbccf192ac
commit
136340f2ef
@ -1,3 +1,10 @@
|
||||
from importlib import metadata as _metadata
|
||||
|
||||
try:
|
||||
__version__: str = _metadata.version('ollama')
|
||||
except _metadata.PackageNotFoundError:
|
||||
__version__ = '0.0.0'
|
||||
|
||||
from ollama._client import AsyncClient, Client
|
||||
from ollama._types import (
|
||||
ChatResponse,
|
||||
@ -20,6 +27,7 @@ from ollama._types import (
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'__version__',
|
||||
'AsyncClient',
|
||||
'ChatResponse',
|
||||
'Client',
|
||||
@ -37,11 +45,13 @@ __all__ = [
|
||||
'ShowResponse',
|
||||
'StatusResponse',
|
||||
'Tool',
|
||||
'version',
|
||||
'WebFetchResponse',
|
||||
'WebSearchResponse',
|
||||
]
|
||||
|
||||
_client = Client()
|
||||
_async_client = AsyncClient()
|
||||
|
||||
generate = _client.generate
|
||||
chat = _client.chat
|
||||
@ -55,5 +65,37 @@ list = _client.list
|
||||
copy = _client.copy
|
||||
show = _client.show
|
||||
ps = _client.ps
|
||||
exists = _client.exists
|
||||
web_search = _client.web_search
|
||||
web_fetch = _client.web_fetch
|
||||
|
||||
|
||||
def version() -> str:
|
||||
"""Return the running Ollama server version string.
|
||||
|
||||
Hits the ``/api/version`` endpoint on the local Ollama server and returns
|
||||
the version string (e.g. ``"0.18.2"``).
|
||||
|
||||
This is distinct from :data:`__version__`, which is the version of the
|
||||
*Python client package* itself.
|
||||
|
||||
Returns:
|
||||
The Ollama server version string.
|
||||
|
||||
Example::
|
||||
|
||||
import ollama
|
||||
|
||||
print(ollama.__version__) # "0.6.1" — client package version
|
||||
print(ollama.version()) # "0.18.2" — running server version
|
||||
"""
|
||||
return _client.version()
|
||||
|
||||
|
||||
async def async_version() -> str:
|
||||
"""Async variant of :func:`version`.
|
||||
|
||||
Returns:
|
||||
The Ollama server version string.
|
||||
"""
|
||||
return await _async_client.version()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user