mirror of
https://github.com/home-assistant/core.git
synced 2025-09-04 04:11:37 +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:
|
def _adjust_schema(schema: dict[str, Any]) -> None:
|
||||||
"""Adjust the schema to be compatible with OpenAI API."""
|
"""Adjust the schema to be compatible with OpenAI API."""
|
||||||
if schema["type"] == "object":
|
if schema["type"] == "object":
|
||||||
|
schema.setdefault("strict", True)
|
||||||
|
schema.setdefault("additionalProperties", False)
|
||||||
if "properties" not in schema:
|
if "properties" not in schema:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -125,8 +127,6 @@ def _format_structured_output(
|
|||||||
|
|
||||||
_adjust_schema(result)
|
_adjust_schema(result)
|
||||||
|
|
||||||
result["strict"] = True
|
|
||||||
result["additionalProperties"] = False
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@@ -63,6 +63,8 @@ async def test_format_structured_output() -> None:
|
|||||||
"item_value",
|
"item_value",
|
||||||
],
|
],
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
|
"strict": True,
|
||||||
},
|
},
|
||||||
"type": "array",
|
"type": "array",
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user