Skip to content

Commit

Permalink
Merge pull request #884 from pipecat-ai/aleix/filters-handle-endframe
Browse files Browse the repository at this point in the history
processors(filters): allow passing EndFrame
  • Loading branch information
aconchillo authored Dec 19, 2024
2 parents 17decee + 2dfdceb commit 78b90e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
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)

0 comments on commit 78b90e9

Please sign in to comment.