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.62k stars 322 forks source link

Not able to set `seed` parameter in `generation_config` #536

Open zya opened 2 months ago

zya commented 2 months ago

Description of the bug:

Both of the following results in an error.

model = genai.GenerativeModel(
        model_name="models/gemini-1.5-pro-001",
        system_instruction=(...),
        generation_config={
           ...,
           "seed": 1
        }
    )
model = genai.GenerativeModel(
        model_name="models/gemini-1.5-pro-001",
        system_instruction=(...),
        generation_config={
           ...,
        }
    )
model.generate_content(prompt, generation_config={"seed": 1})

Error:

ValueError: Unknown field for GenerationConfig: seed

Seed is mentioned in the docs here:

Actual vs expected behavior:

Actual: Error is thrown when seed is used in generation_config Expected: seed to be supported and passed to the underlying generate content API.

Any other information you'd like to share?

No response

Gunand3043 commented 2 months ago

Hi @zya,

You can set the seed parameter in generation_config only when using the Vertex AI SDK. For reference, you can check this link. If you are using Python SDK, here is the documentation link.

zya commented 2 months ago

@Gunand3043 Thanks. Do you happen to know why seed isn't supported? And more generally, what is the purpose of having these two API's separate? Are we supposed to use Gemini API for experimentation and Vertex for production?

Gunand3043 commented 2 months ago

At the moment, I'm not exactly sure why 'seed' isn't supported in the Google AI SDK.

I kind of agree with your idea of using the Google AI SDK for experimentation and the Vertex AI SDK for production. Since Vertex AI SDK offers more features than the Google AI SDK, such as deploying generative AI applications and building solutions end-to-end, Vertex AI is the better option. For a more detailed comparison, please check out the below link.

Hope it helps.

zya commented 2 months ago

In that case perhaps we want to change the type of this ticket to be a feature request to add support for seed in the Gemini API?

t1u1 commented 2 months ago

What does "seed" not supported in Gemini API mean? That it is constant or random?

In other words, I would like to know if the responses for the same input and configuration are going to be the same, or they will be different for each invocation?

MarkDaoust commented 2 months ago

Right now it's different each time. They're working on it.