Skip to content

Commit 95a335d

Browse files
yinghsienwucopybara-github
authored andcommitted
feat: Support GoogleMaps Tool grounding_types places and routing
PiperOrigin-RevId: 956140187
1 parent 3b321ac commit 95a335d

7 files changed

Lines changed: 141 additions & 0 deletions

File tree

google/genai/_live_converters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ def _GoogleMaps_to_mldev(
407407
if getv(from_object, ['enable_widget']) is not None:
408408
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
409409

410+
if getv(from_object, ['grounding_types']) is not None:
411+
raise ValueError(
412+
'grounding_types parameter is only supported in Gemini Enterprise Agent'
413+
' Platform mode, not in Gemini Developer API mode.'
414+
)
415+
410416
return to_object
411417

412418

google/genai/_tokens_converters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ def _GoogleMaps_to_mldev(
248248
if getv(from_object, ['enable_widget']) is not None:
249249
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
250250

251+
if getv(from_object, ['grounding_types']) is not None:
252+
raise ValueError(
253+
'grounding_types parameter is only supported in Gemini Enterprise Agent'
254+
' Platform mode, not in Gemini Developer API mode.'
255+
)
256+
251257
return to_object
252258

253259

google/genai/batches.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,12 @@ def _GoogleMaps_to_mldev(
12771277
if getv(from_object, ['enable_widget']) is not None:
12781278
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
12791279

1280+
if getv(from_object, ['grounding_types']) is not None:
1281+
raise ValueError(
1282+
'grounding_types parameter is only supported in Gemini Enterprise Agent'
1283+
' Platform mode, not in Gemini Developer API mode.'
1284+
)
1285+
12801286
return to_object
12811287

12821288

google/genai/caches.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,12 @@ def _GoogleMaps_to_mldev(
553553
if getv(from_object, ['enable_widget']) is not None:
554554
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
555555

556+
if getv(from_object, ['grounding_types']) is not None:
557+
raise ValueError(
558+
'grounding_types parameter is only supported in Gemini Enterprise Agent'
559+
' Platform mode, not in Gemini Developer API mode.'
560+
)
561+
556562
return to_object
557563

558564

google/genai/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,12 @@ def _GoogleMaps_to_mldev(
30763076
if getv(from_object, ['enable_widget']) is not None:
30773077
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
30783078

3079+
if getv(from_object, ['grounding_types']) is not None:
3080+
raise ValueError(
3081+
'grounding_types parameter is only supported in Gemini Enterprise Agent'
3082+
' Platform mode, not in Gemini Developer API mode.'
3083+
)
3084+
30793085
return to_object
30803086

30813087

google/genai/tests/models/test_generate_content_tools.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,32 @@ def divide_floats(a: float, b: float) -> float:
637637
config={'tools': [{'google_maps': {'enable_widget': True}}]},
638638
),
639639
),
640+
pytest_helper.TestTableItem(
641+
name='test_google_maps_places_routing',
642+
parameters=types._GenerateContentParameters(
643+
model='gemini-3.5-flash',
644+
contents=t.t_contents(
645+
'How long does it take to drive from SFO to LAX?'
646+
),
647+
config={
648+
'tools': [{'google_maps': {'grounding_types': {'places': {}}}}]
649+
},
650+
),
651+
exception_if_mldev='only supported in',
652+
),
653+
pytest_helper.TestTableItem(
654+
name='test_google_maps_routing',
655+
parameters=types._GenerateContentParameters(
656+
model='gemini-3.5-flash',
657+
contents=t.t_contents(
658+
'Give me directions from SFO to LAX.'
659+
),
660+
config={
661+
'tools': [{'google_maps': {'grounding_types': {'routing': {}}}}]
662+
},
663+
),
664+
exception_if_mldev='only supported in',
665+
),
640666
pytest_helper.TestTableItem(
641667
name='test_include_server_side_tool_invocations',
642668
parameters=types._GenerateContentParameters(

google/genai/types.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,6 +3753,84 @@ class AuthConfigDict(TypedDict, total=False):
37533753
AuthConfigOrDict = Union[AuthConfig, AuthConfigDict]
37543754

37553755

3756+
class GoogleMapsPlaces(_common.BaseModel):
3757+
"""Grounding with Google Maps Places data (e.g.
3758+
3759+
QueryPlaces). This is the default Google Maps grounding type when no other
3760+
type is specified. This data type is not supported in Gemini API.
3761+
"""
3762+
3763+
pass
3764+
3765+
3766+
class GoogleMapsPlacesDict(TypedDict, total=False):
3767+
"""Grounding with Google Maps Places data (e.g.
3768+
3769+
QueryPlaces). This is the default Google Maps grounding type when no other
3770+
type is specified. This data type is not supported in Gemini API.
3771+
"""
3772+
3773+
pass
3774+
3775+
3776+
GoogleMapsPlacesOrDict = Union[GoogleMapsPlaces, GoogleMapsPlacesDict]
3777+
3778+
3779+
class GoogleMapsRouting(_common.BaseModel):
3780+
"""Grounding with Google Maps Routing APIs (ComputeRoutes and SearchAlongRoute).
3781+
3782+
This data type is not supported in Gemini API.
3783+
"""
3784+
3785+
pass
3786+
3787+
3788+
class GoogleMapsRoutingDict(TypedDict, total=False):
3789+
"""Grounding with Google Maps Routing APIs (ComputeRoutes and SearchAlongRoute).
3790+
3791+
This data type is not supported in Gemini API.
3792+
"""
3793+
3794+
pass
3795+
3796+
3797+
GoogleMapsRoutingOrDict = Union[GoogleMapsRouting, GoogleMapsRoutingDict]
3798+
3799+
3800+
class GoogleMapsGroundingTypes(_common.BaseModel):
3801+
"""Defines the types of Google Maps grounding that can be enabled and their configurations.
3802+
3803+
This data type is not supported in Gemini API.
3804+
"""
3805+
3806+
places: Optional[GoogleMapsPlaces] = Field(
3807+
default=None,
3808+
description="""Optional. Enables grounding with Google Maps Places. This is the default grounding type when no `GroundingTypes` are specified.""",
3809+
)
3810+
routing: Optional[GoogleMapsRouting] = Field(
3811+
default=None,
3812+
description="""Optional. Enables grounding with Google Maps Routing APIs (ComputeRoutes and SearchAlongRoute).""",
3813+
)
3814+
3815+
3816+
class GoogleMapsGroundingTypesDict(TypedDict, total=False):
3817+
"""Defines the types of Google Maps grounding that can be enabled and their configurations.
3818+
3819+
This data type is not supported in Gemini API.
3820+
"""
3821+
3822+
places: Optional[GoogleMapsPlacesDict]
3823+
"""Optional. Enables grounding with Google Maps Places. This is the default grounding type when no `GroundingTypes` are specified."""
3824+
3825+
routing: Optional[GoogleMapsRoutingDict]
3826+
"""Optional. Enables grounding with Google Maps Routing APIs (ComputeRoutes and SearchAlongRoute)."""
3827+
3828+
3829+
GoogleMapsGroundingTypesOrDict = Union[
3830+
GoogleMapsGroundingTypes, GoogleMapsGroundingTypesDict
3831+
]
3832+
3833+
37563834
class GoogleMaps(_common.BaseModel):
37573835
"""Tool to retrieve knowledge from Google Maps."""
37583836

@@ -3764,6 +3842,10 @@ class GoogleMaps(_common.BaseModel):
37643842
default=None,
37653843
description="""Deprecated. The Google Maps contextual widget behavior in Grounding with Google Maps is being deprecated; this field is planned for removal and no longer has any effect once removed. Optional. Whether to return a widget context token in the GroundingMetadata of the response.""",
37663844
)
3845+
grounding_types: Optional[GoogleMapsGroundingTypes] = Field(
3846+
default=None,
3847+
description="""Optional. Specifies the types of Google Maps grounding to enable. This field is not supported in Gemini API.""",
3848+
)
37673849

37683850

37693851
class GoogleMapsDict(TypedDict, total=False):
@@ -3775,6 +3857,9 @@ class GoogleMapsDict(TypedDict, total=False):
37753857
enable_widget: Optional[bool]
37763858
"""Deprecated. The Google Maps contextual widget behavior in Grounding with Google Maps is being deprecated; this field is planned for removal and no longer has any effect once removed. Optional. Whether to return a widget context token in the GroundingMetadata of the response."""
37773859

3860+
grounding_types: Optional[GoogleMapsGroundingTypesDict]
3861+
"""Optional. Specifies the types of Google Maps grounding to enable. This field is not supported in Gemini API."""
3862+
37783863

37793864
GoogleMapsOrDict = Union[GoogleMaps, GoogleMapsDict]
37803865

0 commit comments

Comments
 (0)