Skip to content

Commit 1737f72

Browse files
jaycee-licopybara-github
authored andcommitted
feat: Support enableWidget feature in GoogleMaps
PiperOrigin-RevId: 817775114
1 parent dc77a1d commit 1737f72

File tree

7 files changed

+90
-0
lines changed

7 files changed

+90
-0
lines changed

google/genai/_live_converters.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ def _GoogleMaps_to_mldev(
237237
if getv(from_object, ['auth_config']) is not None:
238238
raise ValueError('auth_config parameter is not supported in Gemini API.')
239239

240+
if getv(from_object, ['enable_widget']) is not None:
241+
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
242+
240243
return to_object
241244

242245

google/genai/_tokens_converters.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ def _GoogleMaps_to_mldev(
156156
if getv(from_object, ['auth_config']) is not None:
157157
raise ValueError('auth_config parameter is not supported in Gemini API.')
158158

159+
if getv(from_object, ['enable_widget']) is not None:
160+
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
161+
159162
return to_object
160163

161164

google/genai/batches.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,9 @@ def _GoogleMaps_to_mldev(
10241024
if getv(from_object, ['auth_config']) is not None:
10251025
raise ValueError('auth_config parameter is not supported in Gemini API.')
10261026

1027+
if getv(from_object, ['enable_widget']) is not None:
1028+
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
1029+
10271030
return to_object
10281031

10291032

google/genai/caches.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ def _GoogleMaps_to_mldev(
370370
if getv(from_object, ['auth_config']) is not None:
371371
raise ValueError('auth_config parameter is not supported in Gemini API.')
372372

373+
if getv(from_object, ['enable_widget']) is not None:
374+
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
375+
373376
return to_object
374377

375378

google/genai/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,9 @@ def _GoogleMaps_to_mldev(
24412441
if getv(from_object, ['auth_config']) is not None:
24422442
raise ValueError('auth_config parameter is not supported in Gemini API.')
24432443

2444+
if getv(from_object, ['enable_widget']) is not None:
2445+
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
2446+
24442447
return to_object
24452448

24462449

google/genai/tests/models/test_generate_content_tools.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,20 @@ def divide_floats(a: float, b: float) -> float:
511511
},
512512
),
513513
),
514+
pytest_helper.TestTableItem(
515+
name='test_google_maps_with_enable_widget',
516+
parameters=types._GenerateContentParameters(
517+
model='gemini-2.5-flash',
518+
contents=t.t_contents('What is the nearest airport to Seattle?'),
519+
config={
520+
'tools': [
521+
{'google_maps': {'enable_widget': True}}
522+
]
523+
},
524+
),
525+
# TODO(b/450916996): Remove this once the feature is launched in Gemini.
526+
exception_if_mldev='400',
527+
),
514528
]
515529

516530

google/genai/types.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,10 @@ class GoogleMaps(_common.BaseModel):
28232823
default=None,
28242824
description="""Optional. Auth config for the Google Maps tool.""",
28252825
)
2826+
enable_widget: Optional[bool] = Field(
2827+
default=None,
2828+
description="""Optional. If true, include the widget context token in the response.""",
2829+
)
28262830

28272831

28282832
class GoogleMapsDict(TypedDict, total=False):
@@ -2831,6 +2835,9 @@ class GoogleMapsDict(TypedDict, total=False):
28312835
auth_config: Optional[AuthConfigDict]
28322836
"""Optional. Auth config for the Google Maps tool."""
28332837

2838+
enable_widget: Optional[bool]
2839+
"""Optional. If true, include the widget context token in the response."""
2840+
28342841

28352842
GoogleMapsOrDict = Union[GoogleMaps, GoogleMapsDict]
28362843

@@ -4850,6 +4857,12 @@ class GroundingChunkMapsPlaceAnswerSourcesReviewSnippet(_common.BaseModel):
48504857
default=None,
48514858
description="""A reference representing this place review which may be used to look up this place review again.""",
48524859
)
4860+
review_id: Optional[str] = Field(
4861+
default=None, description="""Id of the review referencing the place."""
4862+
)
4863+
title: Optional[str] = Field(
4864+
default=None, description="""Title of the review."""
4865+
)
48534866

48544867

48554868
class GroundingChunkMapsPlaceAnswerSourcesReviewSnippetDict(
@@ -4874,6 +4887,12 @@ class GroundingChunkMapsPlaceAnswerSourcesReviewSnippetDict(
48744887
review: Optional[str]
48754888
"""A reference representing this place review which may be used to look up this place review again."""
48764889

4890+
review_id: Optional[str]
4891+
"""Id of the review referencing the place."""
4892+
4893+
title: Optional[str]
4894+
"""Title of the review."""
4895+
48774896

48784897
GroundingChunkMapsPlaceAnswerSourcesReviewSnippetOrDict = Union[
48794898
GroundingChunkMapsPlaceAnswerSourcesReviewSnippet,
@@ -5234,6 +5253,39 @@ class SearchEntryPointDict(TypedDict, total=False):
52345253
SearchEntryPointOrDict = Union[SearchEntryPoint, SearchEntryPointDict]
52355254

52365255

5256+
class GroundingMetadataSourceFlaggingUri(_common.BaseModel):
5257+
"""Source content flagging uri for a place or review.
5258+
5259+
This is currently populated only for Google Maps grounding.
5260+
"""
5261+
5262+
flag_content_uri: Optional[str] = Field(
5263+
default=None,
5264+
description="""A link where users can flag a problem with the source (place or review).""",
5265+
)
5266+
source_id: Optional[str] = Field(
5267+
default=None, description="""Id of the place or review."""
5268+
)
5269+
5270+
5271+
class GroundingMetadataSourceFlaggingUriDict(TypedDict, total=False):
5272+
"""Source content flagging uri for a place or review.
5273+
5274+
This is currently populated only for Google Maps grounding.
5275+
"""
5276+
5277+
flag_content_uri: Optional[str]
5278+
"""A link where users can flag a problem with the source (place or review)."""
5279+
5280+
source_id: Optional[str]
5281+
"""Id of the place or review."""
5282+
5283+
5284+
GroundingMetadataSourceFlaggingUriOrDict = Union[
5285+
GroundingMetadataSourceFlaggingUri, GroundingMetadataSourceFlaggingUriDict
5286+
]
5287+
5288+
52375289
class GroundingMetadata(_common.BaseModel):
52385290
"""Metadata returned to client when grounding is enabled."""
52395291

@@ -5259,6 +5311,12 @@ class GroundingMetadata(_common.BaseModel):
52595311
default=None,
52605312
description="""Optional. Google search entry for the following-up web searches.""",
52615313
)
5314+
source_flagging_uris: Optional[list[GroundingMetadataSourceFlaggingUri]] = (
5315+
Field(
5316+
default=None,
5317+
description="""Optional. Output only. List of source flagging uris. This is currently populated only for Google Maps grounding.""",
5318+
)
5319+
)
52625320
web_search_queries: Optional[list[str]] = Field(
52635321
default=None,
52645322
description="""Optional. Web search queries for the following-up web search.""",
@@ -5286,6 +5344,9 @@ class GroundingMetadataDict(TypedDict, total=False):
52865344
search_entry_point: Optional[SearchEntryPointDict]
52875345
"""Optional. Google search entry for the following-up web searches."""
52885346

5347+
source_flagging_uris: Optional[list[GroundingMetadataSourceFlaggingUriDict]]
5348+
"""Optional. Output only. List of source flagging uris. This is currently populated only for Google Maps grounding."""
5349+
52895350
web_search_queries: Optional[list[str]]
52905351
"""Optional. Web search queries for the following-up web search."""
52915352

0 commit comments

Comments
 (0)