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:
Frank Schwenk
2026-06-17 08:32:28 +02:00
parent 648e62d2b4
commit c59c3069c4
10 changed files with 12 additions and 155 deletions
-83
View File
@@ -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,
}
+1 -24
View File
@@ -11,7 +11,7 @@ from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi.responses import FileResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from server.ai import generate_daily_motivation, generate_oracle, get_oracle, get_roast_of_the_day
from server.ai import generate_daily_motivation, get_roast_of_the_day
from server.auth import create_token, require_auth, verify_pin
from server.config_loader import load_meds_config, slot_to_dict, today_str
from server.db import ensure_schema, get_db, new_id, utc_now_iso
@@ -51,17 +51,6 @@ async def _ensure_today_motivation() -> None:
await db.close()
async def _ensure_today_oracle() -> None:
config = load_meds_config()
db = await get_db()
try:
await generate_oracle(db, config.timezone)
except Exception:
logger.exception("Startup oracle generation failed")
finally:
await db.close()
@asynccontextmanager
async def lifespan(app: FastAPI):
db = await get_db()
@@ -69,7 +58,6 @@ async def lifespan(app: FastAPI):
await db.close()
start_scheduler()
asyncio.create_task(_ensure_today_motivation())
asyncio.create_task(_ensure_today_oracle())
yield
@@ -219,17 +207,6 @@ async def get_roast(_: dict = Depends(require_auth)) -> JSONResponse:
return JSONResponse(data, headers=NO_STORE)
@app.get("/api/oracle")
async def get_oracle_route(_: dict = Depends(require_auth)) -> JSONResponse:
config = load_meds_config()
db = await get_db()
try:
data = await get_oracle(db, config.timezone)
finally:
await db.close()
return JSONResponse(data, headers=NO_STORE)
# Static files — must be after API routes
PUBLIC = pathlib.Path(settings.public_dir)
if PUBLIC.exists():
+1 -19
View File
@@ -9,7 +9,7 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.cron import CronTrigger
from apscheduler.triggers.date import DateTrigger
from server.ai import generate_daily_motivation, generate_oracle
from server.ai import generate_daily_motivation
from server.config_loader import load_meds_config, slot_to_dict, today_str
from server.db import get_db, utc_now_iso
from server.messages import pick
@@ -54,17 +54,6 @@ async def _generate_daily_motivation() -> None:
await db.close()
async def _generate_daily_oracle() -> None:
config = load_meds_config()
db = await get_db()
try:
await generate_oracle(db, config.timezone)
except Exception:
logger.exception("Daily oracle generation failed")
finally:
await db.close()
async def _evening_check() -> None:
logger.info("Evening check triggered")
db = await get_db()
@@ -158,13 +147,6 @@ def start_scheduler() -> None:
replace_existing=True,
)
scheduler.add_job(
_generate_daily_oracle,
trigger=CronTrigger(hour=3, minute=5, timezone=tz),
id="daily-oracle",
replace_existing=True,
)
if not scheduler.running:
scheduler.start()
logger.info("Scheduler started for timezone %s", tz)