feature: scripts/export_run.py 用来导出运行结果
This commit is contained in:
+30
-6
@@ -65,8 +65,12 @@ def render_input(model_input: dict[str, Any]) -> list[str]:
|
||||
return sections or ["无", ""]
|
||||
|
||||
|
||||
def is_completed_pass(result: dict[str, Any]) -> bool:
|
||||
return result.get("execution_status") == "completed" and result.get("verdict") == "pass"
|
||||
def matches_result(
|
||||
result: dict[str, Any], execution_status: str | None, verdict: str | None
|
||||
) -> bool:
|
||||
return (execution_status is None or result.get("execution_status") == execution_status) and (
|
||||
verdict is None or result.get("verdict") == verdict
|
||||
)
|
||||
|
||||
|
||||
def render_markdown(run: dict[str, Any], results: list[dict[str, Any]]) -> str:
|
||||
@@ -83,9 +87,9 @@ def render_markdown(run: dict[str, Any], results: list[dict[str, Any]]) -> str:
|
||||
f"- 开始时间:{run.get('started_at', '')}",
|
||||
f"- 完成时间:{run.get('finished_at', '')}",
|
||||
"",
|
||||
f"- 本报告 Pass 样例:{len(results)}",
|
||||
f"- 本报告导出样例:{len(results)}",
|
||||
"",
|
||||
"## Pass 样例详情",
|
||||
"## 测试样例详情",
|
||||
"",
|
||||
]
|
||||
for index, result in enumerate(results, 1):
|
||||
@@ -133,6 +137,16 @@ def parse_args() -> argparse.Namespace:
|
||||
parser.add_argument("--run-id", type=int, default=7, help="要导出的 run ID(默认:7)")
|
||||
parser.add_argument("--base-url", default="http://127.0.0.1:8000", help="API 服务地址")
|
||||
parser.add_argument("--username", help="登录用户名;省略时交互输入")
|
||||
parser.add_argument(
|
||||
"--execution-status",
|
||||
choices=("completed", "error"),
|
||||
help="只导出指定执行状态;默认导出全部",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--verdict",
|
||||
choices=("pass", "fail", "needs_human_review", "judge_format_error", "none"),
|
||||
help="只导出指定评价结果;none 表示未评价;默认导出全部",
|
||||
)
|
||||
parser.add_argument("--output", type=Path, help="输出文件路径")
|
||||
return parser.parse_args()
|
||||
|
||||
@@ -157,8 +171,18 @@ def main() -> int:
|
||||
results = request_json(
|
||||
args.base_url, f"/api/v1/runs/{args.run_id}/results", token=token
|
||||
)
|
||||
results = [result for result in results if is_completed_pass(result)]
|
||||
output = args.output or Path("outputs") / f"run_{args.run_id}_pass_results.md"
|
||||
verdict = None if args.verdict is None else args.verdict
|
||||
results = [
|
||||
result
|
||||
for result in results
|
||||
if matches_result(
|
||||
result,
|
||||
args.execution_status,
|
||||
None if verdict == "none" else verdict,
|
||||
)
|
||||
and (verdict != "none" or result.get("verdict") is None)
|
||||
]
|
||||
output = args.output or Path("outputs") / f"run_{args.run_id}_results.md"
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
output.write_text(render_markdown(run, results), encoding="utf-8")
|
||||
except (RuntimeError, KeyError, OSError) as exc:
|
||||
|
||||
Reference in New Issue
Block a user