File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 33import json
44import httpx
55import binascii
6+ import platform
67import urllib .parse
78from os import PathLike
89from pathlib import Path
1819else :
1920 from collections .abc import Iterator , AsyncIterator
2021
22+ from importlib import metadata
23+
24+ try :
25+ __version__ = metadata .version ('ollama' )
26+ except metadata .PackageNotFoundError :
27+ __version__ = '0.0.0'
28+
2129from ollama ._types import Message , Options , RequestError , ResponseError
2230
2331
@@ -37,10 +45,17 @@ def __init__(
3745 - `timeout`: None
3846 `kwargs` are passed to the httpx client.
3947 """
48+
49+ headers = kwargs .pop ('headers' , {})
50+ headers ['Content-Type' ] = 'application/json'
51+ headers ['Accept' ] = 'application/json'
52+ headers ['User-Agent' ] = f'ollama-python/{ __version__ } ({ platform .machine ()} { platform .system ().lower ()} ) Python/{ platform .python_version ()} '
53+
4054 self ._client = client (
4155 base_url = _parse_host (host or os .getenv ('OLLAMA_HOST' )),
4256 follow_redirects = follow_redirects ,
4357 timeout = timeout ,
58+ headers = headers ,
4459 ** kwargs ,
4560 )
4661
You can’t perform that action at this time.
0 commit comments