Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhu authored Apr 30, 2024
2 parents 98541ae + ba9ff45 commit 68592e1
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions autogen/_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ def type2schema(t: Any) -> JsonSchemaValue:
Returns:
JsonSchemaValue: The JSON schema
"""
if PYDANTIC_V1:
if t is None:
return {"type": "null"}
elif get_origin(t) is Union:
return {"anyOf": [type2schema(tt) for tt in get_args(t)]}
elif get_origin(t) in [Tuple, tuple]:
prefixItems = [type2schema(tt) for tt in get_args(t)]
return {
"maxItems": len(prefixItems),
"minItems": len(prefixItems),
"prefixItems": prefixItems,
"type": "array",
}

d = schema_of(t)
if "title" in d:
d.pop("title")
if "description" in d:
d.pop("description")

return d

if t is None:
return {"type": "null"}
elif get_origin(t) is Union:
return {"anyOf": [type2schema(tt) for tt in get_args(t)]}
elif get_origin(t) in [Tuple, tuple]:
prefixItems = [type2schema(tt) for tt in get_args(t)]
return {
"maxItems": len(prefixItems),
"minItems": len(prefixItems),
"prefixItems": prefixItems,
"type": "array",
}
else:
d = schema_of(t)
if "title" in d:
d.pop("title")
if "description" in d:
d.pop("description")

return d

def model_dump(model: BaseModel) -> Dict[str, Any]:
"""Convert a pydantic model to a dict
Expand Down

0 comments on commit 68592e1

Please sign in to comment.