From 069c08be58656e03881b75042c76b932f1f53380 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Sun, 6 Apr 2025 23:06:15 -0500 Subject: [PATCH] Catch crash when openai compatible endpoints don't return results correctly --- frigate/genai/openai.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frigate/genai/openai.py b/frigate/genai/openai.py index 4b1926099e..76ba8cb442 100644 --- a/frigate/genai/openai.py +++ b/frigate/genai/openai.py @@ -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