google-gemini / generative-ai-python

The official Python library for the Google Gemini API
https://pypi.org/project/google-generativeai/
Apache License 2.0
1.45k stars 281 forks source link

TypeError when running the example #497

Closed fabiorangel closed 1 month ago

fabiorangel commented 1 month ago

Description of the bug:

I am running exactly this example which is also defined as a test:

import typing_extensions as typing

class Recipe(typing.TypedDict):
    recipe_name: str

model = genai.GenerativeModel("gemini-1.5-pro-latest")
result = model.generate_content(
    "List a few popular cookie recipes.",
    generation_config=genai.GenerationConfig(
        response_mime_type="application/json", response_schema=list([Recipe])
    ),
)

The code is presented here for method models.generateContent: https://ai.google.dev/api/generate-content?hl=pt-br#method:-models.generatecontent

This is also a test defined here: https://github.com/google-gemini/generative-ai-python/blob/42d952a2429fa72c0f2617d71eb9aa3f708b6867/samples/controlled_generation.py#L18

It is raising TypeError: TypeError: pop expected at most 1 argument, got 2

Actual vs expected behavior:

I expected the example to work with no errors and maybe this test is not being used.

Any other information you'd like to share?

Python version: Python 3.10.12 Working on Databricks using the runtime: 14.3 LTS

MarkDaoust commented 1 month ago

Yeah, I haven't enabled testing for these yet.

list([Recipe])

Should be list[Recipe].