Catch crash when openai compatible endpoints don't return results correctly (#17572)

This commit is contained in:
Josh Hawkins 2025-04-07 07:59:39 -05:00 committed by GitHub
parent 7d7d99cb70
commit a29d4382e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -54,9 +54,13 @@ class OpenAIClient(GenAIClient):
],
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))
return None
if len(result.choices) > 0:
return result.choices[0].message.content.strip()
return None