-
Notifications
You must be signed in to change notification settings - Fork 1
Fix model construct #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
partial=True, | ||
) | ||
for ingredient in validated.ingredients: | ||
assert isinstance(ingredient, Recipe.Ingredient) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want to check ingredient.name == "salt" ?
assert isinstance(constructed, ListOfModels) | ||
assert isinstance(constructed.models, list) | ||
assert isinstance(constructed.models[0], NestedModel) | ||
assert isinstance(constructed.models[1], NestedModel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So models[1] is a NestedModel without the "field2" attribute?
That would mean that accessing NestedModel.field2 on the chunk processing will raise an AttributeError. And this error can be predicted by the type check... So that will crash at runtime.
I don't have the perfect solution for that. Maybe we should enforce all agent output classes to only have optionals when streaming in the newest SDK versions ? If not raise an error even before starting the stream ?
This way field2 will be None instead of absent; and you are forced by the type checker to handle the case where "field2" is None in the stream processing...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mention the caveat of non optional fields in the Readme.
There is no way to do "partial validation" in Pydantic unfortunately.
Another way to handle the issue would be to compute "healthy defaults" for each field but it might get quite complex.. I'll make a quick attempt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok 👌, thank you!
Having warnings when streaming an output with non-optional would be useful too.
thanks @guillaq, one important comment, I think Also, do we have an issue to update the SDK version for our API? |
@yannbu I managed to create an optional version of pydantic models to allow for partial validation of payloads. I'll check autopilot with it. |
We do not |
Found an issue with autopilot where we were streaming dictionaries instead of pydantic objects when the output had nested objects.
The issue was undetected until now because: