From 25bcaf5c7c9572afffa32a01092b25960e580b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Wed, 15 Jan 2025 09:39:05 -0800 Subject: [PATCH] observers: introduce pipeline observers --- src/pipecat/observers/__init__.py | 0 src/pipecat/observers/base_observer.py | 38 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/pipecat/observers/__init__.py create mode 100644 src/pipecat/observers/base_observer.py diff --git a/src/pipecat/observers/__init__.py b/src/pipecat/observers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/pipecat/observers/base_observer.py b/src/pipecat/observers/base_observer.py new file mode 100644 index 000000000..2a17b5668 --- /dev/null +++ b/src/pipecat/observers/base_observer.py @@ -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