Skip to content
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

assistants: fallback type in discriminated unions #1615

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kristapratico
Copy link
Contributor

@kristapratico kristapratico commented Aug 8, 2024

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Provides a well-defined behavior / fallback type for response data that doesn't fit any known type in a discriminated union. Aims to handle more gracefully the scenario in which a client may be using a version of the library that does not yet know about a tool type / its response.

Additional context & links

#1574

@kristapratico kristapratico requested a review from a team as a code owner August 8, 2024 00:33
Comment on lines -359 to +363
type_ = field.annotation
if field.metadata:
type_ = wrap_in_annotated_type(field)
else:
type_ = field.annotation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case where the response data for a union field doesn't conform to expected (i.e. we fail the validate_type call), we seem to lose the metadata (which has the discriminator info) when constructing the field. This makes the code construct the first type present in the union instead of creating the actual known type. Test case illustrating this here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant