From 16b33412611bdef2b4cc903a8ea18096917096b4 Mon Sep 17 00:00:00 2001 From: mattie ruth backman Date: Wed, 18 Sep 2024 08:55:02 -0400 Subject: [PATCH] PR feedback --- src/pipecat/metrics/__init__.py | 0 src/pipecat/metrics/metrics.py | 6 +++--- src/pipecat/pipeline/task.py | 4 ++-- src/pipecat/services/azure.py | 2 +- src/pipecat/services/cartesia.py | 6 +++--- src/pipecat/services/deepgram.py | 2 +- src/pipecat/services/elevenlabs.py | 2 +- src/pipecat/services/lmnt.py | 2 +- src/pipecat/services/playht.py | 2 +- src/pipecat/services/xtts.py | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 src/pipecat/metrics/__init__.py diff --git a/src/pipecat/metrics/__init__.py b/src/pipecat/metrics/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/pipecat/metrics/metrics.py b/src/pipecat/metrics/metrics.py index dd0207276..9baffcbcb 100644 --- a/src/pipecat/metrics/metrics.py +++ b/src/pipecat/metrics/metrics.py @@ -8,12 +8,12 @@ class MetricsData(BaseModel): class TTFBMetricsData(MetricsData): value: float - model: Optional[str] + model: Optional[str] = None class ProcessingMetricsData(MetricsData): value: float - model: Optional[str] + model: Optional[str] = None class LLMUsageMetricsData(MetricsData): @@ -30,5 +30,5 @@ class CacheUsageMetricsData(LLMUsageMetricsData): class TTSUsageMetricsData(MetricsData): processor: str - model: Optional[str] + model: Optional[str] = None value: int diff --git a/src/pipecat/pipeline/task.py b/src/pipecat/pipeline/task.py index d04f9fe9b..26e6e9f4f 100644 --- a/src/pipecat/pipeline/task.py +++ b/src/pipecat/pipeline/task.py @@ -121,8 +121,8 @@ def _initial_metrics_frame(self) -> MetricsFrame: processors = self._pipeline.processors_with_metrics() data = [] for p in processors: - data.append(TTFBMetricsData(processor=p.name, value=0.0, model=None)) - data.append(ProcessingMetricsData(processor=p.name, value=0.0, model=None)) + data.append(TTFBMetricsData(processor=p.name, value=0.0)) + data.append(ProcessingMetricsData(processor=p.name, value=0.0)) return MetricsFrame(data=data) async def _process_down_queue(self): diff --git a/src/pipecat/services/azure.py b/src/pipecat/services/azure.py index ea9c8ec8d..07a75af2b 100644 --- a/src/pipecat/services/azure.py +++ b/src/pipecat/services/azure.py @@ -113,7 +113,7 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]: result = await asyncio.to_thread(self._speech_synthesizer.speak_ssml, (ssml)) if result.reason == ResultReason.SynthesizingAudioCompleted: - await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, model=None, value=len(text))) + await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, value=len(text))) await self.stop_ttfb_metrics() await self.push_frame(TTSStartedFrame()) # Azure always sends a 44-byte header. Strip it off. diff --git a/src/pipecat/services/cartesia.py b/src/pipecat/services/cartesia.py index 9247cad43..97aac634f 100644 --- a/src/pipecat/services/cartesia.py +++ b/src/pipecat/services/cartesia.py @@ -141,7 +141,7 @@ async def _connect(self): async def _disconnect(self): try: - await self.stop_all_metrics() + await self.stop_all_metrics(self._model_id) if self._websocket: await self._websocket.close() @@ -158,7 +158,7 @@ async def _disconnect(self): async def _handle_interruption(self, frame: StartInterruptionFrame, direction: FrameDirection): await super()._handle_interruption(frame, direction) - await self.stop_all_metrics() + await self.stop_all_metrics(self._model_id) await self.push_frame(LLMFullResponseEndFrame()) self._context_id = None @@ -211,7 +211,7 @@ async def _receive_task_handler(self): elif msg["type"] == "error": logger.error(f"{self} error: {msg}") await self.push_frame(TTSStoppedFrame()) - await self.stop_all_metrics() + await self.stop_all_metrics(self._model_id) await self.push_error(ErrorFrame(f'{self} error: {msg["error"]}')) else: logger.error(f"Cartesia error, unknown message type: {msg}") diff --git a/src/pipecat/services/deepgram.py b/src/pipecat/services/deepgram.py index 8f905b76d..6dfc9d5cb 100644 --- a/src/pipecat/services/deepgram.py +++ b/src/pipecat/services/deepgram.py @@ -100,7 +100,7 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]: yield ErrorFrame(f"Error getting audio (status: {r.status}, error: {response_text})") return - await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, model=None, value=len(text))) + await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, value=len(text))) await self.push_frame(TTSStartedFrame()) async for data in r.content: diff --git a/src/pipecat/services/elevenlabs.py b/src/pipecat/services/elevenlabs.py index 063e0c71c..35af8b5e3 100644 --- a/src/pipecat/services/elevenlabs.py +++ b/src/pipecat/services/elevenlabs.py @@ -181,7 +181,7 @@ async def _connect(self): async def _disconnect(self): try: - await self.stop_all_metrics() + await self.stop_all_metrics(self._model) if self._websocket: await self._websocket.send(json.dumps({"text": ""})) diff --git a/src/pipecat/services/lmnt.py b/src/pipecat/services/lmnt.py index eaf668301..2fec2d21f 100644 --- a/src/pipecat/services/lmnt.py +++ b/src/pipecat/services/lmnt.py @@ -155,7 +155,7 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]: try: await self._connection.append_text(text) await self._connection.flush() - await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, model=None, value=len(text))) + await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, value=len(text))) except Exception as e: logger.error(f"{self} error sending message: {e}") await self.push_frame(TTSStoppedFrame()) diff --git a/src/pipecat/services/playht.py b/src/pipecat/services/playht.py index 38834a09e..736d995c5 100644 --- a/src/pipecat/services/playht.py +++ b/src/pipecat/services/playht.py @@ -72,7 +72,7 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]: voice_engine="PlayHT2.0-turbo", options=self._options) - await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, model=None, value=len(text))) + await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, value=len(text))) await self.push_frame(TTSStartedFrame()) async for chunk in playht_gen: diff --git a/src/pipecat/services/xtts.py b/src/pipecat/services/xtts.py index d62dabfd5..47c398c6a 100644 --- a/src/pipecat/services/xtts.py +++ b/src/pipecat/services/xtts.py @@ -104,7 +104,7 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]: yield ErrorFrame(f"Error getting audio (status: {r.status}, error: {text})") return - await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, model=None, value=len(text))) + await self.start_tts_usage_metrics(TTSUsageMetricsData(processor=self.name, value=len(text))) await self.push_frame(TTSStartedFrame())