diff --git a/app/server/engine.js b/app/server/engine.js index 408d62b..a448649 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -92,25 +92,27 @@ function recordModelUsage(sessionId, modelId, usage) { ).run(sessionId, modelId, pt, ct, tt, now()); } -// 每模型 token 用量统计:今日(本地时区自然日起)+ 累计。 -// 返回 { [model_id]: { today_tokens, total_tokens } },配置内的模型保证有零值占位。 +// 每模型 token 用量统计:今日(本地时区自然日起)+ 累计,输入/输出分开。 +// 返回 { [model_id]: { today_prompt, today_completion, total_prompt, total_completion } }, +// 配置内的模型保证有零值占位。 function modelUsageStats() { const d = new Date(); const dayStart = new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime(); const stats = {}; const slot = function (id) { - if (!stats[id]) stats[id] = { today_tokens: 0, total_tokens: 0 }; + if (!stats[id]) stats[id] = { today_prompt: 0, today_completion: 0, total_prompt: 0, total_completion: 0 }; return stats[id]; }; for (const m of cfg.models) slot(m.id); - const today = db.prepare( - 'SELECT model_id, SUM(total_tokens) AS n FROM model_usage WHERE created_at >= ? GROUP BY model_id' - ).all(dayStart); - for (const r of today) slot(r.model_id).today_tokens = r.n || 0; - const total = db.prepare( - 'SELECT model_id, SUM(total_tokens) AS n FROM model_usage GROUP BY model_id' - ).all(); - for (const r of total) slot(r.model_id).total_tokens = r.n || 0; + const sumSql = 'SELECT model_id, SUM(prompt_tokens) AS p, SUM(completion_tokens) AS c FROM model_usage'; + for (const r of db.prepare(sumSql + ' WHERE created_at >= ? GROUP BY model_id').all(dayStart)) { + slot(r.model_id).today_prompt = r.p || 0; + slot(r.model_id).today_completion = r.c || 0; + } + for (const r of db.prepare(sumSql + ' GROUP BY model_id').all()) { + slot(r.model_id).total_prompt = r.p || 0; + slot(r.model_id).total_completion = r.c || 0; + } return stats; } diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index e91703f..20ed93a 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -78,12 +78,11 @@ body { .search-cancel { background: none; border: none; color: #2a5299; font-size: 14px; padding: 6px 4px; cursor: pointer; flex: none; } .search-tip { color: #8891a5; font-size: 12px; padding: 2px 4px 8px; } .load-more { - display: block; margin: 4px auto 14px; - padding: 8px 26px; background: #fff; color: #2a5299; - border: 1px solid #d5deee; border-radius: 18px; - font-size: 13px; cursor: pointer; box-shadow: 0 1px 3px rgba(30,40,90,0.06); + width: 100%; background: #f2f3f7; color: #445; + border: 1px solid #dde; border-radius: 10px; + padding: 10px; font-size: 14px; cursor: pointer; margin-bottom: 10px; } -.load-more:active { background: #eef3fc; } +.load-more:active { background: #e8eaf0; } .load-more:disabled { opacity: 0.5; cursor: default; } /* ---- 任务状态栏 ---- */ diff --git a/app/server/public/index.html b/app/server/public/index.html index 3fa78ac..cf332f1 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -284,10 +284,10 @@
- - - - - + + + + +