Skip to content

Commit 2910346

Browse files
yinghsienwucopybara-github
authored andcommitted
feat: add new fields
PiperOrigin-RevId: 918823690
1 parent 15443c0 commit 2910346

6 files changed

Lines changed: 740 additions & 230 deletions

File tree

google/genai/_live_converters.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ def _Blob_to_mldev(
104104
return to_object
105105

106106

107+
def _CodeExecutionResult_to_vertex(
108+
from_object: Union[dict[str, Any], object],
109+
parent_object: Optional[dict[str, Any]] = None,
110+
) -> dict[str, Any]:
111+
to_object: dict[str, Any] = {}
112+
if getv(from_object, ['outcome']) is not None:
113+
setv(to_object, ['outcome'], getv(from_object, ['outcome']))
114+
115+
if getv(from_object, ['output']) is not None:
116+
setv(to_object, ['output'], getv(from_object, ['output']))
117+
118+
if getv(from_object, ['id']) is not None:
119+
raise ValueError(
120+
'id parameter is only supported in Gemini Developer API mode, not in'
121+
' Gemini Enterprise Agent Platform mode.'
122+
)
123+
124+
return to_object
125+
126+
107127
def _Content_to_mldev(
108128
from_object: Union[dict[str, Any], object],
109129
parent_object: Optional[dict[str, Any]] = None,
@@ -146,6 +166,26 @@ def _Content_to_vertex(
146166
return to_object
147167

148168

169+
def _ExecutableCode_to_vertex(
170+
from_object: Union[dict[str, Any], object],
171+
parent_object: Optional[dict[str, Any]] = None,
172+
) -> dict[str, Any]:
173+
to_object: dict[str, Any] = {}
174+
if getv(from_object, ['code']) is not None:
175+
setv(to_object, ['code'], getv(from_object, ['code']))
176+
177+
if getv(from_object, ['language']) is not None:
178+
setv(to_object, ['language'], getv(from_object, ['language']))
179+
180+
if getv(from_object, ['id']) is not None:
181+
raise ValueError(
182+
'id parameter is only supported in Gemini Developer API mode, not in'
183+
' Gemini Enterprise Agent Platform mode.'
184+
)
185+
186+
return to_object
187+
188+
149189
def _FileData_to_mldev(
150190
from_object: Union[dict[str, Any], object],
151191
parent_object: Optional[dict[str, Any]] = None,
@@ -1591,11 +1631,19 @@ def _Part_to_vertex(
15911631
setv(
15921632
to_object,
15931633
['codeExecutionResult'],
1594-
getv(from_object, ['code_execution_result']),
1634+
_CodeExecutionResult_to_vertex(
1635+
getv(from_object, ['code_execution_result']), to_object
1636+
),
15951637
)
15961638

15971639
if getv(from_object, ['executable_code']) is not None:
1598-
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
1640+
setv(
1641+
to_object,
1642+
['executableCode'],
1643+
_ExecutableCode_to_vertex(
1644+
getv(from_object, ['executable_code']), to_object
1645+
),
1646+
)
15991647

16001648
if getv(from_object, ['file_data']) is not None:
16011649
setv(to_object, ['fileData'], getv(from_object, ['file_data']))

google/genai/batches.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,6 @@ def _EmbedContentConfig_to_mldev(
857857
parent_object: Optional[dict[str, Any]] = None,
858858
) -> dict[str, Any]:
859859
to_object: dict[str, Any] = {}
860-
861860
if getv(from_object, ['task_type']) is not None:
862861
setv(
863862
parent_object,

google/genai/caches.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ def _Blob_to_mldev(
9999
return to_object
100100

101101

102+
def _CodeExecutionResult_to_vertex(
103+
from_object: Union[dict[str, Any], object],
104+
parent_object: Optional[dict[str, Any]] = None,
105+
) -> dict[str, Any]:
106+
to_object: dict[str, Any] = {}
107+
if getv(from_object, ['outcome']) is not None:
108+
setv(to_object, ['outcome'], getv(from_object, ['outcome']))
109+
110+
if getv(from_object, ['output']) is not None:
111+
setv(to_object, ['output'], getv(from_object, ['output']))
112+
113+
if getv(from_object, ['id']) is not None:
114+
raise ValueError(
115+
'id parameter is only supported in Gemini Developer API mode, not in'
116+
' Gemini Enterprise Agent Platform mode.'
117+
)
118+
119+
return to_object
120+
121+
102122
def _Content_to_mldev(
103123
from_object: Union[dict[str, Any], object],
104124
parent_object: Optional[dict[str, Any]] = None,
@@ -362,6 +382,26 @@ def _DeleteCachedContentResponse_from_vertex(
362382
return to_object
363383

364384

385+
def _ExecutableCode_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, ['code']) is not None:
391+
setv(to_object, ['code'], getv(from_object, ['code']))
392+
393+
if getv(from_object, ['language']) is not None:
394+
setv(to_object, ['language'], getv(from_object, ['language']))
395+
396+
if getv(from_object, ['id']) is not None:
397+
raise ValueError(
398+
'id parameter is only supported in Gemini Developer API mode, not in'
399+
' Gemini Enterprise Agent Platform mode.'
400+
)
401+
402+
return to_object
403+
404+
365405
def _FileData_to_mldev(
366406
from_object: Union[dict[str, Any], object],
367407
parent_object: Optional[dict[str, Any]] = None,
@@ -715,11 +755,19 @@ def _Part_to_vertex(
715755
setv(
716756
to_object,
717757
['codeExecutionResult'],
718-
getv(from_object, ['code_execution_result']),
758+
_CodeExecutionResult_to_vertex(
759+
getv(from_object, ['code_execution_result']), to_object
760+
),
719761
)
720762

721763
if getv(from_object, ['executable_code']) is not None:
722-
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
764+
setv(
765+
to_object,
766+
['executableCode'],
767+
_ExecutableCode_to_vertex(
768+
getv(from_object, ['executable_code']), to_object
769+
),
770+
)
723771

724772
if getv(from_object, ['file_data']) is not None:
725773
setv(to_object, ['fileData'], getv(from_object, ['file_data']))

google/genai/models.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,27 @@ def _CitationMetadata_from_mldev(
204204
return to_object
205205

206206

207+
def _CodeExecutionResult_to_vertex(
208+
from_object: Union[dict[str, Any], object],
209+
parent_object: Optional[dict[str, Any]] = None,
210+
root_object: Optional[Union[dict[str, Any], object]] = None,
211+
) -> dict[str, Any]:
212+
to_object: dict[str, Any] = {}
213+
if getv(from_object, ['outcome']) is not None:
214+
setv(to_object, ['outcome'], getv(from_object, ['outcome']))
215+
216+
if getv(from_object, ['output']) is not None:
217+
setv(to_object, ['output'], getv(from_object, ['output']))
218+
219+
if getv(from_object, ['id']) is not None:
220+
raise ValueError(
221+
'id parameter is only supported in Gemini Developer API mode, not in'
222+
' Gemini Enterprise Agent Platform mode.'
223+
)
224+
225+
return to_object
226+
227+
207228
def _ComputeTokensParameters_to_vertex(
208229
api_client: BaseApiClient,
209230
from_object: Union[dict[str, Any], object],
@@ -772,7 +793,6 @@ def _EmbedContentConfig_to_mldev(
772793
root_object: Optional[Union[dict[str, Any], object]] = None,
773794
) -> dict[str, Any]:
774795
to_object: dict[str, Any] = {}
775-
776796
if getv(from_object, ['task_type']) is not None:
777797
setv(
778798
parent_object,
@@ -1108,6 +1128,27 @@ def _Endpoint_from_vertex(
11081128
return to_object
11091129

11101130

1131+
def _ExecutableCode_to_vertex(
1132+
from_object: Union[dict[str, Any], object],
1133+
parent_object: Optional[dict[str, Any]] = None,
1134+
root_object: Optional[Union[dict[str, Any], object]] = None,
1135+
) -> dict[str, Any]:
1136+
to_object: dict[str, Any] = {}
1137+
if getv(from_object, ['code']) is not None:
1138+
setv(to_object, ['code'], getv(from_object, ['code']))
1139+
1140+
if getv(from_object, ['language']) is not None:
1141+
setv(to_object, ['language'], getv(from_object, ['language']))
1142+
1143+
if getv(from_object, ['id']) is not None:
1144+
raise ValueError(
1145+
'id parameter is only supported in Gemini Developer API mode, not in'
1146+
' Gemini Enterprise Agent Platform mode.'
1147+
)
1148+
1149+
return to_object
1150+
1151+
11111152
def _FileData_to_mldev(
11121153
from_object: Union[dict[str, Any], object],
11131154
parent_object: Optional[dict[str, Any]] = None,
@@ -3573,11 +3614,19 @@ def _Part_to_vertex(
35733614
setv(
35743615
to_object,
35753616
['codeExecutionResult'],
3576-
getv(from_object, ['code_execution_result']),
3617+
_CodeExecutionResult_to_vertex(
3618+
getv(from_object, ['code_execution_result']), to_object, root_object
3619+
),
35773620
)
35783621

35793622
if getv(from_object, ['executable_code']) is not None:
3580-
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))
3623+
setv(
3624+
to_object,
3625+
['executableCode'],
3626+
_ExecutableCode_to_vertex(
3627+
getv(from_object, ['executable_code']), to_object, root_object
3628+
),
3629+
)
35813630

35823631
if getv(from_object, ['file_data']) is not None:
35833632
setv(to_object, ['fileData'], getv(from_object, ['file_data']))

0 commit comments

Comments
 (0)