ai: перевод абузных постов и саммари подборки (bot buttons, /sum, /tr, /api/summary, cache)
This commit is contained in:
@@ -142,6 +142,20 @@ def _run_check(job_id, names=None, category=None):
|
||||
_job(job_id, state="done", done=total, alive=alive, dead=dead, current="")
|
||||
|
||||
|
||||
def _ai_summary(tag=None, limit=14):
|
||||
"""ИИ-саммари абузов для панели. None если ИИ не настроен."""
|
||||
from . import abuse as abuse_mod, ai as ai_mod
|
||||
if not ai_mod.available():
|
||||
return {"ok": False, "error": "ai_not_configured"}
|
||||
d = abuse_mod.scan(limit=limit, tag=tag, window=6000)
|
||||
items = [i for i in d.get("items", []) if [t for t in (i.get("tags") or []) if t != "keys"]]
|
||||
if not items:
|
||||
return {"ok": True, "summary": "", "n": 0}
|
||||
posts = ["%s — %s" % (i.get("title") or "", i.get("source") or "") for i in items]
|
||||
txt = ai_mod.summarize(posts, tag=tag)
|
||||
return {"ok": bool(txt), "summary": txt or "", "n": len(items)}
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
server_version = "omni/1.2"
|
||||
|
||||
@@ -226,6 +240,19 @@ class Handler(BaseHTTPRequestHandler):
|
||||
lim = 40
|
||||
return self._json(_ab.scan(limit=lim, tag=tag))
|
||||
|
||||
if path == "/api/summary":
|
||||
tag = (q.get("tag") or [""])[0].strip() or None
|
||||
if tag in ("all", "все"):
|
||||
tag = None
|
||||
try:
|
||||
lim = max(1, min(40, int((q.get("limit") or ["14"])[0])))
|
||||
except ValueError:
|
||||
lim = 14
|
||||
try:
|
||||
return self._json(_ai_summary(tag=tag, limit=lim))
|
||||
except Exception as e:
|
||||
return self._json({"ok": False, "error": str(e)[:200]})
|
||||
|
||||
if path == "/api/sources":
|
||||
cat = (q.get("category") or [None])[0]
|
||||
query = (q.get("q") or [""])[0].strip().lower()
|
||||
|
||||
Reference in New Issue
Block a user