diff --git a/frigate/genai/__init__.py b/frigate/genai/__init__.py index e26b50757..3bc98100c 100644 --- a/frigate/genai/__init__.py +++ b/frigate/genai/__init__.py @@ -153,9 +153,6 @@ Each line represents a detection state, not necessarily unique individuals. The if "other_concerns" in schema.get("required", []): schema["required"].remove("other_concerns") - # OpenAI strict mode requires additionalProperties: false on all objects - schema["additionalProperties"] = False - response_format = { "type": "json_schema", "json_schema": { diff --git a/frigate/genai/openai.py b/frigate/genai/openai.py index af94859de..432641332 100644 --- a/frigate/genai/openai.py +++ b/frigate/genai/openai.py @@ -73,8 +73,17 @@ class OpenAIClient(GenAIClient): **self.genai_config.runtime_options, } if response_format: + # OpenAI strict mode requires additionalProperties: false on the schema + if response_format.get("type") == "json_schema" and response_format.get( + "json_schema", {} + ).get("strict"): + schema = response_format.get("json_schema", {}).get("schema") + if isinstance(schema, dict): + schema["additionalProperties"] = False request_params["response_format"] = response_format + result = self.provider.chat.completions.create(**request_params) + if ( result is not None and hasattr(result, "choices")