Skip to content

Commit e68df66

Browse files
authored
Fix structured output object selector conversion for OpenAI (home-assistant#150916)
1 parent 8d30d69 commit e68df66

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

homeassistant/components/openai_conversation/entity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
def _adjust_schema(schema: dict[str, Any]) -> None:
9393
"""Adjust the schema to be compatible with OpenAI API."""
9494
if schema["type"] == "object":
95+
schema.setdefault("strict", True)
96+
schema.setdefault("additionalProperties", False)
9597
if "properties" not in schema:
9698
return
9799

@@ -125,8 +127,6 @@ def _format_structured_output(
125127

126128
_adjust_schema(result)
127129

128-
result["strict"] = True
129-
result["additionalProperties"] = False
130130
return result
131131

132132

tests/components/openai_conversation/test_entity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ async def test_format_structured_output() -> None:
6363
"item_value",
6464
],
6565
"type": "object",
66+
"additionalProperties": False,
67+
"strict": True,
6668
},
6769
"type": "array",
6870
},

0 commit comments

Comments
 (0)