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

[WIP] Gemini Structured Outputs #116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

btumbleson
Copy link

Hey folks, this is a bit beyond my comfort zone, but wanted to share my WIP code for structured outputs with Gemini.

This code is working for me with a handful of somewhat complex schemas (I've explicitly used/ tested the Object, Array, String and Number schemas, with nesting), although I acknowledge I haven't attached any tests here (yet).

Some observations that may need to be addressed more meaningfully:

  • The ObjectSchema defines an allowAdditionalProperties key which is valid for OpenAI, but not for Gemini. As the schema itself isn't aware of the Provider being chosen, without doing some injection/ facade/ whatever, it was easier to just strip this key out after the toArray() map. There may need to be a longer term decision made here based on how other providers treat their schema definitions, or perhaps a provider-specific map() or toArray() handler for the schema.
  • Gemini doesn't appear to have multiple structured options like OpenAI, so the StructuredModeResolver is a bit superfluous. Granted it's still a valid check on if a specific model supports structured mode, but I skipped this logic inclusion in my WIP pass here as all "current" Gemini models (excluding v1 Pro) support structured outputs.

Thoughts on a path forward to formalizing this?

Copy link

netlify bot commented Jan 9, 2025

Deploy Preview for stunning-cannoli-238aa5 ready!

Name Link
🔨 Latest commit db9781b
🔍 Latest deploy log https://app.netlify.com/sites/stunning-cannoli-238aa5/deploys/6780179c197bf00008c85552
😎 Deploy Preview https://deploy-preview-116--stunning-cannoli-238aa5.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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