mirror of
https://github.com/home-assistant/core.git
synced 2025-09-01 10:51:47 +02:00
Fix structured output object selector conversion for OpenAI (#150916)
This commit is contained in:
@@ -92,6 +92,8 @@ MAX_TOOL_ITERATIONS = 10
|
||||
def _adjust_schema(schema: dict[str, Any]) -> None:
|
||||
"""Adjust the schema to be compatible with OpenAI API."""
|
||||
if schema["type"] == "object":
|
||||
schema.setdefault("strict", True)
|
||||
schema.setdefault("additionalProperties", False)
|
||||
if "properties" not in schema:
|
||||
return
|
||||
|
||||
@@ -125,8 +127,6 @@ def _format_structured_output(
|
||||
|
||||
_adjust_schema(result)
|
||||
|
||||
result["strict"] = True
|
||||
result["additionalProperties"] = False
|
||||
return result
|
||||
|
||||
|
||||
|
@@ -63,6 +63,8 @@ async def test_format_structured_output() -> None:
|
||||
"item_value",
|
||||
],
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"strict": True,
|
||||
},
|
||||
"type": "array",
|
||||
},
|
||||
|
Reference in New Issue
Block a user