Skip to content

Commit

Permalink
bring back user transcript logs (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom authored Oct 30, 2024
1 parent 5376f08 commit ee0ca5a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions examples/voice-pipeline-agent/cost_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions examples/voice-pipeline-agent/minimal_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions livekit-agents/livekit/agents/metrics/usage_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions livekit-agents/livekit/agents/pipeline/pipeline_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 += (
Expand Down

0 comments on commit ee0ca5a

Please sign in to comment.