Skip to content

Commit

Permalink
Fix openapi parameter parsing (#6676)
Browse files Browse the repository at this point in the history
Ensure parameters are json serializable, related to #6671
  • Loading branch information
dev2049 authored Jun 24, 2023
1 parent b7e1c54 commit fa1bb87
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions langchain/chains/openai_functions/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit fa1bb87

Please sign in to comment.