function_filter

Function-based frame filtering for Pipecat pipelines.

This module provides a processor that filters frames based on a custom function, allowing for flexible frame filtering logic in processing pipelines.

class pipecat.processors.filters.function_filter.FunctionFilter(filter: Callable[[Frame], Awaitable[bool]], direction: FrameDirection | None = FrameDirection.DOWNSTREAM, filter_system_frames: bool = False, **kwargs)[source]

Bases: FrameProcessor

A frame processor that filters frames using a custom function.

This processor allows frames to pass through based on the result of a user-provided filter function. System and end frames always pass through regardless of the filter result.

__init__(filter: Callable[[Frame], Awaitable[bool]], direction: FrameDirection | None = FrameDirection.DOWNSTREAM, filter_system_frames: bool = False, **kwargs)[source]

Initialize the function filter.

Parameters:
  • filter – An async function that takes a Frame and returns True if the frame should pass through, False otherwise.

  • direction – The direction to apply filtering. Only frames moving in this direction will be filtered; frames in the other direction pass through unfiltered. If None, frames in both directions are filtered. Defaults to DOWNSTREAM.

  • filter_system_frames – Whether to filter system frames. Defaults to False.

  • **kwargs – Additional arguments passed to parent class.

async process_frame(frame: Frame, direction: FrameDirection)[source]

Process a frame through the filter.

Parameters:
  • frame – The frame to process.

  • direction – The direction the frame is moving in the pipeline.