-
-
Notifications
You must be signed in to change notification settings - Fork 69
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(gemini): support structured outputs #177
base: main
Are you sure you want to change the base?
Conversation
10ed5fb
to
fac51a4
Compare
fac51a4
to
6e17a45
Compare
Preview deployments for prism ⚡️
Commit: Deployment ID: Static site name: |
I'm not yet familiar with the Gemini API but if it accepts a proper schema that would seem the better route. Do you know if there limitations at all, which would make the Anthropic adaption approach better? We use the Anthropic adaption a lot, and whilst it works most of the time it isn't completely reliable. It goes off piste around 5% of the time. |
Google's docs seem to encourage using the schema via model configuration:
The only potential (sort of) downside is your call will fail if the schema doesn't pass validation which wouldn't happen with the Anthropic approach - personally I'd prefer to know that my schema was invalid and correct it. |
Yea, I see that it would fail at the request level as an advantage - you don't get billed for the tokens for a broken request/response. |
Yep, and additionally I see the 'passing schemas as a message' type approach as a kind of hacky workaround for something that models seem to slowly be adopting more officially. So if there is an official implementation, probably better to work with it. |
I think we should support both the implementation as both are supported by gemini at the moment. #173 similar like openai structred support.
|
Seems like @mattmcdonald-uk appreciate the pull request. Just pulled it into a project and it's working great with gemini-2.0-flash. |
Created this PR before realising this one existed.
The main difference is this PR updates the structured output to match the schema format Google defines. It then passes this directly using
response_schema
rather than appending a message.To me this seems the preferred way of doing it:
response_schema
means you get validation (and relevant errors) on your schema