Add groundingMetadata to Gemini Multimodal Live Service #1932
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request introduces support for grounding metadata from the Google Gemini Multimodal Live API, enabling client applications (e.g., iOS apps) to 8000 display Google Search grounding links and related information.
Changes Implemented:
Extended Event Models (
src/pipecat/services/gemini_multimodal_live/events.py
):SearchEntryPoint
WebSource
GroundingChunk
GroundingSegment
GroundingSupport
GroundingMetadata
ServerContent
to include an optionalgroundingMetadata
field.Enhanced Gemini Service Logic (
src/pipecat/services/gemini_multimodal_live/gemini.py
):_search_result_buffer
and_accumulated_grounding_metadata
to track relevant data across streamed events._handle_evt_grounding_metadata
to specifically processserverContent
messages that only containgroundingMetadata
._handle_evt_model_turn
,_handle_evt_output_transcription
,_handle_evt_turn_complete
) to capture and storegroundingMetadata
if present._process_grounding_metadata()
:events.GroundingMetadata
into Pipecat's standardLLMSearchResponseFrame
(frompipecat.services.google.frames
).search_result
(accumulated text),origins
(includingsite_uri
with Vertex AI Search redirect links andsite_title
), andrendered_content
(HTML for search suggestions).LLMSearchResponseFrame
is then pushed down the pipeline.Logging Refinements:
gemini.py
andevents.py
to be more PR-friendly. Please delete logging if excessive and not inline with best practices for the main repo on Pipecat.How to Test:
examples/foundational/26g-gemini-multimodal-live-grounding.py
example.google_search
as a tool and a system instruction that encourages its use (e.g., asking for current events).LLMSearchResponseFrame
being emitted.frame.search_result
(the LLM's textual answer)frame.rendered_content
(HTML for search suggestions/chips)frame.origins
(list of sources, each withsite_title
,site_uri
, andresults
snippets)Key Files Changed:
src/pipecat/services/gemini_multimodal_live/gemini.py
src/pipecat/services/gemini_multimodal_live/events.py
Added Foundational Example 26g for testing:
examples/foundational/26g-gemini-multimodal-live-groundingMetadata.py
Let me know if you'd like any part of this adjusted!