Skip to content

Commit 1bd5aa0

Browse files
committed
Fix structured output object selector conversion for OpenAI (home-assistant#150916)
1 parent e4329ab commit 1bd5aa0

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
@@ -91,6 +91,8 @@
9191
def _adjust_schema(schema: dict[str, Any]) -> None:
9292
"""Adjust the schema to be compatible with OpenAI API."""
9393
if schema["type"] == "object":
94+
schema.setdefault("strict", True)
95+
schema.setdefault("additionalProperties", False)
9496
if "properties" not in schema:
9597
return
9698

@@ -124,8 +126,6 @@ def _format_structured_output(
124126

125127
_adjust_schema(result)
126128

127-
result["strict"] = True
128-
result["additionalProperties"] = False
129129
return result
130130

131131

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)