mirror of
https://github.com/ollama/ollama-python.git
synced 2026-05-01 11:48:17 +08:00
fix: add missing authorization check in AsyncClient web_search and web_fetch
The sync Client.web_search and Client.web_fetch both validate that a Bearer token is present in the authorization header before making requests to ollama.com API endpoints. However, their async counterparts in AsyncClient are missing this check entirely, allowing unauthenticated requests to go through and fail with unclear server-side errors. Add the same authorization header validation to AsyncClient.web_search and AsyncClient.web_fetch to match the sync implementation and provide clear error messages when credentials are missing. Signed-off-by: JiangNan <1394485448@qq.com>
This commit is contained in:
parent
dbccf192ac
commit
7a36db4abb
@ -801,7 +801,12 @@ class AsyncClient(BaseClient):
|
||||
|
||||
Returns:
|
||||
WebSearchResponse with the search results
|
||||
Raises:
|
||||
ValueError: If OLLAMA_API_KEY environment variable is not set
|
||||
"""
|
||||
if not self._client.headers.get('authorization', '').startswith('Bearer '):
|
||||
raise ValueError('Authorization header with Bearer token is required for web search')
|
||||
|
||||
return await self._request(
|
||||
WebSearchResponse,
|
||||
'POST',
|
||||
@ -821,7 +826,12 @@ class AsyncClient(BaseClient):
|
||||
|
||||
Returns:
|
||||
WebFetchResponse with the fetched result
|
||||
Raises:
|
||||
ValueError: If OLLAMA_API_KEY environment variable is not set
|
||||
"""
|
||||
if not self._client.headers.get('authorization', '').startswith('Bearer '):
|
||||
raise ValueError('Authorization header with Bearer token is required for web fetch')
|
||||
|
||||
return await self._request(
|
||||
WebFetchResponse,
|
||||
'POST',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user