From 7749692f72181916725bfa075002bfb6b3f8cd59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 12 Sep 2024 00:18:29 -0700 Subject: [PATCH] processors: get pipeline clock from StartFrame --- src/pipecat/processors/frame_processor.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pipecat/processors/frame_processor.py b/src/pipecat/processors/frame_processor.py index 156e1c0ae..e228ec6b4 100644 --- a/src/pipecat/processors/frame_processor.py +++ b/src/pipecat/processors/frame_processor.py @@ -9,6 +9,7 @@ import time from enum import Enum +from pipecat.clocks.base_clock import BaseClock from pipecat.frames.frames import ( ErrorFrame, Frame, @@ -69,7 +70,10 @@ class FrameProcessorMetrics: async def start_llm_usage_metrics(self, tokens: dict): logger.debug( - f"{self._name} prompt tokens: {tokens['prompt_tokens']}, completion tokens: {tokens['completion_tokens']}") + f"{ + self._name} prompt tokens: { + tokens['prompt_tokens']}, completion tokens: { + tokens['completion_tokens']}") return MetricsFrame(tokens=[tokens]) async def start_tts_usage_metrics(self, text: str): @@ -96,6 +100,9 @@ class FrameProcessor: self._next: "FrameProcessor" | None = None self._loop: asyncio.AbstractEventLoop = loop or asyncio.get_running_loop() + # Clock + self._clock: BaseClock | None = None + # Properties self._allow_interruptions = False self._enable_metrics = False @@ -177,8 +184,12 @@ class FrameProcessor: def get_parent(self) -> "FrameProcessor": return self._parent + def get_clock(self) -> BaseClock: + return self._clock + async def process_frame(self, frame: Frame, direction: FrameDirection): if isinstance(frame, StartFrame): + self._clock = frame.clock self._allow_interruptions = frame.allow_interruptions self._enable_metrics = frame.enable_metrics self._enable_usage_metrics = frame.enable_usage_metrics