diff --git a/ollama/_client.py b/ollama/_client.py index c1f5f95..3372af4 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -90,11 +90,16 @@ class BaseClient: base_url=_parse_host(host or os.getenv('OLLAMA_HOST')), follow_redirects=follow_redirects, timeout=timeout, + # Lowercase all headers to ensure override headers={ - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'User-Agent': f'ollama-python/{__version__} ({platform.machine()} {platform.system().lower()}) Python/{platform.python_version()}', - }.update(headers or {}), + k.lower(): v + for k, v in { + **(headers or {}), + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'User-Agent': f'ollama-python/{__version__} ({platform.machine()} {platform.system().lower()}) Python/{platform.python_version()}', + }.items() + }, **kwargs, ) diff --git a/tests/test_client.py b/tests/test_client.py index 3bb451c..124ccfc 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -968,3 +968,19 @@ async def test_async_client_copy(httpserver: HTTPServer): client = AsyncClient(httpserver.url_for('/api/copy')) response = await client.copy('dum', 'dummer') assert response['status'] == 'success' + + +def test_headers(): + client = Client() + assert client._client.headers['content-type'] == 'application/json' + assert client._client.headers['accept'] == 'application/json' + assert client._client.headers['user-agent'].startswith('ollama-python/') + + client = Client( + headers={ + 'X-Custom': 'value', + 'Content-Type': 'text/plain', + } + ) + assert client._client.headers['x-custom'] == 'value' + assert client._client.headers['content-type'] == 'application/json'