v2.1.0:测试名称(主题)标注+详情/Excel整体统计平均/最小/最大+开放API(配置更新PUT/测试列表limit/服务端JSON导出/api_key打码)+API.md文档
This commit is contained in:
+27
-4
@@ -28,6 +28,7 @@ CREATE TABLE IF NOT EXISTS tests(
|
||||
status TEXT DEFAULT 'running',
|
||||
provider TEXT DEFAULT '',
|
||||
model TEXT DEFAULT '',
|
||||
name TEXT DEFAULT '',
|
||||
config_json TEXT DEFAULT '{}',
|
||||
gen_cfg_json TEXT DEFAULT '{}',
|
||||
summary_json TEXT DEFAULT '{}',
|
||||
@@ -67,11 +68,15 @@ def _connect():
|
||||
|
||||
|
||||
def _migrate(conn):
|
||||
"""老库升级:为 test_runs 补 context_length 列"""
|
||||
"""老库升级:test_runs 补 context_length、tests 补 name"""
|
||||
cur = conn.execute("PRAGMA table_info(test_runs)")
|
||||
cols = [r[1] for r in cur.fetchall()]
|
||||
if "context_length" not in cols:
|
||||
conn.execute("ALTER TABLE test_runs ADD COLUMN context_length INTEGER DEFAULT 0")
|
||||
cur = conn.execute("PRAGMA table_info(tests)")
|
||||
tcols = [r[1] for r in cur.fetchall()]
|
||||
if "name" not in tcols:
|
||||
conn.execute("ALTER TABLE tests ADD COLUMN name TEXT DEFAULT ''")
|
||||
|
||||
|
||||
def init_db():
|
||||
@@ -134,6 +139,23 @@ def delete_config(cid: int):
|
||||
conn.close()
|
||||
|
||||
|
||||
def update_config(cid: int, cfg: dict):
|
||||
"""局部更新:只更新请求里出现的字段"""
|
||||
allow = {"name", "provider", "base_url", "api_key", "model", "temperature"}
|
||||
fields = {k: v for k, v in cfg.items() if k in allow and v is not None}
|
||||
if not fields:
|
||||
return
|
||||
sets = ",".join("%s=?" % k for k in fields)
|
||||
vals = list(fields.values()) + [cid]
|
||||
with _lock:
|
||||
conn = _connect()
|
||||
try:
|
||||
conn.execute("UPDATE configs SET %s WHERE id=?" % sets, vals)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
# ───────────────────────── 测试记录 ─────────────────────────
|
||||
|
||||
def create_test(cfg: dict, gen: dict) -> int:
|
||||
@@ -141,9 +163,10 @@ def create_test(cfg: dict, gen: dict) -> int:
|
||||
conn = _connect()
|
||||
try:
|
||||
cur = conn.execute(
|
||||
"INSERT INTO tests(status,provider,model,config_json,gen_cfg_json,started_at) "
|
||||
"VALUES('running',?,?,?,?,?)",
|
||||
"INSERT INTO tests(status,provider,model,name,config_json,gen_cfg_json,started_at) "
|
||||
"VALUES('running',?,?,?,?,?,?)",
|
||||
(cfg.get("provider", "openai"), cfg.get("model", ""),
|
||||
gen.get("name") or cfg.get("name") or "",
|
||||
json.dumps(cfg, ensure_ascii=False), json.dumps(gen, ensure_ascii=False),
|
||||
time.time()))
|
||||
conn.commit()
|
||||
@@ -186,7 +209,7 @@ def list_tests(limit=100):
|
||||
conn = _connect()
|
||||
try:
|
||||
rows = conn.execute(
|
||||
"SELECT id,created_at,status,provider,model,summary_json,error "
|
||||
"SELECT id,created_at,status,provider,model,name,summary_json,error "
|
||||
"FROM tests ORDER BY id DESC LIMIT ?", (limit,)).fetchall()
|
||||
out = []
|
||||
for r in rows:
|
||||
|
||||
Reference in New Issue
Block a user