openai[patch]: fix schema formatting util (#27685)

This commit is contained in:
Bagatur
2024-10-28 08:46:47 -07:00
committed by GitHub
parent 440c162b8b
commit ede953d617
2 changed files with 47 additions and 3 deletions

View File

@@ -2143,9 +2143,13 @@ def _convert_to_openai_response_format(
if isinstance(schema, type) and is_basemodel_subclass(schema):
return schema
if "json_schema" in schema and schema.get("type") == "json_schema":
if (
isinstance(schema, dict)
and "json_schema" in schema
and schema.get("type") == "json_schema"
):
response_format = schema
elif "name" in schema and "schema" in schema:
elif isinstance(schema, dict) and "name" in schema and "schema" in schema:
response_format = {"type": "json_schema", "json_schema": schema}
else:
strict = strict if strict is not None else True