Skip to content

NVR with realtime local object detection for IP cameras

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

Josh Hawkinsa29d4382e16d
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