From 0265c1d3eff0df2de59099c27e4eb797d972104b Mon Sep 17 00:00:00 2001 From: Nikita Gamolsky Date: Sat, 2 Nov 2024 16:12:29 -0700 Subject: [PATCH] alllow interrupt --- examples/foundational/99-anthropic-hackathon.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/foundational/99-anthropic-hackathon.py b/examples/foundational/99-anthropic-hackathon.py index f23c27af1..042d0ac48 100644 --- a/examples/foundational/99-anthropic-hackathon.py +++ b/examples/foundational/99-anthropic-hackathon.py @@ -19,6 +19,7 @@ from runner import configure from pipecat.audio.vad.silero import SileroVADAnalyzer from pipecat.frames.frames import ( + BotInterruptionFrame, Frame, ImageRawFrame, LLMFullResponseEndFrame, @@ -209,9 +210,7 @@ Your response will be turned into speech so use only simple words and punctuatio ], ) - task = PipelineTask( - pipeline, PipelineParams(allow_interruptions=False, enable_metrics=True) - ) + task = PipelineTask(pipeline, PipelineParams(allow_interruptions=True, enable_metrics=True)) @transport.event_handler("on_first_participant_joined") async def on_first_participant_joined(transport, participant): @@ -227,6 +226,7 @@ Your response will be turned into speech so use only simple words and punctuatio @transport.event_handler("on_app_message") async def on_app_message(transport, message, sender): logger.debug(f"Received app message: {message} - {context}") + if not recent_image_frames: logger.debug("No image frames to send") return @@ -235,7 +235,13 @@ Your response will be turned into speech so use only simple words and punctuatio anthropic_context, message["message"], frames=list(recent_image_frames) ) - await task.queue_frames([context_aggregator.user().get_context_frame()]) + interrupt_message = "STOP" + + if interrupt_message == message["message"]: + logger.debug("Interrupting") + await task.queue_frames([BotInterruptionFrame()]) + else: + await task.queue_frames([context_aggregator.user().get_context_frame()]) runner = PipelineRunner() await runner.run(task)