From 4951c97eabd3289fbc5d6df61c25f0ce2cefae31 Mon Sep 17 00:00:00 2001 From: Pete Date: Thu, 3 Jul 2025 17:49:27 -0400 Subject: [PATCH] Clean up verbose logging in grounding metadata implementation - Remove debug logging from grounding metadata event handlers - Simplify logging in _process_grounding_metadata method - Clean up example file logging for better readability - Remove verbose event parsing comments Based on suggestions from draft PR #2121 --- ...emini-multimodal-live-groundingMetadata.py | 23 ++++++------------- .../services/gemini_multimodal_live/events.py | 9 -------- .../services/gemini_multimodal_live/gemini.py | 13 ----------- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/examples/foundational/26g-gemini-multimodal-live-groundingMetadata.py b/examples/foundational/26g-gemini-multimodal-live-groundingMetadata.py index 0c6d35ff0..b5b2a18f6 100644 --- a/examples/foundational/26g-gemini-multimodal-live-groundingMetadata.py +++ b/examples/foundational/26g-gemini-multimodal-live-groundingMetadata.py @@ -53,33 +53,24 @@ class GroundingMetadataProcessor(FrameProcessor): # Always call super().process_frame first await super().process_frame(frame, direction) - # Only log important frame types, not every audio frame - if hasattr(frame, '__class__'): - frame_type = frame.__class__.__name__ - if frame_type in ['LLMTextFrame', 'TTSTextFrame', 'LLMFullResponseStartFrame', 'LLMFullResponseEndFrame']: - logger.debug(f"GroundingProcessor received: {frame_type}") - if isinstance(frame, LLMSearchResponseFrame): self._grounding_count += 1 - logger.info(f"\nšŸ” GROUNDING METADATA RECEIVED #{self._grounding_count}") - logger.info(f"šŸ“ Search Result Text: {frame.search_result[:200]}...") - - if frame.rendered_content: - logger.info(f"šŸ”— Rendered Content: {frame.rendered_content}") + logger.info(f"šŸ” GROUNDING METADATA RECEIVED #{self._grounding_count}") + logger.info(f"šŸ“ Search Result: {frame.search_result[:200]}...") if frame.origins: - logger.info(f"šŸ“ Number of Origins: {len(frame.origins)}") + logger.info(f"šŸ“ Origins: {len(frame.origins)} sources") for i, origin in enumerate(frame.origins): - logger.info(f" Origin {i+1}: {origin.site_title} - {origin.site_uri}") - if origin.results: - logger.info(f" Results: {len(origin.results)} items") + logger.info(f" {i+1}. {origin.site_title} - {origin.site_uri}") + + if frame.rendered_content: + logger.info(f"šŸ”— Rendered Content Available: {len(frame.rendered_content)} chars") # Always push the frame downstream await self.push_frame(frame, direction) async def run_bot(webrtc_connection: SmallWebRTCConnection, _: argparse.Namespace): - logger.info(f"Starting Gemini Live Grounding Test Bot") # Initialize the SmallWebRTCTransport with the connection transport = SmallWebRTCTransport( diff --git a/src/pipecat/services/gemini_multimodal_live/events.py b/src/pipecat/services/gemini_multimodal_live/events.py index dced95d6c..c8530b7ee 100644 --- a/src/pipecat/services/gemini_multimodal_live/events.py +++ b/src/pipecat/services/gemini_multimodal_live/events.py @@ -488,15 +488,6 @@ def parse_server_event(str): """ try: evt_dict = json.loads(message_str) - - # Only log grounding metadata detection if truly needed for debugging - # In production, this could be removed entirely or moved to TRACE level - if 'serverContent' in evt_dict: - server_content = evt_dict['serverContent'] - if 'groundingMetadata' in server_content: - # Consider removing this log entirely for production - pass - evt = ServerEvent.model_validate(evt_dict) return evt except Exception as e: diff --git a/src/pipecat/services/gemini_multimodal_live/gemini.py b/src/pipecat/services/gemini_multimodal_live/gemini.py index 5303a3c6f..633bf6de2 100644 --- a/src/pipecat/services/gemini_multimodal_live/gemini.py +++ b/src/pipecat/services/gemini_multimodal_live/gemini.py @@ -1096,7 +1096,6 @@ class GeminiMultimodalLiveLLMService(LLMService): # Check for grounding metadata in server content if evt.serverContent and evt.serverContent.groundingMetadata: self._accumulated_grounding_metadata = evt.serverContent.groundingMetadata - logger.debug("Grounding metadata detected in model turn.") inline_data = part.inlineData if not inline_data: @@ -1166,10 +1165,7 @@ class GeminiMultimodalLiveLLMService(LLMService): # Process grounding metadata if we have accumulated any if self._accumulated_grounding_metadata: - logger.debug("Processing grounding metadata...") await self._process_grounding_metadata(self._accumulated_grounding_metadata, self._search_result_buffer) - else: - logger.debug("No grounding metadata to process") # Reset grounding tracking for next response self._search_result_buffer = "" @@ -1262,24 +1258,16 @@ class GeminiMultimodalLiveLLMService(LLMService): async def _handle_evt_grounding_metadata(self, evt): """Handle dedicated grounding metadata events.""" - logger.debug("Received dedicated grounding metadata event.") - if evt.serverContent and evt.serverContent.groundingMetadata: grounding_metadata = evt.serverContent.groundingMetadata - logger.debug(f"Grounding data: {len(grounding_metadata.groundingChunks or [])} chunks, {len(grounding_metadata.groundingSupports or [])} supports") - # Process the grounding metadata immediately await self._process_grounding_metadata(grounding_metadata, self._search_result_buffer) async def _process_grounding_metadata(self, grounding_metadata: events.GroundingMetadata, search_result: str = ""): """Process grounding metadata and emit LLMSearchResponseFrame.""" - logger.debug(f"Processing grounding metadata. Search result text length: {len(search_result)}") if not grounding_metadata: - logger.warning("No grounding metadata provided to _process_grounding_metadata") return - # logger.debug(f"Processing grounding metadata: {grounding_metadata}") # Too verbose for PR - # Extract rendered content for search suggestions rendered_content = None if grounding_metadata.searchEntryPoint and grounding_metadata.searchEntryPoint.renderedContent: @@ -1324,7 +1312,6 @@ class GeminiMultimodalLiveLLMService(LLMService): rendered_content=rendered_content ) - logger.debug(f"Emitting LLMSearchResponseFrame with {len(origins)} origins, rendered_content available: {rendered_content is not None}") await self.push_frame(search_frame) async def _handle_evt_usage_metadata(self, evt): if not evt.usageMetadata: