fix: pydantic schema parser now supports nested objects
Updated.
fix: fixes pydantic parser to support nested objects.
This fails before the PR and succeeds afterward:
from pydantic import BaseModel
from typing import List, Optional
from crewai.utilities.pydantic_schema_parser import PydanticSchemaParser
class InnerModel(BaseModel):
inner_field: int
class TestModel(BaseModel):
simple_field: str
list_field: List[int]
optional_field: Optional[str]
nested_model: InnerModel
print(PydanticSchemaParser(model=InnerModel).get_schema()) # works
print(PydanticSchemaParser(model=TestModel).get_schema()) # fails
Note. Because the main branch currently doesn't support nested
schemas and the original code against which I made this PR months ago
drifted, I made a judgement call on how to format the nested
structures. I chose the following, inferred from the current code:
>>> print(PydanticSchemaParser(model=InnerModel).get_schema())
{
inner_field: int
}
>>> print(PydanticSchemaParser(model=TestModel).get_schema())
{
simple_field: str,
list_field: List[int],
optional_field: Optional[str],
nested_model: InnerModel
{
inner_field: int
}
}
```
Thanks for this. Struggling with this error atm. Hopefully this is merged.
Nice! I see there are some conlicts, I'll try to fix it
Hey @inchoate! Thanks for your pull request!
We've made quite a few changes since July, so could you take a moment to check if everything is still relevant and working as it should? If it is, just give us a shout— we’d love to help you get it merged!
Thanks
Updated.
@pythonbyte @joaomdmoura
Let me know if you want a new PR b/c of the force push.