google-gemini / cookbook

Examples and guides for using the Gemini API
https://ai.google.dev/gemini-api/docs
Apache License 2.0
5.46k stars 833 forks source link

Cook book - responseSchema #241

Open LindaLawton opened 4 months ago

LindaLawton commented 4 months ago

Description of the feature request:

Can we get a cookbook for the usage of responseSchema

https://ai.google.dev/api/rest/v1beta/GenerationConfig

What problem are you trying to solve with this feature?

No response

Any other information you'd like to share?

No response

markmcd commented 3 months ago

There's an example in the JSON mode recipe. Are you looking for more advanced examples?

lordsoffallen commented 2 months ago

Examples don't work as expected. Here is an output for trying to use one:

../../../../miniconda3/envs/projx/lib/python3.10/site-packages/vertexai/generative_models/_generative_models.py:1456: in __init__
    gapic_schema_dict = _convert_schema_dict_to_gapic(response_schema)
../../../../miniconda3/envs/projx/lib/python3.10/site-packages/vertexai/generative_models/_generative_models.py:1775: in _convert_schema_dict_to_gapic
    if "type" in gapic_schema_dict:
E   TypeError: argument of type '_TypedDictMeta' is not iterable

I used TypedDict as the cookbook uses it but it doesn't work.

markmcd commented 2 months ago
../../../../miniconda3/envs/projx/lib/python3.10/site-packages/vertexai/generative_models/_generative_models.py:1456: in __init__

I see vertexai in your stack trace. This cookbook is for the Gemini API, not Vertex. We try to keep the SDKs as similar as possible but they aren't 100% drop-in compatible.

I'm able to run the JSON mode recipe from end-to-end without failure or intervention. If you are still seeing an error with the Gemini SDK, can you point to the specific example that fails using the un-edited notebook? Or provide the (edited) code you used so we can try to help.

Or if you have compatibility concerns, the best place for that feedback is in the issue tracker for the relevant SDK(s).