File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 3
3
import json
4
4
import httpx
5
5
import binascii
6
+ import platform
6
7
import urllib .parse
7
8
from os import PathLike
8
9
from pathlib import Path
18
19
else :
19
20
from collections .abc import Iterator , AsyncIterator
20
21
22
+ from importlib import metadata
23
+
24
+ try :
25
+ __version__ = metadata .version ('ollama' )
26
+ except metadata .PackageNotFoundError :
27
+ __version__ = '0.0.0'
28
+
21
29
from ollama ._types import Message , Options , RequestError , ResponseError
22
30
23
31
@@ -37,10 +45,15 @@ def __init__(
37
45
- `timeout`: None
38
46
`kwargs` are passed to the httpx client.
39
47
"""
48
+
49
+ headers = kwargs .pop ('headers' , {})
50
+ headers ['user-agent' ] = f'ollama-python/{ __version__ } ({ platform .machine ()} { platform .system ().lower ()} ) Python/{ platform .python_version ()} '
51
+
40
52
self ._client = client (
41
53
base_url = _parse_host (host or os .getenv ('OLLAMA_HOST' )),
42
54
follow_redirects = follow_redirects ,
43
55
timeout = timeout ,
56
+ headers = headers ,
44
57
** kwargs ,
45
58
)
46
59
You can’t perform that action at this time.
0 commit comments