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

feat: Add support for partial literals and enums #362

Closed

Conversation

lucasastorian
Copy link

@lucasastorian lucasastorian commented Jan 25, 2024


Ellipsis ⚠️ This PR description was created by Ellipsis for commit 23a3abb.

Summary:

This PR modifies the '_make_field_optional' function in 'partial.py' to convert Literal and Enum fields to Optional[str] to prevent streaming failures with OpenAI.

Key points:

  • Added checks in '_make_field_optional' function to convert Literal and Enum fields to Optional[str].
  • This change is made to prevent failures when streaming with OpenAI.

Generated with ❤️ by ellipsis.dev

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Looks good to me!


Something look wrong? You can customize Ellipsis' behavior when reviewing code by editing the config file for this repository.

Generated with ❤️ by ellipsis.dev

@jxnl
Copy link
Collaborator

jxnl commented Jan 25, 2024

beautiful! Can you:

  • add a test
  • making a note of this in the docs?

@jxnl
Copy link
Collaborator

jxnl commented Jan 30, 2024

Looking back, I feel like things should be... validated with and without strict mode. Something we should think harder about.

@lucasastorian
Copy link
Author

Sorry - haven't gotten to this yet. Will take a look tomorrow.

I've been using Partial to stream incomplete tool completions from OpenAI (I added support for tool choice myself). The issue was that (obviously), the Pydantic schema would fail mid-stream, when OpenAI didn't stream the full Literal/Enum value at once. One way to do it, is to validate completed attributes in strict mode, and incomplete attributes ones in unstrict mode. That might be a little overkill though - it's just as easy to validate in unstrict mode during the stream & then in strict mode once complete.

@jxnl
Copy link
Collaborator

jxnl commented Jan 30, 2024

Yeah, let's just do unstrict, doing partial streaming in strict.

@jxnl jxnl self-requested a review January 31, 2024 21:42
@jxnl jxnl changed the title Added support for Partial Models with Literals/Enums by converting th… ... Feb 6, 2024
@jxnl jxnl changed the title ... feat: Add support for partial literals and enums Feb 6, 2024
@jxnl
Copy link
Collaborator

jxnl commented Feb 16, 2024

are you able to add tests?

@jxnl jxnl closed this Apr 8, 2024
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.

2 participants