Open jtoy opened 2 weeks ago
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" }
)
@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:
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."
@weilandia Here's my test results:
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 | 🔒 | 🔒 |
does the gem support json mode as outlined here: https://ai.google.dev/gemini-api/docs/api-overview#curl_4