gbaptista / gemini-ai

A Ruby Gem for interacting with Gemini through Vertex AI, Generative Language API, or AI Studio, Google's generative AI services.
https://rubygems.org/gems/gemini-ai
MIT License
73 stars 17 forks source link

support/docs for json mode #18

Open jtoy opened 2 weeks ago

jtoy commented 2 weeks ago

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

weilandia commented 1 week 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" }
)
gbaptista commented 6 days ago

@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 commented 6 days ago

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 commented 6 days ago

@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 🔒 🔒