diff --git a/examples/foundational/20e-persistent-context-aws-nova-sonic.py b/examples/foundational/20e-persistent-context-aws-nova-sonic.py index 731c69c3a..8ac1508f8 100644 --- a/examples/foundational/20e-persistent-context-aws-nova-sonic.py +++ b/examples/foundational/20e-persistent-context-aws-nova-sonic.py @@ -175,6 +175,10 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection): ), ) + # Specify initial system instruction. + # HACK: note that, for now, we need to inject a special bit of text into this instruction to + # allow the first assistant response to be programmatically triggered (which happens in the + # on_client_connected handler, below) system_instruction = ( "You are a friendly assistant. The user and you will engage in a spoken dialog exchanging " "the transcripts of a natural real-time conversation. Keep your responses short, generally " diff --git a/examples/foundational/39-aws-nova-sonic.py b/examples/foundational/39-aws-nova-sonic.py index a89796ea6..fe0d07dca 100644 --- a/examples/foundational/39-aws-nova-sonic.py +++ b/examples/foundational/39-aws-nova-sonic.py @@ -87,7 +87,6 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection): # HACK: note that, for now, we need to inject a special bit of text into this instruction to # allow the first assistant response to be programmatically triggered (which happens in the # on_client_connected handler, below) - # TODO: looks like Nova Sonic can't handle new lines? system_instruction = ( "You are a friendly assistant. The user and you will engage in a spoken dialog exchanging " "the transcripts of a natural real-time conversation. Keep your responses short, generally " diff --git a/src/pipecat/services/aws_nova_sonic/aws.py b/src/pipecat/services/aws_nova_sonic/aws.py index 50b83d3e0..e5df20e66 100644 --- a/src/pipecat/services/aws_nova_sonic/aws.py +++ b/src/pipecat/services/aws_nova_sonic/aws.py @@ -498,7 +498,7 @@ class AWSNovaSonicLLMService(LLMService): await self._send_client_event(audio_content_start) async def _send_text_event(self, text: str, role: Role): - if not self._stream: + if not self._stream or not text: return content_name = str(uuid.uuid4()) @@ -521,13 +521,14 @@ class AWSNovaSonicLLMService(LLMService): ''' await self._send_client_event(text_content_start) + escaped_text = json.dumps(text) # includes quotes text_input = f''' {{ "event": {{ "textInput": {{ "promptName": "{self._prompt_name}", "contentName": "{content_name}", - "content": "{text}" + "content": {escaped_text} }} }} }}