## 新增功能 - 文件管理模块:分类树 + 文件上传/下载/删除 - 文件上传支持拖拽(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>
130 lines
4.3 KiB
Python
130 lines
4.3 KiB
Python
"""CLI commands for evaluation execution."""
|
|
|
|
import asyncio
|
|
from typing import Any
|
|
|
|
import typer
|
|
from agenteval.evaluation.engine import EvalEngine
|
|
from agenteval.storage.repository import RunRepository, ScenarioRepository, TargetRepository
|
|
from rich.console import Console
|
|
from rich.table import Table
|
|
|
|
app = typer.Typer(help="评测执行")
|
|
console = Console()
|
|
|
|
|
|
def _progress(event: str, data: dict[str, Any]) -> None:
|
|
if event == "case_start":
|
|
console.print(f"[用例 {data['index']}/{data['total']}] {data['case_id']}")
|
|
elif event == "turn_end":
|
|
console.print(f" 第 {data['round']} 轮回复,耗时 {data['latency_ms']}ms")
|
|
elif event == "rule_result":
|
|
style = "green" if data["passed"] else "red"
|
|
console.print(f" [{data['rule_type']}] {'通过' if data['passed'] else '失败'} - {data['reason']}", style=style)
|
|
elif event == "error":
|
|
console.print(f"执行异常: {data['error']}", style="red")
|
|
|
|
|
|
@app.command("start", help="启动一次评测")
|
|
def start_run(
|
|
target_id: str = typer.Option(..., help="评测对象 ID"),
|
|
scenario_id: str = typer.Option(..., help="评测场景 ID"),
|
|
output_json: bool = typer.Option(False, "--output-json", help="运行结束后输出 JSON 报告"),
|
|
) -> None:
|
|
target = TargetRepository().get(target_id)
|
|
if not target:
|
|
console.print(f"评测对象不存在: {target_id}", style="red")
|
|
raise typer.Exit(1)
|
|
|
|
scenario = ScenarioRepository().get(scenario_id)
|
|
if not scenario:
|
|
console.print(f"评测场景不存在: {scenario_id}", style="red")
|
|
raise typer.Exit(1)
|
|
|
|
console.print(f"开始评测: 对象={target.name}, 场景={scenario.name}")
|
|
engine = EvalEngine(target=target, scenario=scenario)
|
|
try:
|
|
run = asyncio.run(engine.run(progress_callback=_progress))
|
|
except Exception as exc:
|
|
console.print(f"评测失败: {exc}", style="red")
|
|
raise typer.Exit(1)
|
|
|
|
console.print(f"评测完成: run_id={run.id}, status={run.status.value}")
|
|
if run.summary:
|
|
console.print_json(data=run.summary)
|
|
|
|
if output_json:
|
|
from agenteval.evaluation.report import render_json_report
|
|
|
|
console.print(render_json_report(run.id))
|
|
|
|
|
|
@app.command("list", help="列出评测执行记录")
|
|
def list_runs() -> None:
|
|
runs = RunRepository().list_all()
|
|
if not runs:
|
|
console.print("暂无评测记录")
|
|
return
|
|
|
|
table = Table(show_header=True, header_style="bold")
|
|
table.add_column("Run ID")
|
|
table.add_column("对象 ID")
|
|
table.add_column("场景 ID")
|
|
table.add_column("状态")
|
|
table.add_column("开始时间")
|
|
table.add_column("完成时间")
|
|
|
|
for run in runs:
|
|
table.add_row(
|
|
run.id or "",
|
|
run.target_id,
|
|
run.scenario_id,
|
|
run.status.value,
|
|
str(run.started_at)[:19] if run.started_at else "",
|
|
str(run.completed_at)[:19] if run.completed_at else "",
|
|
)
|
|
console.print(table)
|
|
|
|
|
|
@app.command("status", help="查看评测执行状态")
|
|
def run_status(run_id: str) -> None:
|
|
run = RunRepository().get(run_id)
|
|
if not run:
|
|
console.print(f"评测记录不存在: {run_id}", style="red")
|
|
raise typer.Exit(1)
|
|
|
|
console.print_json(data=run.model_dump())
|
|
|
|
|
|
@app.command("logs", help="查看评测执行日志(对话轮次)")
|
|
def run_logs(run_id: str) -> None:
|
|
repo = RunRepository()
|
|
run = repo.get(run_id)
|
|
if not run:
|
|
console.print(f"评测记录不存在: {run_id}", style="red")
|
|
raise typer.Exit(1)
|
|
|
|
turns = repo.get_turns(run_id)
|
|
if not turns:
|
|
console.print("暂无对话记录")
|
|
return
|
|
|
|
table = Table(show_header=True, header_style="bold")
|
|
table.add_column("Case ID")
|
|
table.add_column("轮次")
|
|
table.add_column("消息 ID")
|
|
table.add_column("耗时(ms)")
|
|
table.add_column("发送时间")
|
|
table.add_column("回复时间")
|
|
|
|
for turn in turns:
|
|
table.add_row(
|
|
turn.case_id,
|
|
str(turn.round_index),
|
|
turn.question_msg_id or "",
|
|
str(turn.latency_ms) if turn.latency_ms is not None else "",
|
|
str(turn.sent_at)[:19] if turn.sent_at else "",
|
|
str(turn.received_at)[:19] if turn.received_at else "",
|
|
)
|
|
console.print(table)
|