8a3e7e2b53
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
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()
|