Skip to content

Commit 1d3d1c9

Browse files
yyyu-googlecopybara-github
authored andcommitted
fix: do not raise error for default field in Schema for Gemini API calls
PiperOrigin-RevId: 752544303
1 parent 916bd6e commit 1d3d1c9

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

google/genai/_live_converters.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ def _Schema_to_mldev(
166166
if getv(from_object, ['pattern']) is not None:
167167
raise ValueError('pattern parameter is not supported in Gemini API.')
168168

169-
if getv(from_object, ['default']) is not None:
170-
raise ValueError('default parameter is not supported in Gemini API.')
171-
172169
if getv(from_object, ['max_length']) is not None:
173170
raise ValueError('max_length parameter is not supported in Gemini API.')
174171

@@ -184,6 +181,9 @@ def _Schema_to_mldev(
184181
if getv(from_object, ['any_of']) is not None:
185182
setv(to_object, ['anyOf'], getv(from_object, ['any_of']))
186183

184+
if getv(from_object, ['default']) is not None:
185+
setv(to_object, ['default'], getv(from_object, ['default']))
186+
187187
if getv(from_object, ['description']) is not None:
188188
setv(to_object, ['description'], getv(from_object, ['description']))
189189

@@ -245,9 +245,6 @@ def _Schema_to_vertex(
245245
if getv(from_object, ['pattern']) is not None:
246246
setv(to_object, ['pattern'], getv(from_object, ['pattern']))
247247

248-
if getv(from_object, ['default']) is not None:
249-
setv(to_object, ['default'], getv(from_object, ['default']))
250-
251248
if getv(from_object, ['max_length']) is not None:
252249
setv(to_object, ['maxLength'], getv(from_object, ['max_length']))
253250

@@ -263,6 +260,9 @@ def _Schema_to_vertex(
263260
if getv(from_object, ['any_of']) is not None:
264261
setv(to_object, ['anyOf'], getv(from_object, ['any_of']))
265262

263+
if getv(from_object, ['default']) is not None:
264+
setv(to_object, ['default'], getv(from_object, ['default']))
265+
266266
if getv(from_object, ['description']) is not None:
267267
setv(to_object, ['description'], getv(from_object, ['description']))
268268

google/genai/caches.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ def _Schema_to_mldev(
108108
if getv(from_object, ['pattern']) is not None:
109109
raise ValueError('pattern parameter is not supported in Gemini API.')
110110

111-
if getv(from_object, ['default']) is not None:
112-
raise ValueError('default parameter is not supported in Gemini API.')
113-
114111
if getv(from_object, ['max_length']) is not None:
115112
raise ValueError('max_length parameter is not supported in Gemini API.')
116113

@@ -126,6 +123,9 @@ def _Schema_to_mldev(
126123
if getv(from_object, ['any_of']) is not None:
127124
setv(to_object, ['anyOf'], getv(from_object, ['any_of']))
128125

126+
if getv(from_object, ['default']) is not None:
127+
setv(to_object, ['default'], getv(from_object, ['default']))
128+
129129
if getv(from_object, ['description']) is not None:
130130
setv(to_object, ['description'], getv(from_object, ['description']))
131131

@@ -612,9 +612,6 @@ def _Schema_to_vertex(
612612
if getv(from_object, ['pattern']) is not None:
613613
setv(to_object, ['pattern'], getv(from_object, ['pattern']))
614614

615-
if getv(from_object, ['default']) is not None:
616-
setv(to_object, ['default'], getv(from_object, ['default']))
617-
618615
if getv(from_object, ['max_length']) is not None:
619616
setv(to_object, ['maxLength'], getv(from_object, ['max_length']))
620617

@@ -630,6 +627,9 @@ def _Schema_to_vertex(
630627
if getv(from_object, ['any_of']) is not None:
631628
setv(to_object, ['anyOf'], getv(from_object, ['any_of']))
632629

630+
if getv(from_object, ['default']) is not None:
631+
setv(to_object, ['default'], getv(from_object, ['default']))
632+
633633
if getv(from_object, ['description']) is not None:
634634
setv(to_object, ['description'], getv(from_object, ['description']))
635635

google/genai/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ def _Schema_to_mldev(
109109
if getv(from_object, ['pattern']) is not None:
110110
raise ValueError('pattern parameter is not supported in Gemini API.')
111111

112-
if getv(from_object, ['default']) is not None:
113-
raise ValueError('default parameter is not supported in Gemini API.')
114-
115112
if getv(from_object, ['max_length']) is not None:
116113
raise ValueError('max_length parameter is not supported in Gemini API.')
117114

@@ -127,6 +124,9 @@ def _Schema_to_mldev(
127124
if getv(from_object, ['any_of']) is not None:
128125
setv(to_object, ['anyOf'], getv(from_object, ['any_of']))
129126

127+
if getv(from_object, ['default']) is not None:
128+
setv(to_object, ['default'], getv(from_object, ['default']))
129+
130130
if getv(from_object, ['description']) is not None:
131131
setv(to_object, ['description'], getv(from_object, ['description']))
132132

@@ -1225,9 +1225,6 @@ def _Schema_to_vertex(
12251225
if getv(from_object, ['pattern']) is not None:
12261226
setv(to_object, ['pattern'], getv(from_object, ['pattern']))
12271227

1228-
if getv(from_object, ['default']) is not None:
1229-
setv(to_object, ['default'], getv(from_object, ['default']))
1230-
12311228
if getv(from_object, ['max_length']) is not None:
12321229
setv(to_object, ['maxLength'], getv(from_object, ['max_length']))
12331230

@@ -1243,6 +1240,9 @@ def _Schema_to_vertex(
12431240
if getv(from_object, ['any_of']) is not None:
12441241
setv(to_object, ['anyOf'], getv(from_object, ['any_of']))
12451242

1243+
if getv(from_object, ['default']) is not None:
1244+
setv(to_object, ['default'], getv(from_object, ['default']))
1245+
12461246
if getv(from_object, ['description']) is not None:
12471247
setv(to_object, ['description'], getv(from_object, ['description']))
12481248

google/genai/types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,6 @@ class Schema(_common.BaseModel):
10521052
default=None,
10531053
description="""Optional. Pattern of the Type.STRING to restrict a string to a regular expression.""",
10541054
)
1055-
default: Optional[Any] = Field(
1056-
default=None, description="""Optional. Default value of the data."""
1057-
)
10581055
max_length: Optional[int] = Field(
10591056
default=None,
10601057
description="""Optional. Maximum length of the Type.STRING""",
@@ -1075,6 +1072,9 @@ class Schema(_common.BaseModel):
10751072
default=None,
10761073
description="""Optional. The value should be validated against any (one or more) of the subschemas in the list.""",
10771074
)
1075+
default: Optional[Any] = Field(
1076+
default=None, description="""Optional. Default value of the data."""
1077+
)
10781078
description: Optional[str] = Field(
10791079
default=None, description="""Optional. The description of the data."""
10801080
)
@@ -1484,9 +1484,6 @@ class SchemaDict(TypedDict, total=False):
14841484
pattern: Optional[str]
14851485
"""Optional. Pattern of the Type.STRING to restrict a string to a regular expression."""
14861486

1487-
default: Optional[Any]
1488-
"""Optional. Default value of the data."""
1489-
14901487
max_length: Optional[int]
14911488
"""Optional. Maximum length of the Type.STRING"""
14921489

@@ -1502,6 +1499,9 @@ class SchemaDict(TypedDict, total=False):
15021499
any_of: Optional[list['SchemaDict']]
15031500
"""Optional. The value should be validated against any (one or more) of the subschemas in the list."""
15041501

1502+
default: Optional[Any]
1503+
"""Optional. Default value of the data."""
1504+
15051505
description: Optional[str]
15061506
"""Optional. The description of the data."""
15071507

0 commit comments

Comments
 (0)