Skip to content

Commit

Permalink
Fix response_schema with TypedDict
Browse files Browse the repository at this point in the history
  • Loading branch information
Surya2k1 committed Nov 28, 2024
1 parent b8772ed commit c7e9884
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion google/generativeai/types/content_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ def _build_schema(fname, fields_dict):
for name, value in defs.items():
unpack_defs(value, defs)
unpack_defs(parameters, defs)

required_fields = []
if (fname == "dummy" and fields_dict["dummy"]):
required_fields = parameters['properties'][fname].get('required',None)
# 5. Nullable fields:
# * https://github.com/pydantic/pydantic/issues/1270
# * https://stackoverflow.com/a/58841311
Expand All @@ -435,6 +437,8 @@ def _build_schema(fname, fields_dict):
# * https://github.com/pydantic/pydantic/issues/1051
# * http://cl/586221780
strip_titles(parameters)
if required_fields:
parameters['properties']['dummy']['required']= required_fields
return parameters


Expand Down
1 change: 1 addition & 0 deletions tests/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ def test_repr_for_generate_content_response_from_iterator(self):
),
),
),
required=list(("name", "favorite_color", "birthday"))
),
],
)
Expand Down

0 comments on commit c7e9884

Please sign in to comment.