From 4a74eb3321fb1a5843208112182256226c616088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Sun, 6 Oct 2024 00:45:27 -0700 Subject: [PATCH] use isinstance tuples --- src/pipecat/pipeline/parallel_pipeline.py | 2 +- src/pipecat/pipeline/task.py | 2 +- src/pipecat/services/ai_services.py | 4 ++-- src/pipecat/transports/base_output.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pipecat/pipeline/parallel_pipeline.py b/src/pipecat/pipeline/parallel_pipeline.py index 1c2eeabde..da68212ff 100644 --- a/src/pipecat/pipeline/parallel_pipeline.py +++ b/src/pipecat/pipeline/parallel_pipeline.py @@ -120,7 +120,7 @@ class ParallelPipeline(BasePipeline): # If we get an EndFrame we stop our queue processing tasks and wait on # all the pipelines to finish. - if isinstance(frame, CancelFrame) or isinstance(frame, EndFrame): + if isinstance(frame, (CancelFrame, EndFrame)): # Use None to indicate when queues should be done processing. await self._up_queue.put(None) await self._down_queue.put(None) diff --git a/src/pipecat/pipeline/task.py b/src/pipecat/pipeline/task.py index 96845430d..1b2d67ea9 100644 --- a/src/pipecat/pipeline/task.py +++ b/src/pipecat/pipeline/task.py @@ -175,7 +175,7 @@ class PipelineTask: await self._source.process_frame(frame, FrameDirection.DOWNSTREAM) if isinstance(frame, EndFrame): await self._wait_for_endframe() - running = not (isinstance(frame, StopTaskFrame) or isinstance(frame, EndFrame)) + running = not isinstance(frame, (StopTaskFrame, EndFrame)) should_cleanup = not isinstance(frame, StopTaskFrame) self._push_queue.task_done() except asyncio.CancelledError: diff --git a/src/pipecat/services/ai_services.py b/src/pipecat/services/ai_services.py index 90ce29e76..3deabf68c 100644 --- a/src/pipecat/services/ai_services.py +++ b/src/pipecat/services/ai_services.py @@ -259,7 +259,7 @@ class TTSService(AIService): await self._process_text_frame(frame) elif isinstance(frame, StartInterruptionFrame): await self._handle_interruption(frame, direction) - elif isinstance(frame, LLMFullResponseEndFrame) or isinstance(frame, EndFrame): + elif isinstance(frame, (LLMFullResponseEndFrame, EndFrame)): sentence = self._current_sentence self._current_sentence = "" await self._push_tts_frames(sentence) @@ -369,7 +369,7 @@ class WordTTSService(TTSService): async def process_frame(self, frame: Frame, direction: FrameDirection): await super().process_frame(frame, direction) - if isinstance(frame, LLMFullResponseEndFrame) or isinstance(frame, EndFrame): + if isinstance(frame, (LLMFullResponseEndFrame, EndFrame)): await self.flush_audio() async def _handle_interruption(self, frame: StartInterruptionFrame, direction: FrameDirection): diff --git a/src/pipecat/transports/base_output.py b/src/pipecat/transports/base_output.py index c3b9c792b..6ee458f37 100644 --- a/src/pipecat/transports/base_output.py +++ b/src/pipecat/transports/base_output.py @@ -180,7 +180,7 @@ class BaseOutputTransport(FrameProcessor): elif isinstance(frame, CancelFrame): await self.cancel(frame) await self.push_frame(frame, direction) - elif isinstance(frame, StartInterruptionFrame) or isinstance(frame, StopInterruptionFrame): + elif isinstance(frame, (StartInterruptionFrame, StopInterruptionFrame)): await self.push_frame(frame, direction) await self._handle_interruptions(frame) elif isinstance(frame, MetricsFrame): @@ -196,7 +196,7 @@ class BaseOutputTransport(FrameProcessor): # Other frames. elif isinstance(frame, OutputAudioRawFrame): await self._handle_audio(frame) - elif isinstance(frame, OutputImageRawFrame) or isinstance(frame, SpriteFrame): + elif isinstance(frame, (OutputImageRawFrame, SpriteFrame)): await self._handle_image(frame) elif isinstance(frame, TransportMessageFrame) and frame.urgent: await self.send_message(frame)