refactor: remove KI-Orakel from history page and backend
Drop oracle UI, API endpoint, scheduled generation, and related docs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -21,12 +21,6 @@ MOTIVATION_SYSTEM = (
|
||||
"Genau ein Satz auf Deutsch, max 25 Wörter. Keine Anführungszeichen um den Spruch."
|
||||
)
|
||||
|
||||
ORACLE_SYSTEM = (
|
||||
"Du bist das tägliche KI-Orakel einer ADHS-Medikamenten-App. "
|
||||
"Passiv-aggressiv, trocken, max 4 Sätze auf Deutsch. Keine medizinischen Ratschläge."
|
||||
)
|
||||
|
||||
|
||||
async def _get_cache(db: aiosqlite.Connection, key: str) -> str | None:
|
||||
cur = await db.execute("SELECT content FROM ai_cache WHERE key = ?", (key,))
|
||||
row = await cur.fetchone()
|
||||
@@ -93,18 +87,6 @@ def _motivation_key(day: str) -> str:
|
||||
return f"motivation:v2:{day}"
|
||||
|
||||
|
||||
def _oracle_key(day: str) -> str:
|
||||
return f"oracle:v3:{day}"
|
||||
|
||||
|
||||
async def _cached_oracle(db: aiosqlite.Connection, day: str) -> str | None:
|
||||
cached = await _get_cache(db, _oracle_key(day))
|
||||
if cached:
|
||||
return cached
|
||||
week = datetime.strptime(day, "%Y-%m-%d").strftime("%Y-W%W")
|
||||
return await _get_cache(db, f"oracle:v2:{week}")
|
||||
|
||||
|
||||
async def _cached_motivation(db: aiosqlite.Connection, day: str) -> str | None:
|
||||
cached = await _get_cache(db, _motivation_key(day))
|
||||
if cached:
|
||||
@@ -154,68 +136,3 @@ async def get_daily_motivation(db: aiosqlite.Connection, tz: ZoneInfo) -> dict[s
|
||||
|
||||
async def get_roast_of_the_day(db: aiosqlite.Connection, tz: ZoneInfo) -> dict[str, Any]:
|
||||
return await get_daily_motivation(db, tz)
|
||||
|
||||
|
||||
async def generate_oracle(
|
||||
db: aiosqlite.Connection,
|
||||
tz: ZoneInfo,
|
||||
day: str | None = None,
|
||||
*,
|
||||
force: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
day = day or datetime.now(tz).strftime("%Y-%m-%d")
|
||||
key = _oracle_key(day)
|
||||
if not force:
|
||||
cached = await _cached_oracle(db, day)
|
||||
if cached:
|
||||
return {"text": cached, "source": "cache", "day": day}
|
||||
|
||||
stats = await compute_stats(db)
|
||||
days_active = stats["days_active"]
|
||||
window = stats["compliance_window_days"]
|
||||
young_app = days_active < 90
|
||||
context = (
|
||||
f"App aktiv seit {days_active} Tag(en), erste Einnahme am {stats['first_day']}. "
|
||||
if young_app
|
||||
else ""
|
||||
)
|
||||
caveat = (
|
||||
"Die App ist noch jung — lange Streaks oder 90-Tage-Compliance sind noch nicht realistisch erreichbar. "
|
||||
"Bewerte nur die verfügbaren Daten, sei fair aber sarkastisch. "
|
||||
if young_app
|
||||
else ""
|
||||
)
|
||||
prompt = (
|
||||
f"Täglicher Orakel-Report für heute. {context}{caveat}"
|
||||
f"Streak: {stats['streak']} Tage. "
|
||||
f"Compliance über {window} Tag(e): {stats['compliance_percent']}%. "
|
||||
f"Genommen gesamt: {stats['total_taken']}."
|
||||
)
|
||||
text = await _call_openrouter(prompt, system=ORACLE_SYSTEM)
|
||||
if not text:
|
||||
if young_app:
|
||||
text = (
|
||||
f"Tag {days_active} deiner Medis-Karriere. "
|
||||
f"Streak: {stats['streak']}. Compliance ({window} Tage): {stats['compliance_percent']}%. "
|
||||
"Das Orakel ist beeindruckt — oder gelangweilt. Grenzwertig."
|
||||
)
|
||||
else:
|
||||
text = pick("streak", streak=stats["streak"]) + f" Compliance: {stats['compliance_percent']}%."
|
||||
source = "fallback"
|
||||
else:
|
||||
source = "ai"
|
||||
await _set_cache(db, key, text)
|
||||
logger.info("Generated daily oracle for %s (%s)", day, source)
|
||||
return {"text": text, "source": source, "day": day}
|
||||
|
||||
|
||||
async def get_oracle(db: aiosqlite.Connection, tz: ZoneInfo) -> dict[str, Any]:
|
||||
day = datetime.now(tz).strftime("%Y-%m-%d")
|
||||
cached = await _cached_oracle(db, day)
|
||||
if cached:
|
||||
return {"text": cached, "source": "cache", "day": day}
|
||||
return {
|
||||
"text": "Das Orakel bereitet sich vor. Schau später nochmal rein.",
|
||||
"source": "pending",
|
||||
"day": day,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user