feat(voice): support evidence reuse, 120s output capacity, and input ASR coalescing
- Add internal reuse_last_evidence tool for continuing existing topic without repeated retrieval - Expand OpenAI output capacity to 120s / 5,760,000 bytes and add delivery fairness - Coalesce adjacent user ASR transcript deltas to prevent client control queue overflow - Add server-side OPENAI_REALTIME_SPEED configuration and update style to v4 - Add extensive unit and integration regressions for evidence reuse, capacity, and fairness
This commit is contained in:
@@ -183,7 +183,9 @@ class GeminiLiveAdapter:
|
||||
'realtimeInputConfig': {'activityHandling':'NO_INTERRUPTION'},
|
||||
'inputAudioTranscription': {}, 'outputAudioTranscription': {},
|
||||
'tools':[{'functionDeclarations':[{'name':'search_knowledge',
|
||||
'description':'Retrieve authorized evidence. Provide ONLY clean search keywords in query. Set context to null.', 'parameters':_schema(SearchInput.model_json_schema())}]}]}})
|
||||
'description':'Retrieve authorized evidence. Provide ONLY clean search keywords in query. Set context to null.', 'parameters':_schema(SearchInput.model_json_schema())},
|
||||
{'name':'reuse_last_evidence', 'description':'Revalidate the last same-topic evidence. No arguments; search freshly when insufficient.',
|
||||
'parameters': {'type':'OBJECT', 'properties':{}}}]}]}})
|
||||
self._pump_task = asyncio.create_task(self._read_provider_loop())
|
||||
return
|
||||
if not self._confirmed:
|
||||
@@ -449,17 +451,38 @@ class GeminiLiveAdapter:
|
||||
async def close(self):
|
||||
if self._close_task is None:
|
||||
async def cleanup():
|
||||
if self._pump_task and self._pump_task is not asyncio.current_task():
|
||||
self._pump_task.cancel()
|
||||
await asyncio.gather(self._pump_task, return_exceptions=True)
|
||||
pending = set()
|
||||
try:
|
||||
await asyncio.wait_for(self.transport.close(), self.settings.send_timeout_seconds)
|
||||
if self._pump_task and self._pump_task is not asyncio.current_task():
|
||||
self._pump_task.cancel()
|
||||
_, pending = await asyncio.wait({self._pump_task}, timeout=self.settings.send_timeout_seconds)
|
||||
if pending:
|
||||
self._pump_task.add_done_callback(lambda task: task.exception() if not task.cancelled() else None)
|
||||
try:
|
||||
self.abort()
|
||||
except Exception:
|
||||
pass # Still attempt transport closure independently.
|
||||
closing = asyncio.create_task(self.transport.close())
|
||||
closed, _ = await asyncio.wait({closing}, timeout=self.settings.send_timeout_seconds)
|
||||
if not closed:
|
||||
closing.cancel()
|
||||
closing.add_done_callback(lambda task: task.exception() if not task.cancelled() else None)
|
||||
try:
|
||||
self.abort()
|
||||
except Exception:
|
||||
pass
|
||||
raise TimeoutError('Gemini transport close deadline')
|
||||
# Propagate the close result; don't report cancelled/incomplete cleanup as success.
|
||||
await closing
|
||||
if pending:
|
||||
raise TimeoutError('Gemini pump termination deadline')
|
||||
finally:
|
||||
while not self._inbound_events.empty():
|
||||
self._inbound_events.get_nowait()
|
||||
self._queued_bytes = self._control_count = 0
|
||||
self._audio_bytes = self._audio_slabs = self._leased_audio = self._audio_metadata = 0
|
||||
self._close_task = asyncio.create_task(cleanup())
|
||||
self._close_task.add_done_callback(lambda task: task.exception() if not task.cancelled() else None)
|
||||
await asyncio.shield(self._close_task)
|
||||
|
||||
async def connect_gemini(api_key, model='gemini-2.0-flash-exp', proxy=None, settings=None):
|
||||
|
||||
Reference in New Issue
Block a user