Skip to content

Commit f337c2c

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: Support include_server_side_tool_invocations for genai.
Adds ToolConfig.include_server_side_tool_invocations Adds ExecutableCode.id Adds CodeExecutionResult.id Adds ToolCall and ToolResponse FUTURE_COPYBARA_INTEGRATE_REVIEW=#2125 from googleapis:release-please--branches--main 0061b63 PiperOrigin-RevId: 876445909
1 parent ff7469a commit f337c2c

7 files changed

Lines changed: 735 additions & 96 deletions

File tree

google/genai/_live_converters.py

Lines changed: 128 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ def _Content_to_mldev(
106106
return to_object
107107

108108

109+
def _Content_to_vertex(
110+
from_object: Union[dict[str, Any], object],
111+
parent_object: Optional[dict[str, Any]] = None,
112+
) -> dict[str, Any]:
113+
to_object: dict[str, Any] = {}
114+
if getv(from_object, ['parts']) is not None:
115+
setv(
116+
to_object,
117+
['parts'],
118+
[
119+
_Part_to_vertex(item, to_object)
120+
for item in getv(from_object, ['parts'])
121+
],
122+
)
123+
124+
if getv(from_object, ['role']) is not None:
125+
setv(to_object, ['role'], getv(from_object, ['role']))
126+
127+
return to_object
128+
129+
109130
def _FileData_to_mldev(
110131
from_object: Union[dict[str, Any], object],
111132
parent_object: Optional[dict[str, Any]] = None,
@@ -361,6 +382,27 @@ def _LiveClientContent_to_mldev(
361382
return to_object
362383

363384

385+
def _LiveClientContent_to_vertex(
386+
from_object: Union[dict[str, Any], object],
387+
parent_object: Optional[dict[str, Any]] = None,
388+
) -> dict[str, Any]:
389+
to_object: dict[str, Any] = {}
390+
if getv(from_object, ['turns']) is not None:
391+
setv(
392+
to_object,
393+
['turns'],
394+
[
395+
_Content_to_vertex(item, to_object)
396+
for item in getv(from_object, ['turns'])
397+
],
398+
)
399+
400+
if getv(from_object, ['turn_complete']) is not None:
401+
setv(to_object, ['turnComplete'], getv(from_object, ['turn_complete']))
402+
403+
return to_object
404+
405+
364406
def _LiveClientMessage_to_mldev(
365407
api_client: BaseApiClient,
366408
from_object: Union[dict[str, Any], object],
@@ -416,7 +458,13 @@ def _LiveClientMessage_to_vertex(
416458
)
417459

418460
if getv(from_object, ['client_content']) is not None:
419-
setv(to_object, ['clientContent'], getv(from_object, ['client_content']))
461+
setv(
462+
to_object,
463+
['clientContent'],
464+
_LiveClientContent_to_vertex(
465+
getv(from_object, ['client_content']), to_object
466+
),
467+
)
420468

421469
if getv(from_object, ['realtime_input']) is not None:
422470
setv(
@@ -617,7 +665,9 @@ def _LiveClientSetup_to_vertex(
617665
setv(
618666
to_object,
619667
['systemInstruction'],
620-
t.t_content(getv(from_object, ['system_instruction'])),
668+
_Content_to_vertex(
669+
t.t_content(getv(from_object, ['system_instruction'])), to_object
670+
),
621671
)
622672

623673
if getv(from_object, ['tools']) is not None:
@@ -930,7 +980,9 @@ def _LiveConnectConfig_to_vertex(
930980
setv(
931981
parent_object,
932982
['setup', 'systemInstruction'],
933-
t.t_content(getv(from_object, ['system_instruction'])),
983+
_Content_to_vertex(
984+
t.t_content(getv(from_object, ['system_instruction'])), to_object
985+
),
934986
)
935987

936988
if getv(from_object, ['tools']) is not None:
@@ -1344,10 +1396,8 @@ def _Part_to_mldev(
13441396
parent_object: Optional[dict[str, Any]] = None,
13451397
) -> dict[str, Any]:
13461398
to_object: dict[str, Any] = {}
1347-
if getv(from_object, ['media_resolution']) is not None:
1348-
setv(
1349-
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
1350-
)
1399+
if getv(from_object, ['executable_code']) is not None:
1400+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
13511401

13521402
if getv(from_object, ['code_execution_result']) is not None:
13531403
setv(
@@ -1356,8 +1406,16 @@ def _Part_to_mldev(
13561406
getv(from_object, ['code_execution_result']),
13571407
)
13581408

1359-
if getv(from_object, ['executable_code']) is not None:
1360-
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
1409+
if getv(from_object, ['media_resolution']) is not None:
1410+
setv(
1411+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
1412+
)
1413+
1414+
if getv(from_object, ['tool_call']) is not None:
1415+
setv(to_object, ['toolCall'], getv(from_object, ['tool_call']))
1416+
1417+
if getv(from_object, ['tool_response']) is not None:
1418+
setv(to_object, ['toolResponse'], getv(from_object, ['tool_response']))
13611419

13621420
if getv(from_object, ['file_data']) is not None:
13631421
setv(
@@ -1406,6 +1464,67 @@ def _Part_to_mldev(
14061464
return to_object
14071465

14081466

1467+
def _Part_to_vertex(
1468+
from_object: Union[dict[str, Any], object],
1469+
parent_object: Optional[dict[str, Any]] = None,
1470+
) -> dict[str, Any]:
1471+
to_object: dict[str, Any] = {}
1472+
if getv(from_object, ['executable_code']) is not None:
1473+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
1474+
1475+
if getv(from_object, ['code_execution_result']) is not None:
1476+
setv(
1477+
to_object,
1478+
['codeExecutionResult'],
1479+
getv(from_object, ['code_execution_result']),
1480+
)
1481+
1482+
if getv(from_object, ['media_resolution']) is not None:
1483+
setv(
1484+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
1485+
)
1486+
1487+
if getv(from_object, ['tool_call']) is not None:
1488+
raise ValueError('tool_call parameter is not supported in Vertex AI.')
1489+
1490+
if getv(from_object, ['tool_response']) is not None:
1491+
raise ValueError('tool_response parameter is not supported in Vertex AI.')
1492+
1493+
if getv(from_object, ['file_data']) is not None:
1494+
setv(to_object, ['fileData'], getv(from_object, ['file_data']))
1495+
1496+
if getv(from_object, ['function_call']) is not None:
1497+
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
1498+
1499+
if getv(from_object, ['function_response']) is not None:
1500+
setv(
1501+
to_object,
1502+
['functionResponse'],
1503+
getv(from_object, ['function_response']),
1504+
)
1505+
1506+
if getv(from_object, ['inline_data']) is not None:
1507+
setv(to_object, ['inlineData'], getv(from_object, ['inline_data']))
1508+
1509+
if getv(from_object, ['text']) is not None:
1510+
setv(to_object, ['text'], getv(from_object, ['text']))
1511+
1512+
if getv(from_object, ['thought']) is not None:
1513+
setv(to_object, ['thought'], getv(from_object, ['thought']))
1514+
1515+
if getv(from_object, ['thought_signature']) is not None:
1516+
setv(
1517+
to_object,
1518+
['thoughtSignature'],
1519+
getv(from_object, ['thought_signature']),
1520+
)
1521+
1522+
if getv(from_object, ['video_metadata']) is not None:
1523+
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
1524+
1525+
return to_object
1526+
1527+
14091528
def _SessionResumptionConfig_to_mldev(
14101529
from_object: Union[dict[str, Any], object],
14111530
parent_object: Optional[dict[str, Any]] = None,

google/genai/_tokens_converters.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,8 @@ def _Part_to_mldev(
456456
parent_object: Optional[dict[str, Any]] = None,
457457
) -> dict[str, Any]:
458458
to_object: dict[str, Any] = {}
459-
if getv(from_object, ['media_resolution']) is not None:
460-
setv(
461-
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
462-
)
459+
if getv(from_object, ['executable_code']) is not None:
460+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
463461

464462
if getv(from_object, ['code_execution_result']) is not None:
465463
setv(
@@ -468,8 +466,16 @@ def _Part_to_mldev(
468466
getv(from_object, ['code_execution_result']),
469467
)
470468

471-
if getv(from_object, ['executable_code']) is not None:
472-
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
469+
if getv(from_object, ['media_resolution']) is not None:
470+
setv(
471+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
472+
)
473+
474+
if getv(from_object, ['tool_call']) is not None:
475+
setv(to_object, ['toolCall'], getv(from_object, ['tool_call']))
476+
477+
if getv(from_object, ['tool_response']) is not None:
478+
setv(to_object, ['toolResponse'], getv(from_object, ['tool_response']))
473479

474480
if getv(from_object, ['file_data']) is not None:
475481
setv(

google/genai/batches.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,8 @@ def _Part_to_mldev(
13951395
parent_object: Optional[dict[str, Any]] = None,
13961396
) -> dict[str, Any]:
13971397
to_object: dict[str, Any] = {}
1398-
if getv(from_object, ['media_resolution']) is not None:
1399-
setv(
1400-
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
1401-
)
1398+
if getv(from_object, ['executable_code']) is not None:
1399+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
14021400

14031401
if getv(from_object, ['code_execution_result']) is not None:
14041402
setv(
@@ -1407,8 +1405,16 @@ def _Part_to_mldev(
14071405
getv(from_object, ['code_execution_result']),
14081406
)
14091407

1410-
if getv(from_object, ['executable_code']) is not None:
1411-
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
1408+
if getv(from_object, ['media_resolution']) is not None:
1409+
setv(
1410+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
1411+
)
1412+
1413+
if getv(from_object, ['tool_call']) is not None:
1414+
setv(to_object, ['toolCall'], getv(from_object, ['tool_call']))
1415+
1416+
if getv(from_object, ['tool_response']) is not None:
1417+
setv(to_object, ['toolResponse'], getv(from_object, ['tool_response']))
14121418

14131419
if getv(from_object, ['file_data']) is not None:
14141420
setv(
@@ -1484,6 +1490,13 @@ def _ToolConfig_to_mldev(
14841490
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
14851491
)
14861492

1493+
if getv(from_object, ['include_server_side_tool_invocations']) is not None:
1494+
setv(
1495+
to_object,
1496+
['includeServerSideToolInvocations'],
1497+
getv(from_object, ['include_server_side_tool_invocations']),
1498+
)
1499+
14871500
if getv(from_object, ['function_calling_config']) is not None:
14881501
setv(
14891502
to_object,

0 commit comments

Comments
 (0)