[WIP] AWS Nova Sonic service - Protect against back-to-back BotStoppedSpeaking calls, which I've observed
This commit is contained in:
@@ -145,6 +145,8 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
self._assistant_is_responding = False
|
self._assistant_is_responding = False
|
||||||
self._context_available = False
|
self._context_available = False
|
||||||
self._ready_to_send_context = False
|
self._ready_to_send_context = False
|
||||||
|
self._handling_bot_stopped_speaking = False
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# standard AIService frame handling
|
# standard AIService frame handling
|
||||||
@@ -211,6 +213,11 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
await self._finish_connecting_if_context_available()
|
await self._finish_connecting_if_context_available()
|
||||||
|
|
||||||
async def _handle_bot_stopped_speaking(self):
|
async def _handle_bot_stopped_speaking(self):
|
||||||
|
# Protect against back-to-back BotStoppedSpeaking calls, which I've observed
|
||||||
|
if self._handling_bot_stopped_speaking:
|
||||||
|
return
|
||||||
|
self._handling_bot_stopped_speaking = True
|
||||||
|
|
||||||
if self._assistant_is_responding:
|
if self._assistant_is_responding:
|
||||||
# Consider the assistant finished with their response (after a short delay, to allow for
|
# Consider the assistant finished with their response (after a short delay, to allow for
|
||||||
# any FINAL text block to come in).
|
# any FINAL text block to come in).
|
||||||
@@ -229,6 +236,9 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
await asyncio.sleep(0.25)
|
await asyncio.sleep(0.25)
|
||||||
self._assistant_is_responding = False
|
self._assistant_is_responding = False
|
||||||
await self._report_assistant_response_ended()
|
await self._report_assistant_response_ended()
|
||||||
|
self._handling_bot_stopped_speaking = False
|
||||||
|
|
||||||
|
self._handling_bot_stopped_speaking = False
|
||||||
|
|
||||||
async def _handle_function_call_result(self, frame: AWSNovaSonicFunctionCallResultFrame):
|
async def _handle_function_call_result(self, frame: AWSNovaSonicFunctionCallResultFrame):
|
||||||
result = frame.result_frame
|
result = frame.result_frame
|
||||||
|
|||||||
Reference in New Issue
Block a user