Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processors(filters): allow passing EndFrame #884

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pipecat/processors/filters/frame_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/pipecat/processors/filters/function_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion src/pipecat/processors/filters/null_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
# 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):
"""This filter doesn't allow passing any frames up or downstream."""

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)
Loading