Open ganjigajanan opened 4 months ago
Hi @ganjigajanan,
I have tried in the similar way passing the generation_config
while declaring the model and it works for me as expected, can you take a look at the gist try and let me know if still the error persists.
model = genai.GenerativeModel(
model_name="gemini-1.5-pro-latest",
generation_config={"response_mime_type": "application/json", "response_schema": TextSummary},
)
Thanks
Hi,
I have the same error. Running Python 3.10.2 on Mac.
Was there a resolution to this? Could it be to do with Pydantic version?
Cheers,
David
Update:
I did a check on my pydantic install, which was as follows: pydantic==1.10.14 pydantic_core==2.14.6
Upgrading pydantic yielded: pydantic==2.8.2 pydantic_core==2.20.1
With this the KeyError issue is removed and the Gemini API performs as expected. (Now I need to check for any dependencies on my project to the Pydantic v1...)
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.
I'm also having an issue with response_schema not working as intended. It appears to ignore all keys of a Dict except the first one. This is my class:
class SubtitleObject(typing.TypedDict):
index: str
content: str
This is the response I'm getting:
[{'index': '0'}, {'index': '1'}, {'index': '2'}, {'index': '3'}, {'index': '4'}, {'index': '5'}, {'index': '6'}, {'index': '7'}, {'index': '8'}, {'index': '9'}, {'index': '10'}]
Even the official docs show the same bug:
Description of the bug:
Hello, I'm trying to recreate the example at: https://github.com/google-gemini/cookbook/blob/main/examples/json_capabilities/Text_Summarization.ipynb. After specifying the classes and creating the
generation_config
, while invoking thegenai.GenerativeModel
model withgeneration_config
results in aKeyError
.Actual vs expected behavior:
No response
Any other information you'd like to share?
No response