mirror of
https://github.com/ollama/ollama-python.git
synced 2026-01-14 06:07:17 +08:00
Merge pull request #58 from ollama/mxyng/python-user-agent
python user agent
This commit is contained in:
commit
fcdf5771f5
@ -3,6 +3,7 @@ import io
|
|||||||
import json
|
import json
|
||||||
import httpx
|
import httpx
|
||||||
import binascii
|
import binascii
|
||||||
|
import platform
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from os import PathLike
|
from os import PathLike
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -18,6 +19,13 @@ if sys.version_info < (3, 9):
|
|||||||
else:
|
else:
|
||||||
from collections.abc import Iterator, AsyncIterator
|
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
|
from ollama._types import Message, Options, RequestError, ResponseError
|
||||||
|
|
||||||
|
|
||||||
@ -37,10 +45,17 @@ class BaseClient:
|
|||||||
- `timeout`: None
|
- `timeout`: None
|
||||||
`kwargs` are passed to the httpx client.
|
`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(
|
self._client = client(
|
||||||
base_url=_parse_host(host or os.getenv('OLLAMA_HOST')),
|
base_url=_parse_host(host or os.getenv('OLLAMA_HOST')),
|
||||||
follow_redirects=follow_redirects,
|
follow_redirects=follow_redirects,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
headers=headers,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user