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:
|
||||
"""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
|
||||
try:
|
||||
from database import db
|
||||
|
|
@ -173,8 +173,10 @@ async def complete(
|
|||
raise
|
||||
except Exception as e:
|
||||
logger.warning(f"Cloud-KI nicht erreichbar für privilegierten User, Fallback lokal: {e}")
|
||||
# Fallback auf lokales Modell
|
||||
text = await _local_complete(prompt, system, max_tokens, json_mode)
|
||||
try:
|
||||
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")
|
||||
if return_model:
|
||||
return (text, LOCAL_MODEL)
|
||||
|
|
@ -399,7 +401,7 @@ async def health_summary(health_data: list, dog_info: dict,
|
|||
if not subset:
|
||||
return " (keine Einträge)"
|
||||
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', '?')}"
|
||||
if e.get("naechstes"):
|
||||
line += f" (nächste Fälligkeit: {e['naechstes']})"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue