From dc5648fbb845d892078aafa5eb8af26f2c486689 Mon Sep 17 00:00:00 2001 From: wsb1224 Date: Tue, 9 Jun 2026 21:01:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20admin=20=E5=88=86=E7=B1=BB?= =?UTF-8?q?=20token=20=E6=9F=A5=E8=AF=A2=E7=9A=84=20label=20=E8=BF=90?= =?UTF-8?q?=E7=AE=97=E7=AC=A6=E4=BC=98=E5=85=88=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit .label("tokens") 只绑到了 sum(output) 而非 input+output 整体, 导致后台显示的分类 token 值偏低。 Co-Authored-By: Claude Opus 4.7 (1M context) --- backend/api/admin_router.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/api/admin_router.py b/backend/api/admin_router.py index 006b4f8..80022c8 100644 --- a/backend/api/admin_router.py +++ b/backend/api/admin_router.py @@ -87,8 +87,8 @@ async def list_users( mode_tokens_result = await db.execute( select( ChatLog.mode, - func.coalesce(func.sum(ChatLog.tokens_input), 0) + - func.coalesce(func.sum(ChatLog.tokens_output), 0).label("tokens") + (func.coalesce(func.sum(ChatLog.tokens_input), 0) + + func.coalesce(func.sum(ChatLog.tokens_output), 0)).label("tokens") ).where(ChatLog.user_id == user.id) .group_by(ChatLog.mode) ) @@ -147,8 +147,8 @@ async def get_user_detail( mode_tokens_result = await db.execute( select( ChatLog.mode, - func.coalesce(func.sum(ChatLog.tokens_input), 0) + - func.coalesce(func.sum(ChatLog.tokens_output), 0).label("tokens") + (func.coalesce(func.sum(ChatLog.tokens_input), 0) + + func.coalesce(func.sum(ChatLog.tokens_output), 0)).label("tokens") ).where(ChatLog.user_id == user_id) .group_by(ChatLog.mode) )