Fix openapi parameter parsing (#6676)

Ensure parameters are json serializable, related to #6671
This commit is contained in:
Davis Chase 2023-06-23 21:19:12 -07:00 committed by GitHub
parent b7e1c54947
commit fa1bb873e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,7 +78,7 @@ def _openapi_params_to_json_schema(params: List[Parameter], spec: OpenAPISpec) -
schema = spec.get_schema(media_type_schema)
if p.description and not schema.description:
schema.description = p.description
properties[p.name] = schema.dict(exclude_none=True)
properties[p.name] = json.loads(schema.json(exclude_none=True))
if p.required:
required.append(p.name)
return {"type": "object", "properties": properties, "required": required}
@ -132,7 +132,9 @@ def openapi_spec_to_openai_fn(
for media_type, media_type_object in request_body.content.items():
if media_type_object.media_type_schema:
schema = spec.get_schema(media_type_object.media_type_schema)
media_types[media_type] = schema.dict(exclude_none=True)
media_types[media_type] = json.loads(
schema.json(exclude_none=True)
)
if len(media_types) == 1:
media_type, schema_dict = list(media_types.items())[0]
key = "json" if media_type == "application/json" else "data"