Skip to content

Commit 3d29a32

Browse files
jscudcopybara-github
authored andcommitted
feat: Update data types from discovery doc.
PiperOrigin-RevId: 841976922
1 parent 436ca2e commit 3d29a32

File tree

7 files changed

+2247
-797
lines changed

7 files changed

+2247
-797
lines changed

google/genai/_live_converters.py

Lines changed: 169 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@
2323
from ._common import set_value_by_path as setv
2424

2525

26+
def _AuthConfig_to_mldev(
27+
from_object: Union[dict[str, Any], object],
28+
parent_object: Optional[dict[str, Any]] = None,
29+
) -> dict[str, Any]:
30+
to_object: dict[str, Any] = {}
31+
if getv(from_object, ['api_key']) is not None:
32+
setv(to_object, ['apiKey'], getv(from_object, ['api_key']))
33+
34+
if getv(from_object, ['api_key_config']) is not None:
35+
raise ValueError('api_key_config parameter is not supported in Gemini API.')
36+
37+
if getv(from_object, ['auth_type']) is not None:
38+
raise ValueError('auth_type parameter is not supported in Gemini API.')
39+
40+
if getv(from_object, ['google_service_account_config']) is not None:
41+
raise ValueError(
42+
'google_service_account_config parameter is not supported in Gemini'
43+
' API.'
44+
)
45+
46+
if getv(from_object, ['http_basic_auth_config']) is not None:
47+
raise ValueError(
48+
'http_basic_auth_config parameter is not supported in Gemini API.'
49+
)
50+
51+
if getv(from_object, ['oauth_config']) is not None:
52+
raise ValueError('oauth_config parameter is not supported in Gemini API.')
53+
54+
if getv(from_object, ['oidc_config']) is not None:
55+
raise ValueError('oidc_config parameter is not supported in Gemini API.')
56+
57+
return to_object
58+
59+
2660
def _Blob_to_mldev(
2761
from_object: Union[dict[str, Any], object],
2862
parent_object: Optional[dict[str, Any]] = None,
@@ -61,6 +95,27 @@ def _Content_to_mldev(
6195
return to_object
6296

6397

98+
def _Content_to_vertex(
99+
from_object: Union[dict[str, Any], object],
100+
parent_object: Optional[dict[str, Any]] = None,
101+
) -> dict[str, Any]:
102+
to_object: dict[str, Any] = {}
103+
if getv(from_object, ['parts']) is not None:
104+
setv(
105+
to_object,
106+
['parts'],
107+
[
108+
_Part_to_vertex(item, to_object)
109+
for item in getv(from_object, ['parts'])
110+
],
111+
)
112+
113+
if getv(from_object, ['role']) is not None:
114+
setv(to_object, ['role'], getv(from_object, ['role']))
115+
116+
return to_object
117+
118+
64119
def _FileData_to_mldev(
65120
from_object: Union[dict[str, Any], object],
66121
parent_object: Optional[dict[str, Any]] = None,
@@ -257,7 +312,11 @@ def _GoogleMaps_to_mldev(
257312
) -> dict[str, Any]:
258313
to_object: dict[str, Any] = {}
259314
if getv(from_object, ['auth_config']) is not None:
260-
raise ValueError('auth_config parameter is not supported in Gemini API.')
315+
setv(
316+
to_object,
317+
['authConfig'],
318+
_AuthConfig_to_mldev(getv(from_object, ['auth_config']), to_object),
319+
)
261320

262321
if getv(from_object, ['enable_widget']) is not None:
263322
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
@@ -270,14 +329,14 @@ def _GoogleSearch_to_mldev(
270329
parent_object: Optional[dict[str, Any]] = None,
271330
) -> dict[str, Any]:
272331
to_object: dict[str, Any] = {}
273-
if getv(from_object, ['exclude_domains']) is not None:
332+
if getv(from_object, ['blocking_confidence']) is not None:
274333
raise ValueError(
275-
'exclude_domains parameter is not supported in Gemini API.'
334+
'blocking_confidence parameter is not supported in Gemini API.'
276335
)
277336

278-
if getv(from_object, ['blocking_confidence']) is not None:
337+
if getv(from_object, ['exclude_domains']) is not None:
279338
raise ValueError(
280-
'blocking_confidence parameter is not supported in Gemini API.'
339+
'exclude_domains parameter is not supported in Gemini API.'
281340
)
282341

283342
if getv(from_object, ['time_range_filter']) is not None:
@@ -309,6 +368,27 @@ def _LiveClientContent_to_mldev(
309368
return to_object
310369

311370

371+
def _LiveClientContent_to_vertex(
372+
from_object: Union[dict[str, Any], object],
373+
parent_object: Optional[dict[str, Any]] = None,
374+
) -> dict[str, Any]:
375+
to_object: dict[str, Any] = {}
376+
if getv(from_object, ['turns']) is not None:
377+
setv(
378+
to_object,
379+
['turns'],
380+
[
381+
_Content_to_vertex(item, to_object)
382+
for item in getv(from_object, ['turns'])
383+
],
384+
)
385+
386+
if getv(from_object, ['turn_complete']) is not None:
387+
setv(to_object, ['turnComplete'], getv(from_object, ['turn_complete']))
388+
389+
return to_object
390+
391+
312392
def _LiveClientMessage_to_mldev(
313393
api_client: BaseApiClient,
314394
from_object: Union[dict[str, Any], object],
@@ -364,7 +444,13 @@ def _LiveClientMessage_to_vertex(
364444
)
365445

366446
if getv(from_object, ['client_content']) is not None:
367-
setv(to_object, ['clientContent'], getv(from_object, ['client_content']))
447+
setv(
448+
to_object,
449+
['clientContent'],
450+
_LiveClientContent_to_vertex(
451+
getv(from_object, ['client_content']), to_object
452+
),
453+
)
368454

369455
if getv(from_object, ['realtime_input']) is not None:
370456
setv(
@@ -558,7 +644,9 @@ def _LiveClientSetup_to_vertex(
558644
setv(
559645
to_object,
560646
['systemInstruction'],
561-
t.t_content(getv(from_object, ['system_instruction'])),
647+
_Content_to_vertex(
648+
t.t_content(getv(from_object, ['system_instruction'])), to_object
649+
),
562650
)
563651

564652
if getv(from_object, ['tools']) is not None:
@@ -857,7 +945,9 @@ def _LiveConnectConfig_to_vertex(
857945
setv(
858946
parent_object,
859947
['setup', 'systemInstruction'],
860-
t.t_content(getv(from_object, ['system_instruction'])),
948+
_Content_to_vertex(
949+
t.t_content(getv(from_object, ['system_instruction'])), to_object
950+
),
861951
)
862952

863953
if getv(from_object, ['tools']) is not None:
@@ -1265,6 +1355,67 @@ def _Part_to_mldev(
12651355
if getv(from_object, ['video_metadata']) is not None:
12661356
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
12671357

1358+
if getv(from_object, ['part_metadata']) is not None:
1359+
setv(to_object, ['partMetadata'], getv(from_object, ['part_metadata']))
1360+
1361+
return to_object
1362+
1363+
1364+
def _Part_to_vertex(
1365+
from_object: Union[dict[str, Any], object],
1366+
parent_object: Optional[dict[str, Any]] = None,
1367+
) -> dict[str, Any]:
1368+
to_object: dict[str, Any] = {}
1369+
if getv(from_object, ['media_resolution']) is not None:
1370+
setv(
1371+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
1372+
)
1373+
1374+
if getv(from_object, ['code_execution_result']) is not None:
1375+
setv(
1376+
to_object,
1377+
['codeExecutionResult'],
1378+
getv(from_object, ['code_execution_result']),
1379+
)
1380+
1381+
if getv(from_object, ['executable_code']) is not None:
1382+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
1383+
1384+
if getv(from_object, ['file_data']) is not None:
1385+
setv(to_object, ['fileData'], getv(from_object, ['file_data']))
1386+
1387+
if getv(from_object, ['function_call']) is not None:
1388+
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
1389+
1390+
if getv(from_object, ['function_response']) is not None:
1391+
setv(
1392+
to_object,
1393+
['functionResponse'],
1394+
getv(from_object, ['function_response']),
1395+
)
1396+
1397+
if getv(from_object, ['inline_data']) is not None:
1398+
setv(to_object, ['inlineData'], getv(from_object, ['inline_data']))
1399+
1400+
if getv(from_object, ['text']) is not None:
1401+
setv(to_object, ['text'], getv(from_object, ['text']))
1402+
1403+
if getv(from_object, ['thought']) is not None:
1404+
setv(to_object, ['thought'], getv(from_object, ['thought']))
1405+
1406+
if getv(from_object, ['thought_signature']) is not None:
1407+
setv(
1408+
to_object,
1409+
['thoughtSignature'],
1410+
getv(from_object, ['thought_signature']),
1411+
)
1412+
1413+
if getv(from_object, ['video_metadata']) is not None:
1414+
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
1415+
1416+
if getv(from_object, ['part_metadata']) is not None:
1417+
raise ValueError('part_metadata parameter is not supported in Vertex AI.')
1418+
12681419
return to_object
12691420

12701421

@@ -1310,6 +1461,13 @@ def _Tool_to_mldev(
13101461
if getv(from_object, ['file_search']) is not None:
13111462
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
13121463

1464+
if getv(from_object, ['google_maps']) is not None:
1465+
setv(
1466+
to_object,
1467+
['googleMaps'],
1468+
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
1469+
)
1470+
13131471
if getv(from_object, ['code_execution']) is not None:
13141472
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
13151473

@@ -1318,13 +1476,6 @@ def _Tool_to_mldev(
13181476
'enterprise_web_search parameter is not supported in Gemini API.'
13191477
)
13201478

1321-
if getv(from_object, ['google_maps']) is not None:
1322-
setv(
1323-
to_object,
1324-
['googleMaps'],
1325-
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
1326-
)
1327-
13281479
if getv(from_object, ['google_search']) is not None:
13291480
setv(
13301481
to_object,
@@ -1369,6 +1520,9 @@ def _Tool_to_vertex(
13691520
if getv(from_object, ['file_search']) is not None:
13701521
raise ValueError('file_search parameter is not supported in Vertex AI.')
13711522

1523+
if getv(from_object, ['google_maps']) is not None:
1524+
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
1525+
13721526
if getv(from_object, ['code_execution']) is not None:
13731527
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
13741528

@@ -1379,9 +1533,6 @@ def _Tool_to_vertex(
13791533
getv(from_object, ['enterprise_web_search']),
13801534
)
13811535

1382-
if getv(from_object, ['google_maps']) is not None:
1383-
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
1384-
13851536
if getv(from_object, ['google_search']) is not None:
13861537
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
13871538

google/genai/_tokens_converters.py

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@
2323
from ._common import set_value_by_path as setv
2424

2525

26+
def _AuthConfig_to_mldev(
27+
from_object: Union[dict[str, Any], object],
28+
parent_object: Optional[dict[str, Any]] = None,
29+
) -> dict[str, Any]:
30+
to_object: dict[str, Any] = {}
31+
if getv(from_object, ['api_key']) is not None:
32+
setv(to_object, ['apiKey'], getv(from_object, ['api_key']))
33+
34+
if getv(from_object, ['api_key_config']) is not None:
35+
raise ValueError('api_key_config parameter is not supported in Gemini API.')
36+
37+
if getv(from_object, ['auth_type']) is not None:
38+
raise ValueError('auth_type parameter is not supported in Gemini API.')
39+
40+
if getv(from_object, ['google_service_account_config']) is not None:
41+
raise ValueError(
42+
'google_service_account_config parameter is not supported in Gemini'
43+
' API.'
44+
)
45+
46+
if getv(from_object, ['http_basic_auth_config']) is not None:
47+
raise ValueError(
48+
'http_basic_auth_config parameter is not supported in Gemini API.'
49+
)
50+
51+
if getv(from_object, ['oauth_config']) is not None:
52+
raise ValueError('oauth_config parameter is not supported in Gemini API.')
53+
54+
if getv(from_object, ['oidc_config']) is not None:
55+
raise ValueError('oidc_config parameter is not supported in Gemini API.')
56+
57+
return to_object
58+
59+
2660
def _Blob_to_mldev(
2761
from_object: Union[dict[str, Any], object],
2862
parent_object: Optional[dict[str, Any]] = None,
@@ -177,7 +211,11 @@ def _GoogleMaps_to_mldev(
177211
) -> dict[str, Any]:
178212
to_object: dict[str, Any] = {}
179213
if getv(from_object, ['auth_config']) is not None:
180-
raise ValueError('auth_config parameter is not supported in Gemini API.')
214+
setv(
215+
to_object,
216+
['authConfig'],
217+
_AuthConfig_to_mldev(getv(from_object, ['auth_config']), to_object),
218+
)
181219

182220
if getv(from_object, ['enable_widget']) is not None:
183221
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
@@ -190,14 +228,14 @@ def _GoogleSearch_to_mldev(
190228
parent_object: Optional[dict[str, Any]] = None,
191229
) -> dict[str, Any]:
192230
to_object: dict[str, Any] = {}
193-
if getv(from_object, ['exclude_domains']) is not None:
231+
if getv(from_object, ['blocking_confidence']) is not None:
194232
raise ValueError(
195-
'exclude_domains parameter is not supported in Gemini API.'
233+
'blocking_confidence parameter is not supported in Gemini API.'
196234
)
197235

198-
if getv(from_object, ['blocking_confidence']) is not None:
236+
if getv(from_object, ['exclude_domains']) is not None:
199237
raise ValueError(
200-
'blocking_confidence parameter is not supported in Gemini API.'
238+
'exclude_domains parameter is not supported in Gemini API.'
201239
)
202240

203241
if getv(from_object, ['time_range_filter']) is not None:
@@ -452,6 +490,9 @@ def _Part_to_mldev(
452490
if getv(from_object, ['video_metadata']) is not None:
453491
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
454492

493+
if getv(from_object, ['part_metadata']) is not None:
494+
setv(to_object, ['partMetadata'], getv(from_object, ['part_metadata']))
495+
455496
return to_object
456497

457498

@@ -497,6 +538,13 @@ def _Tool_to_mldev(
497538
if getv(from_object, ['file_search']) is not None:
498539
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
499540

541+
if getv(from_object, ['google_maps']) is not None:
542+
setv(
543+
to_object,
544+
['googleMaps'],
545+
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
546+
)
547+
500548
if getv(from_object, ['code_execution']) is not None:
501549
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
502550

@@ -505,13 +553,6 @@ def _Tool_to_mldev(
505553
'enterprise_web_search parameter is not supported in Gemini API.'
506554
)
507555

508-
if getv(from_object, ['google_maps']) is not None:
509-
setv(
510-
to_object,
511-
['googleMaps'],
512-
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
513-
)
514-
515556
if getv(from_object, ['google_search']) is not None:
516557
setv(
517558
to_object,

0 commit comments

Comments
 (0)