[WIP] AWS Nova Sonic service - add send_transcription_frames option
This commit is contained in:
@@ -118,6 +118,7 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
voice_id: str = "matthew", # matthew, tiffany, amy
|
voice_id: str = "matthew", # matthew, tiffany, amy
|
||||||
instruction: Optional[str] = None,
|
instruction: Optional[str] = None,
|
||||||
tools: Optional[ToolsSchema] = None,
|
tools: Optional[ToolsSchema] = None,
|
||||||
|
send_transcription_frames: bool = True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
@@ -129,6 +130,7 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
self._voice_id = voice_id
|
self._voice_id = voice_id
|
||||||
self._instruction = instruction
|
self._instruction = instruction
|
||||||
self._tools = tools
|
self._tools = tools
|
||||||
|
self._send_transcription_frames = send_transcription_frames
|
||||||
self._context: AWSNovaSonicLLMContext = None
|
self._context: AWSNovaSonicLLMContext = None
|
||||||
self._stream: DuplexEventStream[
|
self._stream: DuplexEventStream[
|
||||||
InvokeModelWithBidirectionalStreamInput,
|
InvokeModelWithBidirectionalStreamInput,
|
||||||
@@ -802,10 +804,12 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
# Manually add new user transcription text to context.
|
# Manually add new user transcription text to context.
|
||||||
# We can't rely on the user context aggregator to do this since it's upstream from the LLM.
|
# We can't rely on the user context aggregator to do this since it's upstream from the LLM.
|
||||||
self._context.add_user_transcription_text_as_message(text)
|
self._context.add_user_transcription_text_as_message(text)
|
||||||
|
|
||||||
# Report that some new user transcription text is available.
|
# Report that some new user transcription text is available.
|
||||||
await self.push_frame(
|
if self._send_transcription_frames:
|
||||||
TranscriptionFrame(text=text, user_id="", timestamp=time_now_iso8601())
|
await self.push_frame(
|
||||||
)
|
TranscriptionFrame(text=text, user_id="", timestamp=time_now_iso8601())
|
||||||
|
)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Context
|
# Context
|
||||||
|
|||||||
@@ -94,11 +94,11 @@ class AWSNovaSonicLLMContext(OpenAILLMContext):
|
|||||||
f"Unhandled content type in context message: {c.get('type')} - {message}"
|
f"Unhandled content type in context message: {c.get('type')} - {message}"
|
||||||
)
|
)
|
||||||
# There won't be content if this is an assistant tool call entry.
|
# There won't be content if this is an assistant tool call entry.
|
||||||
# We're ignoring those since they can't be loaded into AWS Nova Sonic conversation
|
# We're ignoring those since they can't be loaded into AWS Nova Sonic conversation
|
||||||
# history
|
# history
|
||||||
if content:
|
if content:
|
||||||
return AWSNovaSonicConversationHistoryMessage(role=Role[role.upper()], text=content)
|
return AWSNovaSonicConversationHistoryMessage(role=Role[role.upper()], text=content)
|
||||||
# We're ignoring messages with role "tool" since they can't be loaded into AWS Nova Sonic
|
# We're ignoring messages with role "tool" since they can't be loaded into AWS Nova Sonic
|
||||||
# conversation history
|
# conversation history
|
||||||
logger.error(f"Unhandled message type in from_standard_message: {message}")
|
logger.error(f"Unhandled message type in from_standard_message: {message}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user