Implement prompt caching, speculative decoding config, parallel slots, and dynamic pricing metrics

This commit is contained in:
Hitonabi
2026-06-26 14:00:32 +02:00
parent 2c60caf790
commit 35dcc69ba5
12 changed files with 216 additions and 35 deletions
+43 -3
View File
@@ -91,6 +91,7 @@ def self_update() -> dict:
from services.token_stats import get_stats
from services.llamaswap import list_models
@router.get("/system/token-stats")
def token_stats() -> dict:
@@ -99,9 +100,48 @@ def token_stats() -> dict:
c = stats.get("completion_tokens", 0)
total = p + c
# Juni 2026 API-Preise (deutlich gestiegen):
# Premium-Modelle (Claude 4 / GPT-5): 15,00 $ / 1M Input-Tokens und 75,00 $ / 1M Output-Tokens
saved_usd = (p * 15.0 + c * 75.0) / 1_000_000.0
# Map model IDs and aliases to their respective roles for pricing resolution
role_map = {}
try:
for m in list_models():
role_map[m["name"].lower()] = m.get("role")
for alias in m.get("aliases", []):
role_map[alias.lower()] = m.get("role")
except Exception:
pass
# Dynamic pricing tiers based on model class in June 2026
PRICING = {
"heavy": (15.0, 75.0),
"coder": (3.0, 15.0),
"hermes": (1.0, 5.0),
"fast": (0.15, 0.60),
"scout": (0.15, 0.60),
"vision": (0.15, 0.60),
"reasoning": (0.15, 0.60),
}
modeled_p = 0
modeled_c = 0
saved_usd = 0.0
models_data = stats.get("models") or {}
for m_name, m_tokens in models_data.items():
mp = m_tokens.get("prompt", 0)
mc = m_tokens.get("completion", 0)
modeled_p += mp
modeled_c += mc
role = role_map.get(m_name, m_name)
rate_in, rate_out = PRICING.get(role, (0.15, 0.60))
saved_usd += (mp * rate_in + mc * rate_out) / 1_000_000.0
# Baseline/legacy tokens calculated at premium rates ($15.00 / $75.00)
# to preserve historical savings value prior to model-specific logging
baseline_p = max(0, p - modeled_p)
baseline_c = max(0, c - modeled_c)
saved_usd += (baseline_p * 15.0 + baseline_c * 75.0) / 1_000_000.0
saved_eur = saved_usd * 0.92 # 1 USD = 0.92 EUR
return {