fixes for proposed judge pipeline
This commit is contained in:
@@ -11,19 +11,27 @@ from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
||||
|
||||
|
||||
class FunctionFilter(FrameProcessor):
|
||||
def __init__(self, filter: Callable[[Frame], Awaitable[bool]]):
|
||||
def __init__(
|
||||
self,
|
||||
filter: Callable[[Frame], Awaitable[bool]],
|
||||
direction: FrameDirection = FrameDirection.DOWNSTREAM,
|
||||
):
|
||||
super().__init__()
|
||||
self._filter = filter
|
||||
self._direction = direction
|
||||
|
||||
#
|
||||
# Frame processor
|
||||
#
|
||||
|
||||
def _should_passthrough_frame(self, frame):
|
||||
return isinstance(frame, SystemFrame)
|
||||
# Ignore system 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
|
||||
|
||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
||||
passthrough = self._should_passthrough_frame(frame)
|
||||
await super().process_frame(frame, direction)
|
||||
|
||||
passthrough = self._should_passthrough_frame(frame, direction)
|
||||
allowed = await self._filter(frame)
|
||||
if passthrough or allowed:
|
||||
await self.push_frame(frame, direction)
|
||||
|
||||
Reference in New Issue
Block a user