@@ -677,39 +677,22 @@ def _encode_fd(fd: FunctionDeclaration | protos.FunctionDeclaration) -> protos.F
677
677
def _make_google_search_retrieval (gsr : GoogleSearchRetrievalType ):
678
678
if isinstance (gsr , protos .GoogleSearchRetrieval ):
679
679
return gsr
680
- elif isinstance (gsr , Iterable ) and not isinstance (gsr , Mapping ):
681
- # Handle list of protos.Tool(...) and list of protos.GoogleSearchRetrieval
682
- return gsr
683
680
elif isinstance (gsr , Mapping ):
684
- if "mode" in gsr ["dynamic_retrieval_config" ]:
685
- print (to_mode (gsr ["dynamic_retrieval_config" ]["mode" ]))
686
- # Create proto object from dictionary
687
- gsr = {
688
- "google_search_retrieval" : {
689
- "dynamic_retrieval_config" : {
690
- "mode" : to_mode (gsr ["dynamic_retrieval_config" ]["mode" ]),
691
- "dynamic_threshold" : gsr ["dynamic_retrieval_config" ]["dynamic_threshold" ],
692
- }
693
- }
694
- }
695
- print (gsr )
696
- elif "mode" in gsr .keys ():
697
- # Create proto object from dictionary
698
- gsr = {
699
- "google_search_retrieval" : {
700
- "dynamic_retrieval_config" : {
701
- "mode" : to_mode (gsr ["mode" ]),
702
- "dynamic_threshold" : gsr ["dynamic_threshold" ],
703
- }
704
- }
705
- }
706
- return gsr
681
+ drc = gsr .get ("dynamic_retrieval_config" , None )
682
+ if drc is not None :
683
+ mode = drc .get ("mode" , None )
684
+ if mode is not None :
685
+ mode = to_mode (mode )
686
+ gsr = gsr .copy ()
687
+ gsr ["dynamic_retrieval_config" ]["mode" ] = mode
688
+ return protos .GoogleSearchRetrieval (gsr )
707
689
else :
708
690
raise TypeError (
709
691
"Invalid input type. Expected an instance of `genai.GoogleSearchRetrieval`.\n "
710
692
f"However, received an object of type: { type (gsr )} .\n "
711
693
f"Object Value: { gsr } "
712
694
)
695
+
713
696
714
697
715
698
class Tool :
@@ -741,13 +724,13 @@ def __init__(
741
724
742
725
if google_search_retrieval :
743
726
if isinstance (google_search_retrieval , str ):
744
- google_search_retrieval = {
727
+ self . _google_search_retrieval = {
745
728
"google_search_retrieval" : {
746
729
"dynamic_retrieval_config" : {"mode" : to_mode (google_search_retrieval )}
747
730
}
748
731
}
749
732
else :
750
- _make_google_search_retrieval (google_search_retrieval )
733
+ self . _google_search_retrieval = _make_google_search_retrieval (google_search_retrieval )
751
734
752
735
self ._proto = protos .Tool (
753
736
function_declarations = [_encode_fd (fd ) for fd in self ._function_declarations ],
@@ -763,7 +746,7 @@ def function_declarations(self) -> list[FunctionDeclaration | protos.FunctionDec
763
746
764
747
@property
765
748
def google_search_retrieval (self ) -> protos .GoogleSearchRetrieval :
766
- return self ._proto . google_search_retrieval
749
+ return self ._google_search_retrieval
767
750
768
751
@property
769
752
def code_execution (self ) -> protos .CodeExecution :
0 commit comments