feat: cron jobs — daily summary, speaker clustering, clip purge

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 10:49:24 -05:00
parent 59014f6fe7
commit 8a3e7e2b53
5 changed files with 249 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
import sqlite3
import httpx
from app.shared.config import Settings
def generate_daily_summary(date: str, settings: Settings, db: sqlite3.Connection) -> None:
rows = db.execute("""
SELECT u.start_time, u.transcript, r.name as room_name, s.name as speaker_name
FROM utterances u
JOIN rooms r ON u.room_id = r.id
LEFT JOIN speakers s ON u.speaker_id = s.id
WHERE date(u.start_time) = ?
ORDER BY u.start_time ASC
""", (date,)).fetchall()
if not rows:
return
lines = [
f"[{r['room_name']} {r['start_time']}] {r['speaker_name'] or 'Unknown'}: {r['transcript']}"
for r in rows
]
context = "\n".join(lines)
prompt = (
f"Summarize the following household conversations from {date} in 2-4 sentences. "
f"Focus on key decisions, activities, and topics discussed. Do not transcribe verbatim.\n\n"
f"{context}"
)
resp = httpx.post(
f"{settings.ollama_url}/api/chat",
json={
"model": settings.ollama_model,
"messages": [{"role": "user", "content": prompt}],
"stream": False,
},
timeout=120.0,
)
resp.raise_for_status()
summary = resp.json()["message"]["content"]
db.execute(
"INSERT INTO daily_summaries (date, summary_text) VALUES (?,?) "
"ON CONFLICT(date) DO UPDATE SET summary_text=?, generated_at=CURRENT_TIMESTAMP",
(date, summary, summary),
)
db.commit()