Fixed issue where sending too many images per second caused Gemini to ignore them.

This commit is contained in:
Filipi Fuchter
2025-03-11 11:32:38 -03:00
parent 5bd359ada9
commit aab98b61a0

View File

@@ -7,6 +7,7 @@
import asyncio import asyncio
import base64 import base64
import json import json
import time
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum from enum import Enum
from typing import Any, Dict, List, Mapping, Optional, Union from typing import Any, Dict, List, Mapping, Optional, Union
@@ -175,6 +176,7 @@ class GeminiMultimodalLiveLLMService(LLMService):
**kwargs, **kwargs,
): ):
super().__init__(base_url=base_url, **kwargs) super().__init__(base_url=base_url, **kwargs)
self._last_sent_time = 0
self.api_key = api_key self.api_key = api_key
self.base_url = base_url self.base_url = base_url
self.set_model_name(model) self.set_model_name(model)
@@ -543,7 +545,13 @@ class GeminiMultimodalLiveLLMService(LLMService):
async def _send_user_video(self, frame): async def _send_user_video(self, frame):
if self._video_input_paused: if self._video_input_paused:
return return
# logger.debug(f"Sending video frame to Gemini: {frame}")
now = time.time()
if now - self._last_sent_time < 1:
return # Ignore if less than 1 second has passed
self._last_sent_time = now # Update last sent time
logger.debug(f"Sending video frame to Gemini: {frame}")
evt = events.VideoInputMessage.from_image_frame(frame) evt = events.VideoInputMessage.from_image_frame(frame)
await self.send_client_event(evt) await self.send_client_event(evt)