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/docs for json mode #18

Open
jtoy opened this issue Jun 11, 2024 · 7 comments
Open

support/docs for json mode #18

jtoy opened this issue Jun 11, 2024 · 7 comments

Comments

@jtoy
Copy link

jtoy commented Jun 11, 2024

does the gem support json mode as outlined here:
https://ai.google.dev/gemini-api/docs/api-overview#curl_4

@weilandia
Copy link
Contributor

The docs here work, but the confusing part is that json mode only works when using Vertex.

https://ai.google.dev/gemini-api/docs/api-overview#json

i.e.

client.generate_content(
  contents: messages,
  system_instructions: options[:system_message],
  generation_config: { response_mime_type: "application/json" }
)

@gbaptista
Copy link
Owner

@weilandia Thanks for testing and sharing! Yeah, I couldn't find examples/documentation to make it work outside of Vertex.

@jtoy Thanks for opening the issue! I added examples and documentation in the README:

@weilandia
Copy link
Contributor

weilandia commented Jun 22, 2024

Heads up: Using JSON schema in the generation config only works with Pro.

"While Gemini 1.5 Flash models only accept a text description of the JSON schema you want returned, the Gemini 1.5 Pro models let you pass a schema object (or a Python type equivalent), and the model output will strictly follow that schema. This is also known as controlled generation or constrained decoding."

@gbaptista
Copy link
Owner

@weilandia Here's my test results:

  • ❌ Does not support JSON mode.
  • 🟡 Supports JSON mode but not Schema.
  • ✅ Supports JSON mode and Schema.
  • 🔒 I don't have access to the model.
Model Vertex AI Generative Language
gemini-pro-vision 🔒
gemini-pro 🟡
gemini-1.5-pro-preview-0514 🔒
gemini-1.5-pro-preview-0409 🔒
gemini-1.5-pro
gemini-1.5-flash-preview-0514 🟡 🔒
gemini-1.5-flash 🟡
gemini-1.0-pro-vision-latest 🔒 🔒
gemini-1.0-pro-vision-001 🔒
gemini-1.0-pro-vision 🔒
gemini-1.0-pro-latest 🔒
gemini-1.0-pro-002 🟡 🔒
gemini-1.0-pro-001
gemini-1.0-pro 🟡
gemini-ultra 🔒 🔒
gemini-1.0-ultra 🔒 🔒
gemini-1.0-ultra-001 🔒 🔒

@asavageiv
Copy link

asavageiv commented Aug 1, 2024

It works with generative language on gemini-1.5-pro on the v1beta endpoint right now with JSON schema.

@heidar
Copy link

heidar commented Sep 18, 2024

It works with generative language on gemini-1.5-pro on the v1beta endpoint right now with JSON schema.

I get a HTTP 400 response when doing this through the gem. The same request via curl seems to work fine though, and returns only JSON.

Either way, seems like Vertex is not needed for JSON responses anymore, but seems there is an issue in this gem stopping it from working?

@heidar
Copy link

heidar commented Sep 18, 2024

It works for me when I set version: "v1beta" under credentials. Seems the default v1 does not support JSON responses.

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

No branches or pull requests

5 participants