Files
hack/tools/scripts/apply_reconcile.py
T

75 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Apply reconcile.json: create missing channels, revive disabled-live ones
(with test_model set to the direct-verified working model), disable dead ones.
"""
import json, sys, re, time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import newapi_client as n
H = Path(__file__).resolve().parent / "llm-key-hunter"
R = json.loads((H / "results/reconcile.json").read_text())
chans = {c["id"]: c for c in json.loads(Path("/tmp/chans.json").read_text())}
# working model per disabled-live channel: parse from audit detail
def working_model(rec):
d = rec["detail"]
m = re.match(r"(\w+)\s+([\w./\-]+)\s+200", d)
if m:
kind, model = m.group(1), m.group(2)
return kind, model
return None, None
def good_models(kind, prov):
if prov == "zhipu":
if kind == "coding":
return "glm-4.7-flash,glm-4.5-air,glm-4.5-flash,glm-4-flash,glm-5.2"
return "glm-4-flash,glm-4.5-flash"
return None
created, revived, fixed, disabled, failed = [], [], [], [], []
# 1) create missing
print(f"=== creating {len(R['to_create'])} missing channels ===")
for ch in R["to_create"]:
ok, msg = n.add_channel(ch)
tag = "OK " + str(msg) if ok else "FAIL " + str(msg)
print(f" {ch['name']:28} {tag}")
(created if ok else failed).append((ch["name"], msg))
# 2) revive disabled-live: set test_model + models + status=1
print(f"\n=== reviving {len(R['usable_channel_disabled'])} disabled-live channels ===")
for rec in R["usable_channel_disabled"]:
kind, model = working_model(rec)
for cid, name, st in rec["existing"]:
if st == 1:
continue
c = chans.get(cid, {})
fields = {"status": 1}
gm = good_models(kind, rec["prov"])
if gm and c.get("models") != gm:
fields["models"] = gm
if model:
fields["test_model"] = model
ok, msg = n.update_channel(cid, **fields)
if ok:
revived.append(cid)
print(f" {cid:4} {name:26} revive OK (model={model})")
else:
failed.append((name, msg))
print(f" {cid:4} {name:26} FAIL {msg}")
# 3) disable dead enabled
print(f"\n=== disabling {len(R['to_disable'])} dead enabled channels ===")
for cid in sorted(set(R["to_disable"])):
ok, msg = n.update_channel(cid, status=2)
print(f" {cid}: {'OK' if ok else msg}")
(disabled if ok else failed).append(cid)
print(f"\n=== DONE: created={len(created)} revived={len(revived)} "
f"disabled={len(disabled)} failed={len(failed)} ===")
if failed:
print("FAILURES:")
for f in failed[:30]:
print(" ", f)