Catch crash when openai compatible endpoints don't return results correctly

This commit is contained in:
Josh Hawkins 2025-04-06 23:06:15 -05:00
parent 7d7d99cb70
commit 069c08be58

View File

@ -54,9 +54,13 @@ class OpenAIClient(GenAIClient):
], ],
timeout=self.timeout, timeout=self.timeout,
) )
except TimeoutException as e: if (
result is not None
and hasattr(result, "choices")
and len(result.choices) > 0
):
return result.choices[0].message.content.strip()
return None
except (TimeoutException, Exception) as e:
logger.warning("OpenAI returned an error: %s", str(e)) logger.warning("OpenAI returned an error: %s", str(e))
return None return None
if len(result.choices) > 0:
return result.choices[0].message.content.strip()
return None