Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep required fields spec in the structured-output schema #643

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion google/generativeai/types/content_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ def strip_titles(schema):
def add_object_type(schema):
properties = schema.get("properties", None)
if properties is not None:
schema.pop("required", None)
schema["type"] = "object"
for name, value in properties.items():
add_object_type(value)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ def b():
protos.Schema(
type=protos.Type.OBJECT,
properties={"a": {"type_": protos.Type.INTEGER}},
required=["a"],
),
],
[
Expand All @@ -566,6 +567,7 @@ def b():
type=protos.Type.OBJECT,
nullable=True,
properties={"a": {"type_": protos.Type.INTEGER}},
required=["a"],
),
],
[
Expand All @@ -576,6 +578,7 @@ def b():
items=protos.Schema(
type=protos.Type.OBJECT,
properties={"a": {"type_": protos.Type.INTEGER}},
required="a",
),
),
],
Expand All @@ -585,6 +588,7 @@ def b():
protos.Schema(
type=protos.Type.OBJECT,
properties={"a": {"type_": protos.Type.INTEGER, "nullable": True}},
required=["a"],
),
],
[
Expand All @@ -593,6 +597,7 @@ def b():
protos.Schema(
type=protos.Type.OBJECT,
properties={"a": {"type_": "ARRAY", "items": {"type_": "INTEGER"}}},
required=["a"],
),
],
[
Expand All @@ -602,6 +607,7 @@ def b():
items=protos.Schema(
type=protos.Type.OBJECT,
properties={"a": {"type_": "ARRAY", "items": {"type_": "INTEGER"}}},
required="a",
),
type="ARRAY",
),
Expand All @@ -622,6 +628,7 @@ def b():
properties={
"a": {"type_": protos.Type.INTEGER},
},
required=["a"],
),
],
[
Expand All @@ -635,8 +642,10 @@ def b():
properties={
"a": {"type_": protos.Type.INTEGER},
},
required=["a"],
),
},
required="x",
),
],
["enum", Choices, protos.Schema(type=protos.Type.STRING, enum=["a", "b", "c", "d"])],
Expand All @@ -656,6 +665,7 @@ def b():
properties={
"choice": protos.Schema(type=protos.Type.STRING, enum=["a", "b", "c", "d"])
},
required=["choice"],
),
],
)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,10 @@ def test_repr_for_generate_content_response_from_iterator(self):
month=protos.Schema(type="INTEGER"),
year=protos.Schema(type="INTEGER"),
),
required=["day", "month", "year"],
),
),
required=["name", "favorite_color", "birthday"],
),
],
)
Expand Down