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

Support Valibot for Structured Outputs #1021

Open
1 task done
fabian-hiller opened this issue Aug 29, 2024 · 6 comments
Open
1 task done

Support Valibot for Structured Outputs #1021

fabian-hiller opened this issue Aug 29, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@fabian-hiller
Copy link

fabian-hiller commented Aug 29, 2024

Confirm this is a feature request for the Node library and not the underlying OpenAI API.

  • This is a feature request for the Node library

Describe the feature or improvement you're requesting

Hi, I am the creator of Valibot and would like to ask if you are interested in supporting Valibot for Structured Outputs besides Zod. If so, I would be happy to help with implementation and documentation.

Valibot is a newer schema validation library for TypeScript that I developed about a year ago as part of my bachelor thesis. Since then, the project has grown a lot and is slowly becoming a popular alternative to Zod. Among our partners are two universities as well as companies like Vercel, Netlify and DigitalOcean. I expect to release our v1 RC in the next 2 weeks. This might be the perfect time to integrate it into the OpenAI Node library.

Feel free to check out our website: https://valibot.dev/

Additional context

We are currently in the process of implementing an official toJsonSchema function for Valibot.

@RobertCraigie RobertCraigie added the enhancement New feature or request label Sep 3, 2024
@RobertCraigie
Copy link
Collaborator

Hey @fabian-hiller, yes of course structured outputs helpers for Valibot is a great idea that we'd be happy to support!

How far along are you with an official toJsonSchema function?

@fabian-hiller
Copy link
Author

I expect to finish the implementation of our official toJsonSchema function next week. Should I follow the implementation for Zod in this repository and create a PR with similar code for Valibot? Have you implemented a custom conversion from Zod to JSON Schema instead of using a community package because Structured Outputs does not support the full JSON Schema spec?

@RobertCraigie
Copy link
Collaborator

I'm not sure if we'd want to go with the exact same implementation to be honest.

The motivation for using our own zod-to-json-schema were:

  • so we could massage the output to be Structured Outputs compatible
  • to avoid adding a new dependency
  • minor dx improvement that users don't have to install zod-to-json-schema themselves

I don't think we'd want to vendor our own json-schema converter for valibot just to keep the SDK from getting too big. Instead we'd likely go with something more similar to our Python SDK where we have a function that ensures a JSON schema is Structured Outputs compatible, instead of baking that into the JSON schema conversion library itelf.

How does that sound to you?

@fabian-hiller
Copy link
Author

For us as a project, it would be an honor and short-term marketing advantage to be part of this library, but otherwise I fully agree that OpenAI should not be forced to maintain an adapter for every schema library.

Should such a function check every schema passed to response_format? Should there be an option to skip this check? Should I create a PR or do you prefer to create this function yourself?

@fabian-hiller
Copy link
Author

We will probably release the first version of our toJsonSchema function tomorrow and would be ready to proceed with the integration into OpenAI's SDK.

@fabian-hiller
Copy link
Author

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

No branches or pull requests

2 participants