diff --git a/CHANGELOG.md b/CHANGELOG.md index 5246be593..27a620e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,17 +12,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Introduced 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. + debuggers among other things. The example + `examples/foundational/30-observer.py` shows how to add an observer to a + pipeline for debugging. - Introduced heartbeat frames. The pipeline task can now push periodic heartbeats down the pipeline when `enable_heartbeats=True`. Heartbeats are system frames that are supposed to make it all the way to the end of the - pipeline. When a heartbeat frame is received the traversing time (i.e. the time - it took to go through the whole pipeline) will be displayed (with TRACE - logging) otherwise a warning will be shown. - -- Added `30-observer.py` to show how to add an Observer to a pipeline for - debugging. + pipeline. When a heartbeat frame is received the traversing time (i.e. the + time it took to go through the whole pipeline) will be displayed (with TRACE + logging) otherwise a warning will be shown. The example + `examples/foundational/31-heartbeats.py` shows how to enable heartbeats and + forces warnings to be displayed. - Added `OpenRouter` for OpenRouter integration with an OpenAI-compatible interface. Added foundational example `14m-function-calling-openrouter.py`. diff --git a/examples/foundational/31-heartbeats.py b/examples/foundational/31-heartbeats.py new file mode 100644 index 000000000..fbb959519 --- /dev/null +++ b/examples/foundational/31-heartbeats.py @@ -0,0 +1,43 @@ +# +# Copyright (c) 2024–2025, Daily +# +# SPDX-License-Identifier: BSD 2-Clause License +# + +import asyncio +import sys + +from loguru import logger + +from pipecat.frames.frames import Frame +from pipecat.pipeline.pipeline import Pipeline +from pipecat.pipeline.runner import PipelineRunner +from pipecat.pipeline.task import PipelineParams, PipelineTask +from pipecat.processors.frame_processor import FrameDirection, FrameProcessor + +logger.remove(0) +logger.add(sys.stderr, level="DEBUG") + + +class NullProcessor(FrameProcessor): + async def process_frame(self, frame: Frame, direction: FrameDirection): + await super().process_frame(frame, direction) + + +async def main(): + """This test shows heartbeat monitoring by displaying a warning when + heartbeats are not received. + + """ + + pipeline = Pipeline([NullProcessor()]) + + task = PipelineTask(pipeline, PipelineParams(enable_heartbeats=True)) + + runner = PipelineRunner() + + await runner.run(task) + + +if __name__ == "__main__": + asyncio.run(main())