Skip to content

Commit aee2eaf

Browse files
jscudcopybara-github
authored andcommitted
feat: Update data types from discovery doc.
PiperOrigin-RevId: 841976922
1 parent a484746 commit aee2eaf

File tree

7 files changed

+2578
-842
lines changed

7 files changed

+2578
-842
lines changed

google/genai/_live_converters.py

Lines changed: 191 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:
@@ -1327,6 +1417,67 @@ def _Part_to_mldev(
13271417
if getv(from_object, ['video_metadata']) is not None:
13281418
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
13291419

1420+
if getv(from_object, ['part_metadata']) is not None:
1421+
setv(to_object, ['partMetadata'], getv(from_object, ['part_metadata']))
1422+
1423+
return to_object
1424+
1425+
1426+
def _Part_to_vertex(
1427+
from_object: Union[dict[str, Any], object],
1428+
parent_object: Optional[dict[str, Any]] = None,
1429+
) -> dict[str, Any]:
1430+
to_object: dict[str, Any] = {}
1431+
if getv(from_object, ['media_resolution']) is not None:
1432+
setv(
1433+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
1434+
)
1435+
1436+
if getv(from_object, ['code_execution_result']) is not None:
1437+
setv(
1438+
to_object,
1439+
['codeExecutionResult'],
1440+
getv(from_object, ['code_execution_result']),
1441+
)
1442+
1443+
if getv(from_object, ['executable_code']) is not None:
1444+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
1445+
1446+
if getv(from_object, ['file_data']) is not None:
1447+
setv(to_object, ['fileData'], getv(from_object, ['file_data']))
1448+
1449+
if getv(from_object, ['function_call']) is not None:
1450+
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
1451+
1452+
if getv(from_object, ['function_response']) is not None:
1453+
setv(
1454+
to_object,
1455+
['functionResponse'],
1456+
getv(from_object, ['function_response']),
1457+
)
1458+
1459+
if getv(from_object, ['inline_data']) is not None:
1460+
setv(to_object, ['inlineData'], getv(from_object, ['inline_data']))
1461+
1462+
if getv(from_object, ['text']) is not None:
1463+
setv(to_object, ['text'], getv(from_object, ['text']))
1464+
1465+
if getv(from_object, ['thought']) is not None:
1466+
setv(to_object, ['thought'], getv(from_object, ['thought']))
1467+
1468+
if getv(from_object, ['thought_signature']) is not None:
1469+
setv(
1470+
to_object,
1471+
['thoughtSignature'],
1472+
getv(from_object, ['thought_signature']),
1473+
)
1474+
1475+
if getv(from_object, ['video_metadata']) is not None:
1476+
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
1477+
1478+
if getv(from_object, ['part_metadata']) is not None:
1479+
raise ValueError('part_metadata parameter is not supported in Vertex AI.')
1480+
13301481
return to_object
13311482

13321483

@@ -1358,6 +1509,13 @@ def _Tool_to_mldev(
13581509
if getv(from_object, ['file_search']) is not None:
13591510
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
13601511

1512+
if getv(from_object, ['google_maps']) is not None:
1513+
setv(
1514+
to_object,
1515+
['googleMaps'],
1516+
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
1517+
)
1518+
13611519
if getv(from_object, ['code_execution']) is not None:
13621520
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
13631521

@@ -1373,13 +1531,6 @@ def _Tool_to_mldev(
13731531
[item for item in getv(from_object, ['function_declarations'])],
13741532
)
13751533

1376-
if getv(from_object, ['google_maps']) is not None:
1377-
setv(
1378-
to_object,
1379-
['googleMaps'],
1380-
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
1381-
)
1382-
13831534
if getv(from_object, ['google_search']) is not None:
13841535
setv(
13851536
to_object,
@@ -1394,9 +1545,21 @@ def _Tool_to_mldev(
13941545
getv(from_object, ['google_search_retrieval']),
13951546
)
13961547

1548+
if getv(from_object, ['parallel_ai_search']) is not None:
1549+
raise ValueError(
1550+
'parallel_ai_search parameter is not supported in Gemini API.'
1551+
)
1552+
13971553
if getv(from_object, ['url_context']) is not None:
13981554
setv(to_object, ['urlContext'], getv(from_object, ['url_context']))
13991555

1556+
if getv(from_object, ['mcp_servers']) is not None:
1557+
setv(
1558+
to_object,
1559+
['mcpServers'],
1560+
[item for item in getv(from_object, ['mcp_servers'])],
1561+
)
1562+
14001563
return to_object
14011564

14021565

@@ -1414,6 +1577,9 @@ def _Tool_to_vertex(
14141577
if getv(from_object, ['file_search']) is not None:
14151578
raise ValueError('file_search parameter is not supported in Vertex AI.')
14161579

1580+
if getv(from_object, ['google_maps']) is not None:
1581+
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
1582+
14171583
if getv(from_object, ['code_execution']) is not None:
14181584
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
14191585

@@ -1434,9 +1600,6 @@ def _Tool_to_vertex(
14341600
],
14351601
)
14361602

1437-
if getv(from_object, ['google_maps']) is not None:
1438-
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
1439-
14401603
if getv(from_object, ['google_search']) is not None:
14411604
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
14421605

@@ -1447,9 +1610,19 @@ def _Tool_to_vertex(
14471610
getv(from_object, ['google_search_retrieval']),
14481611
)
14491612

1613+
if getv(from_object, ['parallel_ai_search']) is not None:
1614+
setv(
1615+
to_object,
1616+
['parallelAiSearch'],
1617+
getv(from_object, ['parallel_ai_search']),
1618+
)
1619+
14501620
if getv(from_object, ['url_context']) is not None:
14511621
setv(to_object, ['urlContext'], getv(from_object, ['url_context']))
14521622

1623+
if getv(from_object, ['mcp_servers']) is not None:
1624+
raise ValueError('mcp_servers parameter is not supported in Vertex AI.')
1625+
14531626
return to_object
14541627

14551628

0 commit comments

Comments
 (0)