diff --git a/scripts/ab-replay.py b/scripts/ab-replay.py index b86c527..5545691 100644 --- a/scripts/ab-replay.py +++ b/scripts/ab-replay.py @@ -58,24 +58,23 @@ def chat_once(token, model, sid, message, timeout=240): tools, reply, tokens, err = [], "", "", None try: with urllib.request.urlopen(req, timeout=timeout) as r: - ev = None for raw in r: line = raw.decode("utf-8", "replace").rstrip("\n") - if line.startswith("event:"): - ev = line[6:].strip() - elif line.startswith("data:"): - try: - d = json.loads(line[5:].strip()) - except Exception: - continue - if ev == "tool_result" and d.get("action") and not d.get("synthetic"): - tools.append(d["action"]) - elif ev == "token": - tokens += d.get("text", "") - elif ev == "done": - reply = d.get("reply") or "" - elif ev == "error": - err = str(d.get("message") or d)[:150] + if not line.startswith("data:"): + continue + try: + d = json.loads(line[5:].strip()) + except Exception: + continue + ev = d.get("type") + if ev == "tool_result" and d.get("action") and not d.get("synthetic"): + tools.append(d["action"]) + elif ev == "token": + tokens += d.get("text", "") + elif ev == "done": + reply = d.get("reply") or "" + elif ev == "error": + err = str(d.get("message") or d)[:150] except Exception as e: err = f"{type(e).__name__}: {str(e)[:100]}" return {"tools": tools, "reply": reply or tokens, "sec": round(time.time() - t0, 1), "error": err} @@ -100,7 +99,7 @@ def main(): a = ap.parse_args() models = [m for m in a.models.split(",") if m] - today = datetime.datetime.utcnow().strftime("%Y-%m-%d") + today = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d") daily = os.path.join(USER_DIR, "workspace", "memory", today + ".md") before = open(daily, "rb").read() if os.path.exists(daily) else None