@@ -2302,13 +2302,13 @@ def text(self) -> str:
2302
2302
) from e
2303
2303
2304
2304
@property
2305
- def function_calls (self ) -> Sequence [gapic_tool_types . FunctionCall ]:
2305
+ def function_calls (self ) -> Sequence [" FunctionCall" ]:
2306
2306
if not self .content or not self .content .parts :
2307
2307
return []
2308
2308
return [
2309
2309
part .function_call
2310
2310
for part in self .content .parts
2311
- if part and part . function_call
2311
+ if part . _raw_part . _pb . WhichOneof ( "data" ) == " function_call"
2312
2312
]
2313
2313
2314
2314
@@ -2483,8 +2483,12 @@ def file_data(self) -> gapic_content_types.FileData:
2483
2483
return self ._raw_part .file_data
2484
2484
2485
2485
@property
2486
- def function_call (self ) -> gapic_tool_types .FunctionCall :
2487
- return self ._raw_part .function_call
2486
+ def function_call (self ) -> "FunctionCall" :
2487
+ return (
2488
+ FunctionCall ._from_gapic (self ._raw_part .function_call )
2489
+ if self ._raw_part .function_call
2490
+ else None
2491
+ )
2488
2492
2489
2493
@property
2490
2494
def function_response (self ) -> gapic_tool_types .FunctionResponse :
@@ -2495,6 +2499,40 @@ def _image(self) -> "Image":
2495
2499
return Image .from_bytes (data = self ._raw_part .inline_data .data )
2496
2500
2497
2501
2502
+ class FunctionCall :
2503
+ """Function call."""
2504
+
2505
+ def __init__ (
2506
+ self ,
2507
+ * ,
2508
+ name : str ,
2509
+ args : Dict [str , Any ],
2510
+ ):
2511
+ self ._raw_message = aiplatform_types .FunctionCall (name = name , args = args )
2512
+
2513
+ @classmethod
2514
+ def _from_gapic (cls , raw_message : aiplatform_types .FunctionCall ) -> "FunctionCall" :
2515
+ response = cls .__new__ (cls )
2516
+ response ._raw_message = raw_message
2517
+ return response
2518
+
2519
+ def to_dict (self ) -> Dict [str , Any ]:
2520
+ return _proto_to_dict (self ._raw_message )
2521
+
2522
+ def __repr__ (self ) -> str :
2523
+ return self ._raw_message .__repr__ ()
2524
+
2525
+ @property
2526
+ def name (self ) -> str :
2527
+ return self ._raw_message .name
2528
+
2529
+ @property
2530
+ def args (self ) -> Dict [str , Any ]:
2531
+ # We cannot use `type(self.args).to_dict(self.args)`
2532
+ # due to: AttributeError: type object 'MapComposite' has no attribute 'to_dict'
2533
+ return self .to_dict ().get ("args" )
2534
+
2535
+
2498
2536
class SafetySetting :
2499
2537
"""Parameters for the generation."""
2500
2538
@@ -2953,10 +2991,9 @@ def respond_to_model_response(
2953
2991
)
2954
2992
2955
2993
try :
2956
- # We cannot use `function_args = type(function_call.args).to_dict(function_call.args)`
2957
- # due to: AttributeError: type object 'MapComposite' has no attribute 'to_dict'
2958
- function_args = type (function_call ).to_dict (function_call )["args" ]
2959
- function_call_result = callable_function ._function (** function_args )
2994
+ function_call_result = callable_function ._function (
2995
+ ** function_call .args
2996
+ )
2960
2997
if not isinstance (function_call_result , Mapping ):
2961
2998
# If the function returns a single value, wrap it in the
2962
2999
# format that Part.from_function_response can accept.
0 commit comments