From a29d4382e16dbf3d19812373695f1e48ff616d25 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Mon, 7 Apr 2025 07:59:39 -0500 Subject: [PATCH] Catch crash when openai compatible endpoints don't return results correctly (#17572) --- 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 4b1926099..76ba8cb44 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