From 2dfdceb9e6ab820fd400c2347b4ea362cbae9d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 17 Dec 2024 16:12:49 -0800 Subject: [PATCH] processors(filters): allow passing EndFrame --- src/pipecat/processors/filters/frame_filter.py | 4 ++-- src/pipecat/processors/filters/function_filter.py | 7 ++++--- src/pipecat/processors/filters/null_filter.py | 13 ++++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/pipecat/processors/filters/frame_filter.py b/src/pipecat/processors/filters/frame_filter.py index 11f2e601a..674670163 100644 --- a/src/pipecat/processors/filters/frame_filter.py +++ b/src/pipecat/processors/filters/frame_filter.py @@ -6,7 +6,7 @@ from typing import Tuple, Type -from pipecat.frames.frames import ControlFrame, Frame, SystemFrame +from pipecat.frames.frames import EndFrame, Frame, SystemFrame from pipecat.processors.frame_processor import FrameDirection, FrameProcessor @@ -23,7 +23,7 @@ def _should_passthrough_frame(self, frame): if isinstance(frame, self._types): return True - return isinstance(frame, ControlFrame) or isinstance(frame, SystemFrame) + return isinstance(frame, (EndFrame, SystemFrame)) async def process_frame(self, frame: Frame, direction: FrameDirection): await super().process_frame(frame, direction) diff --git a/src/pipecat/processors/filters/function_filter.py b/src/pipecat/processors/filters/function_filter.py index e38cea3e0..1d06be02c 100644 --- a/src/pipecat/processors/filters/function_filter.py +++ b/src/pipecat/processors/filters/function_filter.py @@ -6,7 +6,7 @@ from typing import Awaitable, Callable -from pipecat.frames.frames import Frame, SystemFrame +from pipecat.frames.frames import EndFrame, Frame, SystemFrame from pipecat.processors.frame_processor import FrameDirection, FrameProcessor @@ -24,9 +24,10 @@ def __init__( # Frame processor # - # Ignore system frames and frames that are not following the direction of this gate + # Ignore system frames, end frames and frames that are not following the + # direction of this gate def _should_passthrough_frame(self, frame, direction): - return isinstance(frame, SystemFrame) or direction != self._direction + return isinstance(frame, (SystemFrame, EndFrame)) or direction != self._direction async def process_frame(self, frame: Frame, direction: FrameDirection): await super().process_frame(frame, direction) diff --git a/src/pipecat/processors/filters/null_filter.py b/src/pipecat/processors/filters/null_filter.py index 7e9ca6725..219cc149c 100644 --- a/src/pipecat/processors/filters/null_filter.py +++ b/src/pipecat/processors/filters/null_filter.py @@ -4,7 +4,8 @@ # SPDX-License-Identifier: BSD 2-Clause License # -from pipecat.processors.frame_processor import FrameProcessor +from pipecat.frames.frames import EndFrame, Frame, SystemFrame +from pipecat.processors.frame_processor import FrameDirection, FrameProcessor class NullFilter(FrameProcessor): @@ -12,3 +13,13 @@ class NullFilter(FrameProcessor): def __init__(self, **kwargs): super().__init__(**kwargs) + + # + # Frame processor + # + + async def process_frame(self, frame: Frame, direction: FrameDirection): + await super().process_frame(frame, direction) + + if isinstance(frame, (SystemFrame, EndFrame)): + await self.push_frame(frame, direction)