mirror of https://github.com/aliasrobotics/cai.git
fix: raise descriptive error when API returns empty choices list (fixes #415)
This commit is contained in:
parent
7ec0b4ccf2
commit
603af3f16d
|
|
@ -721,6 +721,16 @@ class OpenAIChatCompletionsModel(Model):
|
|||
|
||||
raise
|
||||
|
||||
# Guard against empty choices list which can occur with some API providers
|
||||
# (e.g. Gemini via OpenAI-compatible endpoint) due to content filtering or
|
||||
# transient API errors. Raise a clear error instead of an obscure IndexError.
|
||||
if not response.choices:
|
||||
raise ValueError(
|
||||
f"Model '{self.model}' returned a response with no choices. "
|
||||
"This may be caused by content filtering, rate limiting, or an "
|
||||
"API compatibility issue with the provider."
|
||||
)
|
||||
|
||||
if _debug.DONT_LOG_MODEL_DATA:
|
||||
logger.debug("Received model response")
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in New Issue