Skip to content

Commit

Permalink
use isinstance tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
aconchillo committed Oct 6, 2024
1 parent 1f54ee6 commit 4a74eb3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pipecat/pipeline/parallel_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):

# 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)
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/pipeline/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async def _process_push_queue(self):
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:
Expand Down
4 changes: 2 additions & 2 deletions src/pipecat/services/ai_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):
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)
Expand Down Expand Up @@ -369,7 +369,7 @@ async def cancel(self, frame: CancelFrame):
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):
Expand Down
4 changes: 2 additions & 2 deletions src/pipecat/transports/base_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):
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):
Expand All @@ -196,7 +196,7 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):
# 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)
Expand Down

0 comments on commit 4a74eb3

Please sign in to comment.