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
This commit is contained in:
@@ -53,33 +53,24 @@ class GroundingMetadataProcessor(FrameProcessor):
|
|||||||
# Always call super().process_frame first
|
# Always call super().process_frame first
|
||||||
await super().process_frame(frame, direction)
|
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):
|
if isinstance(frame, LLMSearchResponseFrame):
|
||||||
self._grounding_count += 1
|
self._grounding_count += 1
|
||||||
logger.info(f"\n🔍 GROUNDING METADATA RECEIVED #{self._grounding_count}")
|
logger.info(f"🔍 GROUNDING METADATA RECEIVED #{self._grounding_count}")
|
||||||
logger.info(f"📝 Search Result Text: {frame.search_result[:200]}...")
|
logger.info(f"📝 Search Result: {frame.search_result[:200]}...")
|
||||||
|
|
||||||
if frame.rendered_content:
|
|
||||||
logger.info(f"🔗 Rendered Content: {frame.rendered_content}")
|
|
||||||
|
|
||||||
if frame.origins:
|
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):
|
for i, origin in enumerate(frame.origins):
|
||||||
logger.info(f" Origin {i+1}: {origin.site_title} - {origin.site_uri}")
|
logger.info(f" {i+1}. {origin.site_title} - {origin.site_uri}")
|
||||||
if origin.results:
|
|
||||||
logger.info(f" Results: {len(origin.results)} items")
|
if frame.rendered_content:
|
||||||
|
logger.info(f"🔗 Rendered Content Available: {len(frame.rendered_content)} chars")
|
||||||
|
|
||||||
# Always push the frame downstream
|
# Always push the frame downstream
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
|
|
||||||
async def run_bot(webrtc_connection: SmallWebRTCConnection, _: argparse.Namespace):
|
async def run_bot(webrtc_connection: SmallWebRTCConnection, _: argparse.Namespace):
|
||||||
logger.info(f"Starting Gemini Live Grounding Test Bot")
|
|
||||||
|
|
||||||
# Initialize the SmallWebRTCTransport with the connection
|
# Initialize the SmallWebRTCTransport with the connection
|
||||||
transport = SmallWebRTCTransport(
|
transport = SmallWebRTCTransport(
|
||||||
|
|||||||
@@ -488,15 +488,6 @@ def parse_server_event(str):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
evt_dict = json.loads(message_str)
|
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)
|
evt = ServerEvent.model_validate(evt_dict)
|
||||||
return evt
|
return evt
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -1096,7 +1096,6 @@ class GeminiMultimodalLiveLLMService(LLMService):
|
|||||||
# Check for grounding metadata in server content
|
# Check for grounding metadata in server content
|
||||||
if evt.serverContent and evt.serverContent.groundingMetadata:
|
if evt.serverContent and evt.serverContent.groundingMetadata:
|
||||||
self._accumulated_grounding_metadata = evt.serverContent.groundingMetadata
|
self._accumulated_grounding_metadata = evt.serverContent.groundingMetadata
|
||||||
logger.debug("Grounding metadata detected in model turn.")
|
|
||||||
|
|
||||||
inline_data = part.inlineData
|
inline_data = part.inlineData
|
||||||
if not inline_data:
|
if not inline_data:
|
||||||
@@ -1166,10 +1165,7 @@ class GeminiMultimodalLiveLLMService(LLMService):
|
|||||||
|
|
||||||
# Process grounding metadata if we have accumulated any
|
# Process grounding metadata if we have accumulated any
|
||||||
if self._accumulated_grounding_metadata:
|
if self._accumulated_grounding_metadata:
|
||||||
logger.debug("Processing grounding metadata...")
|
|
||||||
await self._process_grounding_metadata(self._accumulated_grounding_metadata, self._search_result_buffer)
|
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
|
# Reset grounding tracking for next response
|
||||||
self._search_result_buffer = ""
|
self._search_result_buffer = ""
|
||||||
@@ -1262,24 +1258,16 @@ class GeminiMultimodalLiveLLMService(LLMService):
|
|||||||
|
|
||||||
async def _handle_evt_grounding_metadata(self, evt):
|
async def _handle_evt_grounding_metadata(self, evt):
|
||||||
"""Handle dedicated grounding metadata events."""
|
"""Handle dedicated grounding metadata events."""
|
||||||
logger.debug("Received dedicated grounding metadata event.")
|
|
||||||
|
|
||||||
if evt.serverContent and evt.serverContent.groundingMetadata:
|
if evt.serverContent and evt.serverContent.groundingMetadata:
|
||||||
grounding_metadata = 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
|
# Process the grounding metadata immediately
|
||||||
await self._process_grounding_metadata(grounding_metadata, self._search_result_buffer)
|
await self._process_grounding_metadata(grounding_metadata, self._search_result_buffer)
|
||||||
|
|
||||||
async def _process_grounding_metadata(self, grounding_metadata: events.GroundingMetadata, search_result: str = ""):
|
async def _process_grounding_metadata(self, grounding_metadata: events.GroundingMetadata, search_result: str = ""):
|
||||||
"""Process grounding metadata and emit LLMSearchResponseFrame."""
|
"""Process grounding metadata and emit LLMSearchResponseFrame."""
|
||||||
logger.debug(f"Processing grounding metadata. Search result text length: {len(search_result)}")
|
|
||||||
if not grounding_metadata:
|
if not grounding_metadata:
|
||||||
logger.warning("No grounding metadata provided to _process_grounding_metadata")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# logger.debug(f"Processing grounding metadata: {grounding_metadata}") # Too verbose for PR
|
|
||||||
|
|
||||||
# Extract rendered content for search suggestions
|
# Extract rendered content for search suggestions
|
||||||
rendered_content = None
|
rendered_content = None
|
||||||
if grounding_metadata.searchEntryPoint and grounding_metadata.searchEntryPoint.renderedContent:
|
if grounding_metadata.searchEntryPoint and grounding_metadata.searchEntryPoint.renderedContent:
|
||||||
@@ -1324,7 +1312,6 @@ class GeminiMultimodalLiveLLMService(LLMService):
|
|||||||
rendered_content=rendered_content
|
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)
|
await self.push_frame(search_frame)
|
||||||
async def _handle_evt_usage_metadata(self, evt):
|
async def _handle_evt_usage_metadata(self, evt):
|
||||||
if not evt.usageMetadata:
|
if not evt.usageMetadata:
|
||||||
|
|||||||
Reference in New Issue
Block a user