RequestError is documented in four methods but never raised
What
Four docstrings in ollama/_client.py promise a RequestError:
Client.generate— line 278Client.chat— line 385AsyncClient.generate— line 938AsyncClient.chat— line 1044
"""
Create a response using the requested model.
Raises `RequestError` if a model is not provided.
Raises `ResponseError` if the request could not be fulfilled.
...
"""
But searching the package finds no raise RequestError anywhere:
_client.py:278 / 385 / 938 / 1044 -> docstrings only
_types.py:696 -> class definition
__init__.py:13 / 47 -> export
What actually happens
client.generate(model='') builds GenerateRequest(model=''), which validates
fine (model: str accepts the empty string), sends {"model": ""} to the
server, gets a 400 back, and the client raises ResponseError.
So code written to the docstring never catches anything:
try:
client.generate(model='')
except RequestError: # unreachable
...
Why I am opening an issue instead of a PR
There are two reasonable fixes and I do not want to pick one for you:
- Make it real — validate locally and
raise RequestError('model is required')before sending. This changes behaviour: the call no longer reaches the network, and callers catchingResponseErrorwould need to addRequestError. - Make the docs true — delete the
Raises RequestErrorline from the four docstrings, sinceResponseErroralready covers the failure.
Option 1 matches the docstrings. Option 2 matches the current design. Either is fine by me; I will send a PR for whichever you prefer.
Happy to also add a regression test in tests/test_client.py that pins the
chosen behaviour.
Hi! I'd like to pick this up. I'd go with option 2 (remove the Raises RequestError line from the four docstrings), since it matches current behavior and doesn't change what callers catch. If you'd rather have option 1 (validate locally and raise RequestError), I can do that with a test instead. Which do you prefer?