File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -90,11 +90,16 @@ def __init__(
90
90
base_url = _parse_host (host or os .getenv ('OLLAMA_HOST' )),
91
91
follow_redirects = follow_redirects ,
92
92
timeout = timeout ,
93
+ # Lowercase all headers to ensure override
93
94
headers = {
94
- 'Content-Type' : 'application/json' ,
95
- 'Accept' : 'application/json' ,
96
- 'User-Agent' : f'ollama-python/{ __version__ } ({ platform .machine ()} { platform .system ().lower ()} ) Python/{ platform .python_version ()} ' ,
97
- }.update (headers or {}),
95
+ k .lower (): v
96
+ for k , v in {
97
+ ** (headers or {}),
98
+ 'Content-Type' : 'application/json' ,
99
+ 'Accept' : 'application/json' ,
100
+ 'User-Agent' : f'ollama-python/{ __version__ } ({ platform .machine ()} { platform .system ().lower ()} ) Python/{ platform .python_version ()} ' ,
101
+ }.items ()
102
+ },
98
103
** kwargs ,
99
104
)
100
105
Original file line number Diff line number Diff line change @@ -968,3 +968,19 @@ async def test_async_client_copy(httpserver: HTTPServer):
968
968
client = AsyncClient (httpserver .url_for ('/api/copy' ))
969
969
response = await client .copy ('dum' , 'dummer' )
970
970
assert response ['status' ] == 'success'
971
+
972
+
973
+ def test_headers ():
974
+ client = Client ()
975
+ assert client ._client .headers ['content-type' ] == 'application/json'
976
+ assert client ._client .headers ['accept' ] == 'application/json'
977
+ assert client ._client .headers ['user-agent' ].startswith ('ollama-python/' )
978
+
979
+ client = Client (
980
+ headers = {
981
+ 'X-Custom' : 'value' ,
982
+ 'Content-Type' : 'text/plain' ,
983
+ }
984
+ )
985
+ assert client ._client .headers ['x-custom' ] == 'value'
986
+ assert client ._client .headers ['content-type' ] == 'application/json'
You can’t perform that action at this time.
0 commit comments