Admin: KI-Anfragen nach Quelle aufschlüsseln (cloud/local/luna)
- ki_daily_calls: PK auf (user_id, date, source) erweitert + Index; Migration baut Tabelle mit neuer Struktur neu auf, behält Altdaten als 'cloud' - ki.py: return_source=True-Parameter gibt (text, 'cloud'|'local') zurück - training.py: ki_source aus ki.complete() auslesen, in DB speichern - social.py: _ki_complete_tracked() zählt Luna-Anfragen mit source='luna'; alle Content-Endpoints (generate, evaluate, training-tip, breed-of-day, pflege-tipp) nutzen tracking-Variante - admin.py: Stats aufgeteilt in ki_cloud/ki_local/ki_luna je heute+Monat - admin.js: KI-Karte zeigt 9 Zeilen mit ☁️ Claude / 🖥️ LM Studio / 🌙 Luna - SW by-v359, APP_VER 344
This commit is contained in:
parent
74b6c03bb3
commit
8d5c7a19b1
6 changed files with 136 additions and 33 deletions
|
|
@ -777,11 +777,10 @@ async def ki_feedback(body: KiFeedbackRequest, user=Depends(get_current_user)):
|
|||
).fetchone()[0]
|
||||
|
||||
if age_hours < 6 and new_since == 0:
|
||||
daily_used = conn.execute(
|
||||
"SELECT COALESCE(count,0) FROM ki_daily_calls WHERE user_id=? AND date=?",
|
||||
used = conn.execute(
|
||||
"SELECT COALESCE(SUM(count),0) FROM ki_daily_calls WHERE user_id=? AND date=?",
|
||||
(uid, today)
|
||||
).fetchone()
|
||||
used = daily_used[0] if daily_used else 0
|
||||
).fetchone()[0]
|
||||
return {"feedback": cache_row["feedback"], "cached": True,
|
||||
"daily_used": used, "daily_limit": KI_DAILY_LIMIT}
|
||||
|
||||
|
|
@ -791,14 +790,14 @@ async def ki_feedback(body: KiFeedbackRequest, user=Depends(get_current_user)):
|
|||
user_id INTEGER NOT NULL,
|
||||
date TEXT NOT NULL,
|
||||
count INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (user_id, date)
|
||||
source TEXT NOT NULL DEFAULT 'cloud',
|
||||
PRIMARY KEY (user_id, date, source)
|
||||
)
|
||||
""")
|
||||
row = conn.execute(
|
||||
"SELECT count FROM ki_daily_calls WHERE user_id=? AND date=?",
|
||||
daily_used = conn.execute(
|
||||
"SELECT COALESCE(SUM(count),0) FROM ki_daily_calls WHERE user_id=? AND date=?",
|
||||
(uid, today)
|
||||
).fetchone()
|
||||
daily_used = row[0] if row else 0
|
||||
).fetchone()[0]
|
||||
|
||||
if daily_used >= KI_DAILY_LIMIT:
|
||||
raise HTTPException(429, f"Tages-Limit erreicht ({KI_DAILY_LIMIT} Anfragen/Tag). Morgen wieder verfügbar.")
|
||||
|
|
@ -867,12 +866,13 @@ async def ki_feedback(body: KiFeedbackRequest, user=Depends(get_current_user)):
|
|||
)
|
||||
|
||||
try:
|
||||
feedback_text = await ki.complete(
|
||||
feedback_text, ki_source = await ki.complete(
|
||||
prompt,
|
||||
system=system,
|
||||
max_tokens=400,
|
||||
requires_premium=False,
|
||||
user_is_premium=user.get("is_premium", False),
|
||||
return_source=True,
|
||||
)
|
||||
except (ki.KIUnavailableError, ki.KIPremiumRequired) as e:
|
||||
raise HTTPException(503, str(e))
|
||||
|
|
@ -889,11 +889,11 @@ async def ki_feedback(body: KiFeedbackRequest, user=Depends(get_current_user)):
|
|||
(body.dog_id, feedback_text)
|
||||
)
|
||||
conn.execute("""
|
||||
INSERT INTO ki_daily_calls (user_id, date, count) VALUES (?, ?, 1)
|
||||
ON CONFLICT(user_id, date) DO UPDATE SET count = count + 1
|
||||
""", (uid, today))
|
||||
INSERT INTO ki_daily_calls (user_id, date, count, source) VALUES (?, ?, 1, ?)
|
||||
ON CONFLICT(user_id, date, source) DO UPDATE SET count = count + 1
|
||||
""", (uid, today, ki_source))
|
||||
new_count = conn.execute(
|
||||
"SELECT count FROM ki_daily_calls WHERE user_id=? AND date=?",
|
||||
"SELECT COALESCE(SUM(count),0) FROM ki_daily_calls WHERE user_id=? AND date=?",
|
||||
(uid, today)
|
||||
).fetchone()[0]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue