Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mattieruth committed Sep 20, 2024
1 parent 4cf47d7 commit 16b3341
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 14 deletions.
Empty file added src/pipecat/metrics/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions src/pipecat/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -30,5 +30,5 @@ class CacheUsageMetricsData(LLMUsageMetricsData):

class TTSUsageMetricsData(MetricsData):
processor: str
model: Optional[str]
model: Optional[str] = None
value: int
4 changes: 2 additions & 2 deletions src/pipecat/pipeline/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/services/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/pipecat/services/cartesia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/services/deepgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/services/elevenlabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""}))
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/services/lmnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/services/playht.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/services/xtts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit 16b3341

Please sign in to comment.