diff --git a/ollama/_client.py b/ollama/_client.py index c5aa1bc..607f12c 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -3,6 +3,7 @@ import json import httpx import binascii +import platform import urllib.parse from os import PathLike from pathlib import Path @@ -18,6 +19,13 @@ else: from collections.abc import Iterator, AsyncIterator +from importlib import metadata + +try: + __version__ = metadata.version('ollama') +except metadata.PackageNotFoundError: + __version__ = '0.0.0' + from ollama._types import Message, Options, RequestError, ResponseError @@ -37,10 +45,17 @@ def __init__( - `timeout`: None `kwargs` are passed to the httpx client. """ + + headers = kwargs.pop('headers', {}) + headers['Content-Type'] = 'application/json' + headers['Accept'] = 'application/json' + headers['User-Agent'] = f'ollama-python/{__version__} ({platform.machine()} {platform.system().lower()}) Python/{platform.python_version()}' + self._client = client( base_url=_parse_host(host or os.getenv('OLLAMA_HOST')), follow_redirects=follow_redirects, timeout=timeout, + headers=headers, **kwargs, )