feat: alerta de coste — aviso si sesión supera COST_ALERT_THRESHOLD
Build & Deploy ResearchOwl / build-and-push (push) Successful in 5s

This commit is contained in:
ChemaVX
2026-05-06 07:23:11 +00:00
parent 82e614e285
commit 279475a175
2 changed files with 18 additions and 0 deletions
+15
View File
@@ -112,8 +112,23 @@ async def run_scheduled_research(bot, chat_id: int, topic: str,
f"🔍 Investigación completada — analizando novedades…"
)
else:
async def get_session_cost(session_id: int) -> float:
try:
stats = await db.get_usage_stats(session_id)
return sum(s.get("total_cost", 0) for s in stats)
except Exception:
return 0.0
session_cost = await get_session_cost(session_id)
cost_warning = ""
if session_cost > settings.cost_alert_threshold:
cost_warning = (
f"\n⚠️ Coste: ${session_cost:.4f}"
f" (umbral: ${settings.cost_alert_threshold:.2f})"
)
await reporter.done(
f"✅ Listo — `{scraped}` fuentes · `{chunk_count}` chunks · usa /generate <tipo>"
f"{cost_warning}"
)
else:
await reporter.done(