16
16
import logging
17
17
import sys
18
18
import typing
19
+
19
20
import pydantic
20
21
import pytest
21
22
@@ -260,6 +261,31 @@ def divide_floats(a: float, b: float) -> float:
260
261
config = {'tools' : [{'code_execution' : {}}]},
261
262
),
262
263
),
264
+ pytest_helper .TestTableItem (
265
+ name = 'test_function_google_search_retrieval_with_long_lat' ,
266
+ parameters = types ._GenerateContentParameters (
267
+ model = 'gemini-1.5-flash' ,
268
+ contents = t .t_contents (None , 'what is the price of GOOG?' ),
269
+ config = types .GenerateContentConfig (
270
+ tools = [
271
+ types .Tool (
272
+ google_search_retrieval = types .GoogleSearchRetrieval (
273
+ dynamic_retrieval_config = types .DynamicRetrievalConfig (
274
+ mode = 'MODE_UNSPECIFIED'
275
+ )
276
+ )
277
+ ),
278
+ ],
279
+ tool_config = types .ToolConfig (
280
+ retrieval_config = types .RetrievalConfig (
281
+ lat_lng = types .LatLngDict (
282
+ latitude = 37.7749 , longitude = - 122.4194
283
+ )
284
+ )
285
+ ),
286
+ ),
287
+ ),
288
+ ),
263
289
pytest_helper .TestTableItem (
264
290
name = 'test_url_context' ,
265
291
parameters = types ._GenerateContentParameters (
@@ -477,7 +503,9 @@ async def test_disable_automatic_function_calling_stream_async(client):
477
503
478
504
479
505
@pytest .mark .asyncio
480
- async def test_automatic_function_calling_no_function_response_stream_async (client ):
506
+ async def test_automatic_function_calling_no_function_response_stream_async (
507
+ client ,
508
+ ):
481
509
response = await client .aio .models .generate_content_stream (
482
510
model = 'gemini-1.5-flash' ,
483
511
contents = 'what is the weather in Boston?' ,
@@ -671,7 +699,7 @@ def get_weather_pydantic_model(
671
699
contents = 'it is winter now, what is the weather in Boston?' ,
672
700
config = {
673
701
'tools' : [get_weather_pydantic_model ],
674
- 'automatic_function_calling' : {'ignore_call_history' : True }
702
+ 'automatic_function_calling' : {'ignore_call_history' : True },
675
703
},
676
704
)
677
705
@@ -702,8 +730,9 @@ def get_weather_from_list_of_cities(
702
730
response = client .models .generate_content (
703
731
model = 'gemini-1.5-flash' ,
704
732
contents = 'it is winter now, what is the weather in Boston and New York?' ,
705
- config = {'tools' : [get_weather_from_list_of_cities ],
706
- 'automatic_function_calling' : {'ignore_call_history' : True },
733
+ config = {
734
+ 'tools' : [get_weather_from_list_of_cities ],
735
+ 'automatic_function_calling' : {'ignore_call_history' : True },
707
736
},
708
737
)
709
738
@@ -749,30 +778,34 @@ def get_information(
749
778
),
750
779
config = {
751
780
'tools' : [get_information ],
752
- 'automatic_function_calling' : {'ignore_call_history' : True }
781
+ 'automatic_function_calling' : {'ignore_call_history' : True },
753
782
},
754
783
)
755
784
assert 'Sundae' in response .text
756
785
assert 'cat' in response .text
757
786
758
787
759
- def test_automatic_function_calling_with_parameterized_generic_union_type (client ):
788
+ def test_automatic_function_calling_with_parameterized_generic_union_type (
789
+ client ,
790
+ ):
760
791
def describe_cities (
761
792
country : str ,
762
793
cities : typing .Optional [list [str ]] = None ,
763
794
) -> str :
764
- " Given a country and an optional list of cities, describe the cities."
795
+ ' Given a country and an optional list of cities, describe the cities.'
765
796
if cities is None :
766
797
return 'There are no cities to describe.'
767
798
else :
768
- return f'The cities in { country } are: { ", " .join (cities )} and they are nice.'
799
+ return (
800
+ f'The cities in { country } are: { ", " .join (cities )} and they are nice.'
801
+ )
769
802
770
803
response = client .models .generate_content (
771
804
model = 'gemini-1.5-flash' ,
772
- contents = ( 'Can you describe the city of San Francisco?' ) ,
805
+ contents = 'Can you describe the city of San Francisco?' ,
773
806
config = {
774
807
'tools' : [describe_cities ],
775
- 'automatic_function_calling' : {'ignore_call_history' : True }
808
+ 'automatic_function_calling' : {'ignore_call_history' : True },
776
809
},
777
810
)
778
811
assert 'San Francisco' in response .text
@@ -807,7 +840,7 @@ def test_with_1_empty_tool(client):
807
840
contents = 'What is the price of GOOG?.' ,
808
841
config = {
809
842
'tools' : [{}, get_stock_price ],
810
- 'automatic_function_calling' : {'ignore_call_history' : True }
843
+ 'automatic_function_calling' : {'ignore_call_history' : True },
811
844
},
812
845
)
813
846
@@ -832,7 +865,9 @@ async def test_vai_search_stream_async(client):
832
865
'tools' : [{
833
866
'retrieval' : {
834
867
'vertex_ai_search' : {
835
- 'datastore' : 'projects/vertex-sdk-dev/locations/global/collections/default_collection/dataStores/yvonne_1728691676574'
868
+ 'datastore' : (
869
+ 'projects/vertex-sdk-dev/locations/global/collections/default_collection/dataStores/yvonne_1728691676574'
870
+ )
836
871
}
837
872
}
838
873
}]
@@ -848,7 +883,9 @@ async def test_vai_search_stream_async(client):
848
883
'tools' : [{
849
884
'retrieval' : {
850
885
'vertex_ai_search' : {
851
- 'datastore' : 'projects/vertex-sdk-dev/locations/global/collections/default_collection/dataStores/yvonne_1728691676574'
886
+ 'datastore' : (
887
+ 'projects/vertex-sdk-dev/locations/global/collections/default_collection/dataStores/yvonne_1728691676574'
888
+ )
852
889
}
853
890
}
854
891
}]
@@ -868,7 +905,7 @@ async def divide_integers(a: int, b: int) -> int:
868
905
contents = 'what is the result of 1000/2?' ,
869
906
config = {
870
907
'tools' : [divide_integers ],
871
- 'automatic_function_calling' : {'ignore_call_history' : True }
908
+ 'automatic_function_calling' : {'ignore_call_history' : True },
872
909
},
873
910
)
874
911
@@ -881,13 +918,13 @@ async def divide_integers(a: int, b: int) -> int:
881
918
return a // b
882
919
883
920
response = await client .aio .models .generate_content (
884
- model = 'gemini-1.5-flash' ,
885
- contents = 'what is the result of 1000/2?' ,
886
- config = {
887
- 'tools' : [divide_integers ],
888
- 'automatic_function_calling' : {'ignore_call_history' : True }
889
- },
890
- )
921
+ model = 'gemini-1.5-flash' ,
922
+ contents = 'what is the result of 1000/2?' ,
923
+ config = {
924
+ 'tools' : [divide_integers ],
925
+ 'automatic_function_calling' : {'ignore_call_history' : True },
926
+ },
927
+ )
891
928
892
929
assert '500' in response .text
893
930
@@ -902,7 +939,7 @@ def divide_integers(a: int, b: int) -> int:
902
939
contents = 'what is the result of 1000/2?' ,
903
940
config = {
904
941
'tools' : [divide_integers ],
905
- 'automatic_function_calling' : {'ignore_call_history' : True }
942
+ 'automatic_function_calling' : {'ignore_call_history' : True },
906
943
},
907
944
)
908
945
@@ -920,7 +957,12 @@ def mystery_function(a: int, b: int) -> int:
920
957
config = {'tools' : [divide_integers ]},
921
958
)
922
959
assert response .automatic_function_calling_history
923
- assert response .automatic_function_calling_history [- 1 ].parts [0 ].function_response .response ['error' ]
960
+ assert (
961
+ response .automatic_function_calling_history [- 1 ]
962
+ .parts [0 ]
963
+ .function_response .response ['error' ]
964
+ )
965
+
924
966
925
967
@pytest .mark .asyncio
926
968
async def test_automatic_function_calling_async_float_without_decimal (client ):
@@ -984,7 +1026,9 @@ async def get_current_weather_async(city: str) -> str:
984
1026
985
1027
986
1028
@pytest .mark .asyncio
987
- async def test_automatic_function_calling_async_with_async_function_stream (client ):
1029
+ async def test_automatic_function_calling_async_with_async_function_stream (
1030
+ client ,
1031
+ ):
988
1032
async def get_current_weather_async (city : str ) -> str :
989
1033
"""Returns the current weather in the city."""
990
1034
@@ -1195,8 +1239,9 @@ def test_code_execution_tool(client):
1195
1239
1196
1240
assert response .executable_code
1197
1241
assert (
1198
- 'prime' in response .code_execution_result .lower () or
1199
- '5117' in response .code_execution_result )
1242
+ 'prime' in response .code_execution_result .lower ()
1243
+ or '5117' in response .code_execution_result
1244
+ )
1200
1245
1201
1246
1202
1247
def test_afc_logs_to_logger_instance (client , caplog ):
0 commit comments