v0.9: parallelize phase4 and add model/search playbooks

This commit is contained in:
kai
2026-04-24 10:19:48 +08:00
parent c444007f04
commit c93fce5078
13 changed files with 626 additions and 100 deletions
+8 -3
View File
@@ -15,6 +15,7 @@ from __future__ import annotations
import json
import os
import sys
import threading
import time
from dataclasses import dataclass, field
from pathlib import Path
@@ -111,6 +112,8 @@ class ZenMuxClient:
self.log_file = log_file
self.usage = UsageStats()
self._client = httpx.Client(timeout=timeout)
self._log_lock = threading.Lock()
self._usage_lock = threading.Lock()
def close(self) -> None:
self._client.close()
@@ -125,8 +128,9 @@ class ZenMuxClient:
if not self.log_file:
return
self.log_file.parent.mkdir(parents=True, exist_ok=True)
with self.log_file.open("a", encoding="utf-8") as f:
f.write(json.dumps(payload, ensure_ascii=False) + "\n")
with self._log_lock:
with self.log_file.open("a", encoding="utf-8") as f:
f.write(json.dumps(payload, ensure_ascii=False) + "\n")
def chat_complete(
self,
@@ -191,7 +195,8 @@ class ZenMuxClient:
except Exception as e:
raise ZenMuxError(f"invalid JSON from zenmux: {e}; body={resp.text[:500]}")
usage = data.get("usage", {}) or {}
self.usage.add(model, usage)
with self._usage_lock:
self.usage.add(model, usage)
content = ""
choices = data.get("choices") or []
if choices: