AgentEvalTool/backend/cli/report.py
sinohqb a77cd83e6a v0.2.0-dev: 文件管理 + 页面布局统一 + 6 个 bug 修复
## 新增功能
- 文件管理模块:分类树 + 文件上传/下载/删除
- 文件上传支持拖拽(Dragger)+ 手动上传(customRequest 模式)

## 页面布局统一(参照评测执行页)
- 仪表盘/评测对象/评测场景/评测报告 全部改为全高 flex 布局
- 统一内联页头样式(h2 + 竖线分隔 + 描述)
- 表格撑满高度、overflow 处理
- 每页添加刷新按钮

## Bug 修复
- 分类树操作按钮 hover 不可见(CSS 规则缺失)
- 文件上传失败(multipart boundary 缺失)
- LLM API 响应 content blocks 数组格式支持(_extract_content_from_api_response)
- response_time_max_ms 被静默忽略(隐式规则传空 params)
- 空 messages 导致 IndexError 崩溃
- poll_reply 异常中止整个 run(缺 try/catch)
- engine finally 未关闭 session
- 3 个页面 UTC 时间戳解析偏差 8 小时

## 后端
- EvalEngine: poll_reply 异常保护、空 dialog 保护、session 关闭
- LLM API 响应解析支持 content-block-array 格式
- 隐式 response_time 规则正确传递 max_ms 参数

## 前端
- api.ts: 移除手动 Content-Type(让浏览器自动添加 boundary)
- Files.tsx: customRequest 替代 beforeUpload、布局优化
- index.css: 分类树 hover 规则
- Targets/Scenarios/Home/Reports: 全高布局改造
- 3 个页面时间戳改用 formatDateTime()(修复 UTC 偏差)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-16 15:25:22 +08:00

69 lines
2.3 KiB
Python

"""CLI commands for report generation."""
from pathlib import Path
from typing import Optional
import typer
from agenteval.evaluation.report import render_html_report, render_json_report, save_report
from agenteval.storage.repository import RunRepository
from rich.console import Console
app = typer.Typer(help="评测报告")
console = Console()
@app.command("show", help="查看报告")
def show_report(
run_id: str,
fmt: str = typer.Option("json", "--format", help="输出格式: json | html"),
) -> None:
run = RunRepository().get(run_id)
if not run:
console.print(f"评测记录不存在: {run_id}", style="red")
raise typer.Exit(1)
if fmt == "json":
console.print(render_json_report(run_id))
elif fmt == "html":
console.print(render_html_report(run_id))
else:
console.print(f"不支持的格式: {fmt}", style="red")
raise typer.Exit(1)
@app.command("generate", help="生成报告并保存到文件")
def generate_report(
run_id: str,
fmt: str = typer.Option("html", "--format", help="输出格式: json | html"),
output_dir: Optional[Path] = typer.Option(None, help="输出目录"),
) -> None:
run = RunRepository().get(run_id)
if not run:
console.print(f"评测记录不存在: {run_id}", style="red")
raise typer.Exit(1)
path = save_report(run_id, fmt=fmt, output_dir=output_dir)
console.print(f"报告已保存: {path}")
@app.command("compare", help="对比两次评测报告")
def compare_reports(
run_id_1: str,
run_id_2: str,
) -> None:
from agenteval.evaluation.report import generate_report
r1 = RunRepository().get(run_id_1)
r2 = RunRepository().get(run_id_2)
if not r1 or not r2:
console.print("评测记录不存在", style="red")
raise typer.Exit(1)
report1 = generate_report(run_id_1)
report2 = generate_report(run_id_2)
console.print(f"对比: {run_id_1} vs {run_id_2}")
console.print(f" 用例数: {report1['summary']['total_cases']} -> {report2['summary']['total_cases']}")
console.print(f" 通过用例: {report1['summary']['passed_cases']} -> {report2['summary']['passed_cases']}")
console.print(f" 规则通过率: {report1['summary']['pass_rate']:.2%} -> {report2['summary']['pass_rate']:.2%}")