mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-07-20 14:40:35 +00:00
04066b4b43
Surfaces prompt-cache hit rate on the Insights page so cache-efficiency (a key cost-optimisation signal) is visible at a glance. Backend (api/routes.py, _handle_insights): - Aggregate cache_read_tokens per model and per day, plus a total. - Graceful fallback for older agent state.db schemas lacking the cache_read_tokens column (COALESCE + OperationalError second query). - New response fields: total_cache_read_tokens, total_cache_hit_percent, per-model cache_read_tokens + cache_hit_percent, per-day cache_read_tokens. Frontend: - Models table gains a Cache column (panels.js + style.css 6-col grid). - Daily bar tooltip includes the bounded cache hit rate. - New i18n keys insights_model_cache / insights_cache_hit in all 13 locales. Correctness fix (maintainer-flagged on #3912): the original computed hit-rate as cache_read / input_tokens (reads-over-misses), which EXCEEDS 100% on cache-heavy sessions. This uses the FULL prompt total as the denominator -- cache_read / (input_tokens + cache_read) -- via the shared api.usage.prompt_cache_hit_percent helper, so it is bounded 0-100% and means "% of the prompt served from cache". Returns None (rendered as a muted dash) when there are no cache reads. Tests (tests/test_insights.py): - Updated existing assertions for the new response shape. - Added a non-vacuous <=100% boundary test: a cache-heavy case (cache_read=9900, input=100) where the OLD formula reports 9900% but the bounded denominator yields 99%. Verified the test FAILS under the old formula and PASSES under the fix. Salvage note: PR #3912's diff was ~99 releases stale (mostly re-derived old code, illusory +5405). This ports ONLY the real ~190-line feature fresh onto current master. Closes #3911 Co-authored-by: TomBanksAU <TomBanksAU@users.noreply.github.com>