From ee0ca5a4d23ef6277ff6826893e60f99db58f925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Monnom?= Date: Wed, 30 Oct 2024 14:06:40 -0700 Subject: [PATCH] bring back user transcript logs (#1014) --- examples/voice-pipeline-agent/cost_metrics.py | 6 +++--- examples/voice-pipeline-agent/minimal_assistant.py | 6 +++--- livekit-agents/livekit/agents/metrics/usage_collector.py | 4 ++-- livekit-agents/livekit/agents/pipeline/pipeline_agent.py | 5 +++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/voice-pipeline-agent/cost_metrics.py b/examples/voice-pipeline-agent/cost_metrics.py index f39e58fc7..b8544898b 100644 --- a/examples/voice-pipeline-agent/cost_metrics.py +++ b/examples/voice-pipeline-agent/cost_metrics.py @@ -51,9 +51,9 @@ async def entrypoint(ctx: JobContext): usage_collector = metrics.UsageCollector() @agent.on("metrics_collected") - def _on_metrics_collected(metrics: metrics.AgentMetrics): - metrics.log_metrics(metrics) - usage_collector.add_usage(metrics) + def _on_metrics_collected(mtrcs: metrics.AgentMetrics): + metrics.log_metrics(mtrcs) + usage_collector.collect(mtrcs) async def log_session_cost(): summary = usage_collector.get_summary() diff --git a/examples/voice-pipeline-agent/minimal_assistant.py b/examples/voice-pipeline-agent/minimal_assistant.py index e8edd6161..cfa43bcbc 100644 --- a/examples/voice-pipeline-agent/minimal_assistant.py +++ b/examples/voice-pipeline-agent/minimal_assistant.py @@ -57,9 +57,9 @@ async def entrypoint(ctx: JobContext): usage_collector = metrics.UsageCollector() @agent.on("metrics_collected") - def _on_metrics_collected(metrics: metrics.AgentMetrics): - metrics.log_metrics(metrics) - usage_collector.add_usage(metrics) + def _on_metrics_collected(mtrcs: metrics.AgentMetrics): + metrics.log_metrics(mtrcs) + usage_collector.collect(mtrcs) async def log_usage(): summary = usage_collector.get_summary() diff --git a/livekit-agents/livekit/agents/metrics/usage_collector.py b/livekit-agents/livekit/agents/metrics/usage_collector.py index b32ca4e23..4cdd443fe 100644 --- a/livekit-agents/livekit/agents/metrics/usage_collector.py +++ b/livekit-agents/livekit/agents/metrics/usage_collector.py @@ -17,9 +17,9 @@ def __init__(self) -> None: self._summary = UsageSummary(0, 0, 0, 0.0) def __call__(self, metrics: AgentMetrics) -> None: - self.add_usage(metrics) + self.collect(metrics) - def add_usage(self, metrics: AgentMetrics) -> None: + def collect(self, metrics: AgentMetrics) -> None: if isinstance(metrics, LLMMetrics): self._summary.llm_prompt_tokens += metrics.prompt_tokens self._summary.llm_completion_tokens += metrics.completion_tokens diff --git a/livekit-agents/livekit/agents/pipeline/pipeline_agent.py b/livekit-agents/livekit/agents/pipeline/pipeline_agent.py index 69376c426..ca7baca72 100644 --- a/livekit-agents/livekit/agents/pipeline/pipeline_agent.py +++ b/livekit-agents/livekit/agents/pipeline/pipeline_agent.py @@ -512,6 +512,11 @@ def _on_final_transcript(ev: stt.SpeechEvent) -> None: if not new_transcript: return + logger.debug( + "received user transcript", + extra={"user_transcript": new_transcript}, + ) + self._last_final_transcript_time = time.perf_counter() self._transcribed_text += (