google-gemini / generative-ai-python

The official Python library for the Google Gemini API

Home Page:https://pypi.org/project/google-generativeai/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

response_schema not working with gemini-1.5-pro model

kunalhexus opened this issue · comments

Description of the bug:

I ended up wasting 2 hours on trying to get it to work after seeing the official documentation for contstrained generation on https://ai.google.dev/gemini-api/docs/api-overview#json

Thanks for the pro tip of adding the schema to system prompt mentioned on #343 I was finally able to get it working.

The code generated on https://aistudio.google.com/ is also exteremly deceptive as it makes you input the schema making you believe that constrained generation is working and gives back the code which has no reference to JSON schema specified in Advanced Settings

Actual vs expected behavior:

response_schema in model configuration should be respected without having to explcitly add the whole schema to system prompt

Any other information you'd like to share?

No response

@kunalhexus, I can see response_schema working with python sdk 0.5.4.
Ref: screenshot below.
Can you please share a reproducible code to replicate the error on our end. Thank you!

image

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

This issue was closed because it has been inactive for 28 days. Please post a new issue if you need further assistance. Thanks!