observers: introduce pipeline observers
This commit is contained in:
0
src/pipecat/observers/__init__.py
Normal file
0
src/pipecat/observers/__init__.py
Normal file
38
src/pipecat/observers/base_observer.py
Normal file
38
src/pipecat/observers/base_observer.py
Normal file
@@ -0,0 +1,38 @@
|
||||
#
|
||||
# Copyright (c) 2024–2025, Daily
|
||||
#
|
||||
# SPDX-License-Identifier: BSD 2-Clause License
|
||||
#
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from pipecat.frames.frames import Frame
|
||||
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
||||
|
||||
|
||||
class BaseObserver(ABC):
|
||||
"""This is the base class for pipeline frame observers. Observers can view
|
||||
all the frames that go through the pipeline without the need to inject
|
||||
processors in the pipeline. This can be useful, for example, to implement
|
||||
frame loggers or debuggers among other things.
|
||||
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def on_push_frame(
|
||||
self, src: FrameProcessor, dst: FrameProcessor, frame: Frame, direction: FrameDirection
|
||||
):
|
||||
"""Abstract method to handle the event when a frame is pushed from one
|
||||
processor to another.
|
||||
|
||||
Args:
|
||||
src (FrameProcessor): The source frame processor that is sending the frame.
|
||||
dst (FrameProcessor): The destination frame processor that will receive the frame.
|
||||
frame (Frame): The frame being transferred between processors.
|
||||
direction (FrameDirection): The direction of the frame transfer.
|
||||
|
||||
This method should be implemented by subclasses to define specific behavior
|
||||
when a frame is pushed.
|
||||
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user