v2.1.0:测试名称(主题)标注+详情/Excel整体统计平均/最小/最大+开放API(配置更新PUT/测试列表limit/服务端JSON导出/api_key打码)+API.md文档
This commit is contained in:
@@ -62,6 +62,16 @@ def get_one_config(cid):
|
||||
return jsonify(c)
|
||||
|
||||
|
||||
@app.route("/api/configs/<int:cid>", methods=["PUT"])
|
||||
def update_config(cid):
|
||||
cfg = request.get_json(force=True) or {}
|
||||
old = db.get_config(cid)
|
||||
if not old:
|
||||
return jsonify({"ok": False, "error": "配置不存在"}), 404
|
||||
db.update_config(cid, cfg)
|
||||
return jsonify({"ok": True, "id": cid})
|
||||
|
||||
|
||||
@app.route("/api/configs/<int:cid>", methods=["DELETE"])
|
||||
def del_config(cid):
|
||||
db.delete_config(cid)
|
||||
@@ -107,7 +117,11 @@ def start_test():
|
||||
|
||||
@app.route("/api/tests", methods=["GET"])
|
||||
def list_tests():
|
||||
return jsonify(db.list_tests())
|
||||
try:
|
||||
limit = int(request.args.get("limit", 100))
|
||||
except ValueError:
|
||||
limit = 100
|
||||
return jsonify(db.list_tests(max(1, min(limit, 1000))))
|
||||
|
||||
|
||||
@app.route("/api/tests/<int:tid>", methods=["GET"])
|
||||
@@ -117,6 +131,7 @@ def get_test(tid):
|
||||
return jsonify({"ok": False, "error": "测试不存在"}), 404
|
||||
t["runs"] = db.get_runs(tid)
|
||||
t["logs"] = db.get_logs(tid)
|
||||
_mask_cfg(t.get("config"))
|
||||
return jsonify(t)
|
||||
|
||||
|
||||
@@ -145,6 +160,25 @@ def del_test(tid):
|
||||
return jsonify({"ok": True})
|
||||
|
||||
|
||||
@app.route("/api/tests/<int:tid>/export.json")
|
||||
def export_json(tid):
|
||||
t = db.get_test(tid)
|
||||
if not t:
|
||||
return jsonify({"ok": False, "error": "测试不存在"}), 404
|
||||
t["runs"] = db.get_runs(tid)
|
||||
t["logs"] = db.get_logs(tid)
|
||||
_mask_cfg(t.get("config"))
|
||||
return jsonify(t)
|
||||
|
||||
|
||||
def _mask_cfg(cfg):
|
||||
"""对外隐藏 API Key,仅保留前几位便于识别"""
|
||||
if cfg and cfg.get("api_key"):
|
||||
k = cfg["api_key"]
|
||||
cfg["api_key"] = k[:4] + "****" if len(k) > 6 else "****"
|
||||
return cfg
|
||||
|
||||
|
||||
# ───────────────────────── Excel 导出 ─────────────────────────
|
||||
|
||||
@app.route("/api/tests/<int:tid>/export.xlsx")
|
||||
@@ -193,6 +227,7 @@ def _build_xlsx(t):
|
||||
ws.cell(1, 1).font = Font(bold=True, size=14)
|
||||
info = [
|
||||
["测试编号", "#%d" % t["id"]],
|
||||
["测试名称", t.get("name") or "(未命名)"],
|
||||
["创建时间", t.get("created_at", "")],
|
||||
["状态", t.get("status", "")],
|
||||
["提供商", t.get("provider", "")],
|
||||
@@ -209,25 +244,26 @@ def _build_xlsx(t):
|
||||
]
|
||||
for row in info:
|
||||
ws.append(row)
|
||||
ws.cell(14, 1).font = title_font
|
||||
ws.cell(15, 1).font = title_font
|
||||
r0 = len(info) + 2
|
||||
overall = [
|
||||
["平均首字延迟(ms)", s.get("avg_ttft_ms")],
|
||||
["最佳首字延迟(ms)", s.get("best_ttft_ms")],
|
||||
["平均预填充速度(tok/s)", s.get("avg_prefill_speed")],
|
||||
["平均解码速度(tok/s)", s.get("avg_decode_speed")],
|
||||
["平均提示词(tok)", s.get("avg_prompt_tokens")],
|
||||
["平均输出(tok)", s.get("avg_output_tokens")],
|
||||
["平均总耗时(ms)", s.get("avg_total_ms")],
|
||||
["首字延迟(ms)", s.get("avg_ttft_ms"), s.get("max_ttft_ms"), s.get("min_ttft_ms")],
|
||||
["预填充速度(tok/s)", s.get("avg_prefill_speed"), s.get("max_prefill_speed"), s.get("min_prefill_speed")],
|
||||
["解码速度(tok/s)", s.get("avg_decode_speed"), s.get("max_decode_speed"), s.get("min_decode_speed")],
|
||||
["提示词(tok)", s.get("avg_prompt_tokens"), None, None],
|
||||
["输出(tok)", s.get("avg_output_tokens"), None, None],
|
||||
["总耗时(ms)", s.get("avg_total_ms"), s.get("max_total_ms"), s.get("min_total_ms")],
|
||||
]
|
||||
ws.cell(r0, 1, "整体平均指标").font = title_font
|
||||
for i, row in enumerate(overall, start=r0 + 1):
|
||||
ws.append([])
|
||||
ws.cell(r0, 1, "整体统计指标(平均 / 最大 / 最小)").font = title_font
|
||||
for j, c in enumerate(["指标", "平均", "最大", "最小"], start=1):
|
||||
ws.cell(row=r0 + 1, column=j, value=c)
|
||||
style_header(ws, r0 + 1, 4)
|
||||
for i, row in enumerate(overall, start=r0 + 2):
|
||||
for j, v in enumerate(row, start=1):
|
||||
ws.cell(row=i, column=j, value=v)
|
||||
|
||||
# 按上下文长度分组
|
||||
r1 = r0 + len(overall) + 2
|
||||
r1 = r0 + len(overall) + 3
|
||||
ws.cell(r1, 1, "按上下文长度分组").font = title_font
|
||||
cols = ["上下文长度(tok)", "采样(成功/总数)", "首字ms", "预填充tok/s", "解码tok/s", "提示词tok", "输出tok", "总耗时ms"]
|
||||
ws.append([])
|
||||
|
||||
Reference in New Issue
Block a user