@@ -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+
108129def _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