feat(costs): $-Tagesbudget pro Nutzer (Stufe 3)
cost_daily_limit_usd (Pref > global; 0 = unbegrenzt) in quota.py (cost_within_budget, cost_limit). ws.py-Gate: Web-Such- ODER Kostenbudget aufgebraucht -> Web-Suche fuer den Turn aus + freundlicher Hinweis. Admin: Schema-Feld + list_users + UI-Eingabe ($/Tag) + globales Live-Setting. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
d87f0ce424
commit
66d6708f59
7 changed files with 57 additions and 5 deletions
22
app/quota.py
22
app/quota.py
|
|
@ -68,3 +68,25 @@ def record_web_search(user, store, n: int = 1) -> None:
|
|||
"""Zaehlt n tatsaechlich ausgefuehrte Web-Suchen fuer den Nutzer."""
|
||||
if n and n > 0 and user is not None:
|
||||
store.add_web_search_usage(user.id, n)
|
||||
|
||||
|
||||
def cost_limit(user, cfg=None) -> float:
|
||||
"""Max. Kosten/Tag (USD) fuer diesen Nutzer (Pref > global; 0 = unbegrenzt)."""
|
||||
if cfg is None:
|
||||
from app.runtime_config import runtime_settings
|
||||
cfg = runtime_settings
|
||||
pref = user.prefs.get("cost_daily_limit_usd") if user and user.prefs else None
|
||||
if pref is not None:
|
||||
try:
|
||||
return float(pref)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return cfg.cost_daily_limit_usd
|
||||
|
||||
|
||||
def cost_within_budget(user, store, cfg=None) -> bool:
|
||||
"""Darf der Nutzer heute noch Kosten verursachen? (Limit 0 = unbegrenzt)."""
|
||||
limit = cost_limit(user, cfg)
|
||||
if not limit or limit <= 0:
|
||||
return True
|
||||
return store.cost_for_day(user.id) < limit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue