mirror of
https://github.com/NousResearch/atropos.git
synced 2026-04-22 16:48:57 +00:00
preserve descs
This commit is contained in:
parent
e40dce445c
commit
8c9752b731
1 changed files with 11 additions and 1 deletions
|
|
@ -8,7 +8,17 @@ def get_prefixed_pydantic_model(base_model: BaseModel, prefix: str) -> BaseModel
|
|||
fields = {}
|
||||
for name, field in base_model.model_fields.items():
|
||||
new_name = f"{prefix}{name}"
|
||||
fields[new_name] = (field.annotation, field.default)
|
||||
|
||||
# Preserve field metadata, especially description
|
||||
field_kwargs = {}
|
||||
if hasattr(field, "description") and field.description is not None:
|
||||
field_kwargs["description"] = field.description
|
||||
|
||||
fields[new_name] = (
|
||||
field.annotation,
|
||||
Field(default=field.default, **field_kwargs),
|
||||
)
|
||||
|
||||
return create_model(f"{prefix.capitalize()}{base_model.__name__}", **fields)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue