Skip to content

Commit 546440c

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 PiperOrigin-RevId: 885278310
1 parent be8cd49 commit 546440c

7 files changed

Lines changed: 697 additions & 58 deletions

File tree

google/genai/_live_converters.py

Lines changed: 122 additions & 3 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:
@@ -1403,6 +1455,73 @@ def _Part_to_mldev(
14031455
if getv(from_object, ['video_metadata']) is not None:
14041456
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
14051457

1458+
if getv(from_object, ['tool_call']) is not None:
1459+
setv(to_object, ['toolCall'], getv(from_object, ['tool_call']))
1460+
1461+
if getv(from_object, ['tool_response']) is not None:
1462+
setv(to_object, ['toolResponse'], getv(from_object, ['tool_response']))
1463+
1464+
return to_object
1465+
1466+
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, ['media_resolution']) is not None:
1473+
setv(
1474+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
1475+
)
1476+
1477+
if getv(from_object, ['code_execution_result']) is not None:
1478+
setv(
1479+
to_object,
1480+
['codeExecutionResult'],
1481+
getv(from_object, ['code_execution_result']),
1482+
)
1483+
1484+
if getv(from_object, ['executable_code']) is not None:
1485+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
1486+
1487+
if getv(from_object, ['file_data']) is not None:
1488+
setv(to_object, ['fileData'], getv(from_object, ['file_data']))
1489+
1490+
if getv(from_object, ['function_call']) is not None:
1491+
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
1492+
1493+
if getv(from_object, ['function_response']) is not None:
1494+
setv(
1495+
to_object,
1496+
['functionResponse'],
1497+
getv(from_object, ['function_response']),
1498+
)
1499+
1500+
if getv(from_object, ['inline_data']) is not None:
1501+
setv(to_object, ['inlineData'], getv(from_object, ['inline_data']))
1502+
1503+
if getv(from_object, ['text']) is not None:
1504+
setv(to_object, ['text'], getv(from_object, ['text']))
1505+
1506+
if getv(from_object, ['thought']) is not None:
1507+
setv(to_object, ['thought'], getv(from_object, ['thought']))
1508+
1509+
if getv(from_object, ['thought_signature']) is not None:
1510+
setv(
1511+
to_object,
1512+
['thoughtSignature'],
1513+
getv(from_object, ['thought_signature']),
1514+
)
1515+
1516+
if getv(from_object, ['video_metadata']) is not None:
1517+
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
1518+
1519+
if getv(from_object, ['tool_call']) is not None:
1520+
raise ValueError('tool_call parameter is not supported in Vertex AI.')
1521+
1522+
if getv(from_object, ['tool_response']) is not None:
1523+
raise ValueError('tool_response parameter is not supported in Vertex AI.')
1524+
14061525
return to_object
14071526

14081527

google/genai/_tokens_converters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ def _Part_to_mldev(
515515
if getv(from_object, ['video_metadata']) is not None:
516516
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
517517

518+
if getv(from_object, ['tool_call']) is not None:
519+
setv(to_object, ['toolCall'], getv(from_object, ['tool_call']))
520+
521+
if getv(from_object, ['tool_response']) is not None:
522+
setv(to_object, ['toolResponse'], getv(from_object, ['tool_response']))
523+
518524
return to_object
519525

520526

google/genai/batches.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,12 @@ def _Part_to_mldev(
14541454
if getv(from_object, ['video_metadata']) is not None:
14551455
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
14561456

1457+
if getv(from_object, ['tool_call']) is not None:
1458+
setv(to_object, ['toolCall'], getv(from_object, ['tool_call']))
1459+
1460+
if getv(from_object, ['tool_response']) is not None:
1461+
setv(to_object, ['toolResponse'], getv(from_object, ['tool_response']))
1462+
14571463
return to_object
14581464

14591465

@@ -1493,6 +1499,13 @@ def _ToolConfig_to_mldev(
14931499
),
14941500
)
14951501

1502+
if getv(from_object, ['include_server_side_tool_invocations']) is not None:
1503+
setv(
1504+
to_object,
1505+
['includeServerSideToolInvocations'],
1506+
getv(from_object, ['include_server_side_tool_invocations']),
1507+
)
1508+
14961509
return to_object
14971510

14981511

google/genai/caches.py

Lines changed: 133 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,27 @@ def _Content_to_mldev(
105105
return to_object
106106

107107

108+
def _Content_to_vertex(
109+
from_object: Union[dict[str, Any], object],
110+
parent_object: Optional[dict[str, Any]] = None,
111+
) -> dict[str, Any]:
112+
to_object: dict[str, Any] = {}
113+
if getv(from_object, ['parts']) is not None:
114+
setv(
115+
to_object,
116+
['parts'],
117+
[
118+
_Part_to_vertex(item, to_object)
119+
for item in getv(from_object, ['parts'])
120+
],
121+
)
122+
123+
if getv(from_object, ['role']) is not None:
124+
setv(to_object, ['role'], getv(from_object, ['role']))
125+
126+
return to_object
127+
128+
108129
def _CreateCachedContentConfig_to_mldev(
109130
from_object: Union[dict[str, Any], object],
110131
parent_object: Optional[dict[str, Any]] = None,
@@ -181,14 +202,19 @@ def _CreateCachedContentConfig_to_vertex(
181202
setv(
182203
parent_object,
183204
['contents'],
184-
[item for item in t.t_contents(getv(from_object, ['contents']))],
205+
[
206+
_Content_to_vertex(item, to_object)
207+
for item in t.t_contents(getv(from_object, ['contents']))
208+
],
185209
)
186210

187211
if getv(from_object, ['system_instruction']) is not None:
188212
setv(
189213
parent_object,
190214
['systemInstruction'],
191-
t.t_content(getv(from_object, ['system_instruction'])),
215+
_Content_to_vertex(
216+
t.t_content(getv(from_object, ['system_instruction'])), to_object
217+
),
192218
)
193219

194220
if getv(from_object, ['tools']) is not None:
@@ -202,7 +228,11 @@ def _CreateCachedContentConfig_to_vertex(
202228
)
203229

204230
if getv(from_object, ['tool_config']) is not None:
205-
setv(parent_object, ['toolConfig'], getv(from_object, ['tool_config']))
231+
setv(
232+
parent_object,
233+
['toolConfig'],
234+
_ToolConfig_to_vertex(getv(from_object, ['tool_config']), to_object),
235+
)
206236

207237
if getv(from_object, ['kms_key_name']) is not None:
208238
setv(
@@ -667,6 +697,73 @@ def _Part_to_mldev(
667697
if getv(from_object, ['video_metadata']) is not None:
668698
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
669699

700+
if getv(from_object, ['tool_call']) is not None:
701+
setv(to_object, ['toolCall'], getv(from_object, ['tool_call']))
702+
703+
if getv(from_object, ['tool_response']) is not None:
704+
setv(to_object, ['toolResponse'], getv(from_object, ['tool_response']))
705+
706+
return to_object
707+
708+
709+
def _Part_to_vertex(
710+
from_object: Union[dict[str, Any], object],
711+
parent_object: Optional[dict[str, Any]] = None,
712+
) -> dict[str, Any]:
713+
to_object: dict[str, Any] = {}
714+
if getv(from_object, ['media_resolution']) is not None:
715+
setv(
716+
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
717+
)
718+
719+
if getv(from_object, ['code_execution_result']) is not None:
720+
setv(
721+
to_object,
722+
['codeExecutionResult'],
723+
getv(from_object, ['code_execution_result']),
724+
)
725+
726+
if getv(from_object, ['executable_code']) is not None:
727+
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
728+
729+
if getv(from_object, ['file_data']) is not None:
730+
setv(to_object, ['fileData'], getv(from_object, ['file_data']))
731+
732+
if getv(from_object, ['function_call']) is not None:
733+
setv(to_object, ['functionCall'], getv(from_object, ['function_call']))
734+
735+
if getv(from_object, ['function_response']) is not None:
736+
setv(
737+
to_object,
738+
['functionResponse'],
739+
getv(from_object, ['function_response']),
740+
)
741+
742+
if getv(from_object, ['inline_data']) is not None:
743+
setv(to_object, ['inlineData'], getv(from_object, ['inline_data']))
744+
745+
if getv(from_object, ['text']) is not None:
746+
setv(to_object, ['text'], getv(from_object, ['text']))
747+
748+
if getv(from_object, ['thought']) is not None:
749+
setv(to_object, ['thought'], getv(from_object, ['thought']))
750+
751+
if getv(from_object, ['thought_signature']) is not None:
752+
setv(
753+
to_object,
754+
['thoughtSignature'],
755+
getv(from_object, ['thought_signature']),
756+
)
757+
758+
if getv(from_object, ['video_metadata']) is not None:
759+
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
760+
761+
if getv(from_object, ['tool_call']) is not None:
762+
raise ValueError('tool_call parameter is not supported in Vertex AI.')
763+
764+
if getv(from_object, ['tool_response']) is not None:
765+
raise ValueError('tool_response parameter is not supported in Vertex AI.')
766+
670767
return to_object
671768

672769

@@ -689,6 +786,39 @@ def _ToolConfig_to_mldev(
689786
),
690787
)
691788

789+
if getv(from_object, ['include_server_side_tool_invocations']) is not None:
790+
setv(
791+
to_object,
792+
['includeServerSideToolInvocations'],
793+
getv(from_object, ['include_server_side_tool_invocations']),
794+
)
795+
796+
return to_object
797+
798+
799+
def _ToolConfig_to_vertex(
800+
from_object: Union[dict[str, Any], object],
801+
parent_object: Optional[dict[str, Any]] = None,
802+
) -> dict[str, Any]:
803+
to_object: dict[str, Any] = {}
804+
if getv(from_object, ['retrieval_config']) is not None:
805+
setv(
806+
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
807+
)
808+
809+
if getv(from_object, ['function_calling_config']) is not None:
810+
setv(
811+
to_object,
812+
['functionCallingConfig'],
813+
getv(from_object, ['function_calling_config']),
814+
)
815+
816+
if getv(from_object, ['include_server_side_tool_invocations']) is not None:
817+
raise ValueError(
818+
'include_server_side_tool_invocations parameter is not supported in'
819+
' Vertex AI.'
820+
)
821+
692822
return to_object
693823

694824

0 commit comments

Comments
 (0)