Skip to content

Commit

Permalink
Merge pull request #58 from ollama/mxyng/python-user-agent
Browse files Browse the repository at this point in the history
python user agent
  • Loading branch information
mxyng authored Feb 9, 2024
2 parents eee32dd + ec8bf88 commit fcdf577
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ollama/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import httpx
import binascii
import platform
import urllib.parse
from os import PathLike
from pathlib import Path
Expand All @@ -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


Expand All @@ -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,
)

Expand Down

0 comments on commit fcdf577

Please sign in to comment.