From e92b103fd00933313b4ec53cd3767e9ce22cdb68 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 17 Jan 2026 21:44:13 +0800 Subject: [PATCH] feat: add metrics --- astrbot/core/astr_agent_run_util.py | 6 ++++-- astrbot/dashboard/routes/live_chat.py | 11 +++++------ dashboard/src/components/chat/LiveMode.vue | 14 ++++++++++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/astrbot/core/astr_agent_run_util.py b/astrbot/core/astr_agent_run_util.py index 3301c7ffe..2267ae203 100644 --- a/astrbot/core/astr_agent_run_util.py +++ b/astrbot/core/astr_agent_run_util.py @@ -258,8 +258,10 @@ async def run_live_agent( chain=[ Json( data={ - "duration": tts_duration, - "first_frame_time": tts_first_frame_time, + "tts_total_time": tts_duration, + "tts_first_frame_time": tts_first_frame_time, + "tts": tts_provider.meta().type, + "chat_model": agent_runner.provider.get_model(), } ) ], diff --git a/astrbot/dashboard/routes/live_chat.py b/astrbot/dashboard/routes/live_chat.py index eb17c8c94..0c3ddcc2e 100644 --- a/astrbot/dashboard/routes/live_chat.py +++ b/astrbot/dashboard/routes/live_chat.py @@ -222,6 +222,10 @@ class LiveChatRoute(Route): await websocket.send_json({"t": "error", "data": "语音识别服务未配置"}) return + await websocket.send_json( + {"t": "metrics", "data": {"stt": stt_provider.meta().type}} + ) + user_text = await stt_provider.get_text(audio_path) if not user_text: logger.warning("[Live Chat] STT 识别结果为空") @@ -314,12 +318,7 @@ class LiveChatRoute(Route): await websocket.send_json( { "t": "metrics", - "data": { - "tts_total_time": stats.get("duration", 0), - "tts_first_frame_time": stats.get( - "first_frame_time", 0 - ), - }, + "data": stats, } ) except Exception as e: diff --git a/dashboard/src/components/chat/LiveMode.vue b/dashboard/src/components/chat/LiveMode.vue index b6c4ac26c..c4b73365b 100644 --- a/dashboard/src/components/chat/LiveMode.vue +++ b/dashboard/src/components/chat/LiveMode.vue @@ -22,19 +22,22 @@
WAV Assemble: {{ (metrics.wav_assemble_time * 1000).toFixed(0) - }}ms + }}ms LLM First Token Latency: {{ (metrics.llm_ttft * 1000).toFixed(0) - }}ms + }}ms LLM Total Latency: {{ (metrics.llm_total_time * 1000).toFixed(0) - }}ms + }}ms TTS First Frame Latency: {{ (metrics.tts_first_frame_time * 1000).toFixed(0) }}ms TTS Total Larency: {{ (metrics.tts_total_time * 1000).toFixed(0) - }}ms + }}ms Speak -> First TTS Frame: {{ (metrics.speak_to_first_frame * 1000).toFixed(0) }}ms Speak -> End: {{ (metrics.wav_to_tts_total_time * 1000).toFixed(0) }}ms + STT Provider: {{ metrics.stt }} + TTS Provider: {{ metrics.tts }} + Chat Model: {{ metrics.chat_model }}
@@ -93,6 +96,9 @@ interface LiveMetrics { tts_first_frame_time?: number; tts_total_time?: number; wav_to_tts_total_time?: number; + stt?: string; + tts?: string; + chat_model?: string; } const metrics = ref({});