Fix: KI health_summary Kontextfenster (max 5 Einträge), Cloud-Priority ohne ANTHROPIC_KEY-Check, local-Fallback wrapped (SW by-v798)
This commit is contained in:
parent
d91cc8da26
commit
c1bcc029ea
1 changed files with 6 additions and 4 deletions
|
|
@ -84,7 +84,7 @@ def _track_usage(user_id: int | None, source: str) -> None:
|
||||||
|
|
||||||
def _is_cloud_priority_user(user_id: int | None) -> bool:
|
def _is_cloud_priority_user(user_id: int | None) -> bool:
|
||||||
"""Privilegierte Rollen (Admin, Moderator, Züchter, Manager) nutzen Cloud-KI primär."""
|
"""Privilegierte Rollen (Admin, Moderator, Züchter, Manager) nutzen Cloud-KI primär."""
|
||||||
if not user_id or not ANTHROPIC_KEY:
|
if not user_id:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
from database import db
|
from database import db
|
||||||
|
|
@ -173,8 +173,10 @@ async def complete(
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Cloud-KI nicht erreichbar für privilegierten User, Fallback lokal: {e}")
|
logger.warning(f"Cloud-KI nicht erreichbar für privilegierten User, Fallback lokal: {e}")
|
||||||
# Fallback auf lokales Modell
|
try:
|
||||||
text = await _local_complete(prompt, system, max_tokens, json_mode)
|
text = await _local_complete(prompt, system, max_tokens, json_mode)
|
||||||
|
except Exception as local_e:
|
||||||
|
raise KIUnavailableError("KI-Modell nicht erreichbar.") from local_e
|
||||||
_track_usage(user_id, "local")
|
_track_usage(user_id, "local")
|
||||||
if return_model:
|
if return_model:
|
||||||
return (text, LOCAL_MODEL)
|
return (text, LOCAL_MODEL)
|
||||||
|
|
@ -399,7 +401,7 @@ async def health_summary(health_data: list, dog_info: dict,
|
||||||
if not subset:
|
if not subset:
|
||||||
return " (keine Einträge)"
|
return " (keine Einträge)"
|
||||||
lines = []
|
lines = []
|
||||||
for e in subset[:10]: # maximal 10 pro Typ
|
for e in subset[:5]: # maximal 5 pro Typ — Kontextfenster schonen
|
||||||
line = f" - {e.get('datum', '?')}: {e.get('bezeichnung', '?')}"
|
line = f" - {e.get('datum', '?')}: {e.get('bezeichnung', '?')}"
|
||||||
if e.get("naechstes"):
|
if e.get("naechstes"):
|
||||||
line += f" (nächste Fälligkeit: {e['naechstes']})"
|
line += f" (nächste Fälligkeit: {e['naechstes']})"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue