Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions google/genai/tests/types/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ def test_factory_method_from_code_execution_result_part():
assert isinstance(my_part, SubPart)


def test_generate_content_response_accepts_grounding_chunk_metadata():
response = types.GenerateContentResponse.model_validate({
'candidates': [{
'content': {'parts': [{'text': 'ok'}], 'role': 'model'},
'groundingMetadata': {
'groundingChunks': [{
'chunkMetadata': {'query': 'dummy_query'},
'web': {
'title': 'youtube.com',
'uri': (
'https://vertexaisearch.cloud.google.com/'
'grounding-api-redirect/id'
),
},
}]
},
}]
})

chunk = response.candidates[0].grounding_metadata.grounding_chunks[0]
assert chunk.chunk_metadata == {'query': 'dummy_query'}
assert chunk.web.title == 'youtube.com'


def test_factory_method_from_mcp_call_tool_function_response_on_error():
if not _is_mcp_imported:
return
Expand Down
7 changes: 7 additions & 0 deletions google/genai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7146,6 +7146,10 @@ class GroundingChunk(_common.BaseModel):
the source of the information.
"""

chunk_metadata: Optional[dict[str, Any]] = Field(
default=None,
description="""Metadata for this grounding chunk.""",
)
image: Optional[GroundingChunkImage] = Field(
default=None,
description="""A grounding chunk from an image search result. See the `Image` message for details.""",
Expand Down Expand Up @@ -7176,6 +7180,9 @@ class GroundingChunkDict(TypedDict, total=False):
the source of the information.
"""

chunk_metadata: Optional[dict[str, Any]]
"""Metadata for this grounding chunk."""

image: Optional[GroundingChunkImageDict]
"""A grounding chunk from an image search result. See the `Image` message for details."""

Expand Down
Loading