[STANDARD] Ночной пересчёт соответствия 2026-11-26
This commit is contained in:
1 parent
70908784ed
commit
fec4a2a528
14 files changed
+578
-16
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import json
|
||||
import re
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
|
||||
import psycopg2
|
||||
from urllib.parse import quote
|
||||
|
||||
sys.path.insert(0, "/opt/work-hub/research")
|
||||
sys.path.insert(0, "/opt/hub-core")
|
||||
@@ -60,7 +62,7 @@ while True:
|
||||
cur.execute("""
|
||||
update prism.tasks t set status='running', worker='229-7b', started_at=now()
|
||||
where t.id = (
|
||||
select id from prism.tasks where status='pending' and kind <> 'note_audit' order by id limit 1 for update skip locked
|
||||
select id from prism.tasks where status='pending' and kind not in ('note_audit','practice_extract','requirement_extract') order by id limit 1 for update skip locked
|
||||
) returning t.id, t.kind, t.source_id, t.model_id
|
||||
""")
|
||||
row = cur.fetchone()
|
||||
@@ -82,25 +84,35 @@ while True:
|
||||
note_kind = "scenario" if kind == "model_scenario" else ("review" if kind == "model_review" else "positioning")
|
||||
prompt = MODEL_PROMPT % (name, vendor, role or "unknown", domain or "unknown", specs[:800])
|
||||
r = L.ask(prompt, max_tokens=250, temperature=0.2,
|
||||
chain=[{"name": "qwen2.5:7b", "kind": "ollama", "timeout": 300}])
|
||||
chain=[{"name": "qwen2.5:3b-32k", "kind": "ollama", "timeout": 300}])
|
||||
text = r["text"].strip()[:2000]
|
||||
cur.execute("""insert into prism.model_notes(model_id,kind,text,model)
|
||||
values (%s,%s,%s,'qwen2.5:7b')""", (mid, note_kind, text))
|
||||
cur.execute("""insert into prism.runs(model_id,kind,status,worker,model,stats,started_at,finished_at)
|
||||
values (%s,'model_note7b','ok','229',%s,%s,now(),now())""",
|
||||
(mid, "qwen2.5:7b", json.dumps({"task_id": task_id, "chars": len(text)})))
|
||||
(mid, "qwen2.5:3b-32k", json.dumps({"task_id": task_id, "chars": len(text)})))
|
||||
else:
|
||||
cur.execute("select url,title from prism.sources where id=%s", (sid,))
|
||||
s = cur.fetchone()
|
||||
if not s:
|
||||
raise RuntimeError("source missing")
|
||||
url, title = s
|
||||
txt = R.fetch(url)
|
||||
if any(ord(c) > 127 or c == " " for c in url):
|
||||
url = quote(url, safe=":/?&=#%")
|
||||
def _alarm(signum, frame):
|
||||
raise TimeoutError("source fetch timeout")
|
||||
signal.signal(signal.SIGALRM, _alarm)
|
||||
signal.alarm(60)
|
||||
try:
|
||||
txt = R.fetch(url)
|
||||
finally:
|
||||
signal.alarm(0)
|
||||
if len(txt) < 200:
|
||||
raise RuntimeError("empty text %s" % len(txt))
|
||||
chunk = R.pick_excerpt(txt, 3500)
|
||||
r = L.ask(SUPPORT_PROMPT + chunk, max_tokens=450, temperature=0.0,
|
||||
chain=[{"name": "qwen2.5:7b", "kind": "ollama", "timeout": 300}])
|
||||
conn.commit()
|
||||
r = L.ask(SUPPORT_PROMPT + chunk, max_tokens=3000, temperature=0.0,
|
||||
chain=[{"name": "qwen2.5:3b-32k", "kind": "ollama", "timeout": 300}])
|
||||
d = parse_loose(r["text"])
|
||||
facts = d.get("facts") or []
|
||||
for f in facts:
|
||||
@@ -118,7 +130,7 @@ while True:
|
||||
(mid, sid, key, vtext, f.get("unit"), f.get("quote")))
|
||||
cur.execute("""insert into prism.runs(model_id,kind,status,worker,model,stats,started_at,finished_at)
|
||||
values (%s,'enrich_support7b','ok','229',%s,%s,now(),now())""",
|
||||
(mid, "qwen2.5:7b", json.dumps({"source_id": sid, "facts": len(facts)})))
|
||||
(mid, "qwen2.5:3b-32k", json.dumps({"source_id": sid, "facts": len(facts)})))
|
||||
cur.execute("update prism.tasks set status='done', finished_at=now() where id=%s", (task_id,))
|
||||
print("done", task_id, kind, flush=True)
|
||||
except Exception as e:
|
||||
@@ -126,7 +138,7 @@ while True:
|
||||
(str(e)[:300], task_id))
|
||||
cur.execute("""insert into prism.runs(model_id,kind,status,worker,model,error,started_at,finished_at)
|
||||
values (%s,'worker7b','error','229',%s,%s,now(),now())""",
|
||||
(mid, "qwen2.5:7b", str(e)[:300]))
|
||||
(mid, "qwen2.5:3b-32k", str(e)[:300]))
|
||||
print("error", task_id, kind, str(e)[:150], flush=True)
|
||||
conn.commit()
|
||||
time.sleep(1)
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
import psycopg2
|
||||
|
||||
sys.path.insert(0, "/opt/hub-core")
|
||||
import llm_fallback as L
|
||||
import rag
|
||||
|
||||
conn = psycopg2.connect(rag.DSN)
|
||||
cur = conn.cursor()
|
||||
cur.execute("update prism.tasks set status='pending', started_at=null, worker=null where kind='note_audit' and status='running'")
|
||||
conn.commit()
|
||||
print("note audit worker start", flush=True)
|
||||
while True:
|
||||
cur.execute("""
|
||||
update prism.tasks t set status='running', worker='229-7b', started_at=now()
|
||||
where t.id = (
|
||||
select id from prism.tasks where kind='note_audit' and status='pending'
|
||||
order by id limit 1 for update skip locked
|
||||
) returning t.id, t.model_id
|
||||
""")
|
||||
row = cur.fetchone()
|
||||
conn.commit()
|
||||
if not row:
|
||||
print("no note_audit tasks", flush=True)
|
||||
break
|
||||
task_id, mid = row
|
||||
try:
|
||||
cur.execute("select vendor,name from prism.models where id=%s", (mid,))
|
||||
m = cur.fetchone()
|
||||
vendor, name = m
|
||||
cur.execute("""select string_agg(kind || ': ' || text, E'\n' order by kind)
|
||||
from prism.model_notes where model_id=%s""", (mid,))
|
||||
notes = (cur.fetchone() or [""])[0] or ""
|
||||
cur.execute("""select string_agg(key || '=' || coalesce(value_text,''), ', ' order by key)
|
||||
from (select distinct key,value_text from prism.specs where model_id=%s limit 25) q""", (mid,))
|
||||
specs = (cur.fetchone() or [""])[0] or ""
|
||||
prompt = f"""Проверь, подтверждаются ли технические заметки фактами из спецификаций.
|
||||
Не придумывай. Верни только JSON:
|
||||
{{"ok":true/false,"issues":["..."]}}
|
||||
Модель: {name}
|
||||
Вендор: {vendor}
|
||||
Заметки:
|
||||
{notes[:2500]}
|
||||
Спецификации:
|
||||
{specs[:1500]}
|
||||
"""
|
||||
r = L.ask(prompt, max_tokens=350, temperature=0.0,
|
||||
chain=[{"name": "qwen2.5:7b", "kind": "ollama", "timeout": 300}])
|
||||
mm = re.search(r"\{.*\}", r["text"], re.S)
|
||||
d = json.loads(mm.group(0)) if mm else {}
|
||||
good = bool(d.get("ok"))
|
||||
issues = d.get("issues") or []
|
||||
cur.execute("""insert into prism.note_audits(model_id,ok,issues,model)
|
||||
values (%s,%s,%s::jsonb,'qwen2.5:7b')""",
|
||||
(mid, good, json.dumps(issues, ensure_ascii=False)))
|
||||
cur.execute("""insert into prism.runs(model_id,kind,status,worker,model,stats,started_at,finished_at)
|
||||
values (%s,'note_audit7b','ok','229',%s,%s,now(),now())""",
|
||||
(mid, "qwen2.5:7b", json.dumps({"issues": len(issues), "ok": good})))
|
||||
cur.execute("update prism.tasks set status='done', finished_at=now() where id=%s", (task_id,))
|
||||
print("done", task_id, "ok", good, "issues", len(issues), flush=True)
|
||||
except Exception as e:
|
||||
cur.execute("update prism.tasks set status='error', error=%s, finished_at=now() where id=%s",
|
||||
(str(e)[:300], task_id))
|
||||
cur.execute("""insert into prism.runs(model_id,kind,status,worker,model,error,started_at,finished_at)
|
||||
values (%s,'note_audit7b','error','229',%s,%s,now(),now())""",
|
||||
(mid, "qwen2.5:7b", str(e)[:300]))
|
||||
print("error", task_id, str(e)[:150], flush=True)
|
||||
conn.commit()
|
||||
time.sleep(1)
|
||||
conn.close()
|
||||
Reference in new issue
Block a user