diff --git a/google/genai/_live_converters.py b/google/genai/_live_converters.py index 165ac5f98..dabdc7b63 100644 --- a/google/genai/_live_converters.py +++ b/google/genai/_live_converters.py @@ -407,6 +407,12 @@ def _GoogleMaps_to_mldev( if getv(from_object, ['enable_widget']) is not None: setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget'])) + if getv(from_object, ['grounding_types']) is not None: + raise ValueError( + 'grounding_types parameter is only supported in Gemini Enterprise Agent' + ' Platform mode, not in Gemini Developer API mode.' + ) + return to_object diff --git a/google/genai/_tokens_converters.py b/google/genai/_tokens_converters.py index acfdb0eef..8ece00fb5 100644 --- a/google/genai/_tokens_converters.py +++ b/google/genai/_tokens_converters.py @@ -248,6 +248,12 @@ def _GoogleMaps_to_mldev( if getv(from_object, ['enable_widget']) is not None: setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget'])) + if getv(from_object, ['grounding_types']) is not None: + raise ValueError( + 'grounding_types parameter is only supported in Gemini Enterprise Agent' + ' Platform mode, not in Gemini Developer API mode.' + ) + return to_object diff --git a/google/genai/batches.py b/google/genai/batches.py index 55dfd786e..a3abf1972 100644 --- a/google/genai/batches.py +++ b/google/genai/batches.py @@ -1277,6 +1277,12 @@ def _GoogleMaps_to_mldev( if getv(from_object, ['enable_widget']) is not None: setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget'])) + if getv(from_object, ['grounding_types']) is not None: + raise ValueError( + 'grounding_types parameter is only supported in Gemini Enterprise Agent' + ' Platform mode, not in Gemini Developer API mode.' + ) + return to_object diff --git a/google/genai/caches.py b/google/genai/caches.py index d10fc2e27..90c77e897 100644 --- a/google/genai/caches.py +++ b/google/genai/caches.py @@ -553,6 +553,12 @@ def _GoogleMaps_to_mldev( if getv(from_object, ['enable_widget']) is not None: setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget'])) + if getv(from_object, ['grounding_types']) is not None: + raise ValueError( + 'grounding_types parameter is only supported in Gemini Enterprise Agent' + ' Platform mode, not in Gemini Developer API mode.' + ) + return to_object diff --git a/google/genai/models.py b/google/genai/models.py index 861b030d0..7c4242279 100644 --- a/google/genai/models.py +++ b/google/genai/models.py @@ -3076,6 +3076,12 @@ def _GoogleMaps_to_mldev( if getv(from_object, ['enable_widget']) is not None: setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget'])) + if getv(from_object, ['grounding_types']) is not None: + raise ValueError( + 'grounding_types parameter is only supported in Gemini Enterprise Agent' + ' Platform mode, not in Gemini Developer API mode.' + ) + return to_object diff --git a/google/genai/tests/models/test_generate_content_tools.py b/google/genai/tests/models/test_generate_content_tools.py index e2615c4cc..40721bbbf 100644 --- a/google/genai/tests/models/test_generate_content_tools.py +++ b/google/genai/tests/models/test_generate_content_tools.py @@ -637,6 +637,32 @@ def divide_floats(a: float, b: float) -> float: config={'tools': [{'google_maps': {'enable_widget': True}}]}, ), ), + pytest_helper.TestTableItem( + name='test_google_maps_places_routing', + parameters=types._GenerateContentParameters( + model='gemini-3.5-flash', + contents=t.t_contents( + 'How long does it take to drive from SFO to LAX?' + ), + config={ + 'tools': [{'google_maps': {'grounding_types': {'places': {}}}}] + }, + ), + exception_if_mldev='only supported in', + ), + pytest_helper.TestTableItem( + name='test_google_maps_routing', + parameters=types._GenerateContentParameters( + model='gemini-3.5-flash', + contents=t.t_contents( + 'Give me directions from SFO to LAX.' + ), + config={ + 'tools': [{'google_maps': {'grounding_types': {'routing': {}}}}] + }, + ), + exception_if_mldev='only supported in', + ), pytest_helper.TestTableItem( name='test_include_server_side_tool_invocations', parameters=types._GenerateContentParameters( diff --git a/google/genai/types.py b/google/genai/types.py index f1831d51c..359c00d45 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -3753,6 +3753,84 @@ class AuthConfigDict(TypedDict, total=False): AuthConfigOrDict = Union[AuthConfig, AuthConfigDict] +class GoogleMapsPlaces(_common.BaseModel): + """Grounding with Google Maps Places data (e.g. + + QueryPlaces). This is the default Google Maps grounding type when no other + type is specified. This data type is not supported in Gemini API. + """ + + pass + + +class GoogleMapsPlacesDict(TypedDict, total=False): + """Grounding with Google Maps Places data (e.g. + + QueryPlaces). This is the default Google Maps grounding type when no other + type is specified. This data type is not supported in Gemini API. + """ + + pass + + +GoogleMapsPlacesOrDict = Union[GoogleMapsPlaces, GoogleMapsPlacesDict] + + +class GoogleMapsRouting(_common.BaseModel): + """Grounding with Google Maps Routing APIs (ComputeRoutes and SearchAlongRoute). + + This data type is not supported in Gemini API. + """ + + pass + + +class GoogleMapsRoutingDict(TypedDict, total=False): + """Grounding with Google Maps Routing APIs (ComputeRoutes and SearchAlongRoute). + + This data type is not supported in Gemini API. + """ + + pass + + +GoogleMapsRoutingOrDict = Union[GoogleMapsRouting, GoogleMapsRoutingDict] + + +class GoogleMapsGroundingTypes(_common.BaseModel): + """Defines the types of Google Maps grounding that can be enabled and their configurations. + + This data type is not supported in Gemini API. + """ + + places: Optional[GoogleMapsPlaces] = Field( + default=None, + description="""Optional. Enables grounding with Google Maps Places. This is the default grounding type when no `GroundingTypes` are specified.""", + ) + routing: Optional[GoogleMapsRouting] = Field( + default=None, + description="""Optional. Enables grounding with Google Maps Routing APIs (ComputeRoutes and SearchAlongRoute).""", + ) + + +class GoogleMapsGroundingTypesDict(TypedDict, total=False): + """Defines the types of Google Maps grounding that can be enabled and their configurations. + + This data type is not supported in Gemini API. + """ + + places: Optional[GoogleMapsPlacesDict] + """Optional. Enables grounding with Google Maps Places. This is the default grounding type when no `GroundingTypes` are specified.""" + + routing: Optional[GoogleMapsRoutingDict] + """Optional. Enables grounding with Google Maps Routing APIs (ComputeRoutes and SearchAlongRoute).""" + + +GoogleMapsGroundingTypesOrDict = Union[ + GoogleMapsGroundingTypes, GoogleMapsGroundingTypesDict +] + + class GoogleMaps(_common.BaseModel): """Tool to retrieve knowledge from Google Maps.""" @@ -3764,6 +3842,10 @@ class GoogleMaps(_common.BaseModel): default=None, 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.""", ) + grounding_types: Optional[GoogleMapsGroundingTypes] = Field( + default=None, + description="""Optional. Specifies the types of Google Maps grounding to enable. This field is not supported in Gemini API.""", + ) class GoogleMapsDict(TypedDict, total=False): @@ -3775,6 +3857,9 @@ class GoogleMapsDict(TypedDict, total=False): enable_widget: Optional[bool] """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.""" + grounding_types: Optional[GoogleMapsGroundingTypesDict] + """Optional. Specifies the types of Google Maps grounding to enable. This field is not supported in Gemini API.""" + GoogleMapsOrDict = Union[GoogleMaps, GoogleMapsDict]