Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions ollama/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -20,6 +27,7 @@
)

__all__ = [
'__version__',
'AsyncClient',
'ChatResponse',
'Client',
Expand All @@ -37,11 +45,13 @@
'ShowResponse',
'StatusResponse',
'Tool',
'version',
'WebFetchResponse',
'WebSearchResponse',
]

_client = Client()
_async_client = AsyncClient()

generate = _client.generate
chat = _client.chat
Expand All @@ -55,5 +65,37 @@
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()