feat: async score jobs — POST /api/score/async + 评分记录 page
Each async score job:
- Runs InlineScorer.score() in thread pool
- Writes standard run artifacts (metadata.json, scores.csv, summary.md)
- Runs optimization_advisor => optimization_advice.md
- Result appears in 运行列表 and 报告详情 with full report
New endpoints:
- POST /api/score/async (202, job_id immediate)
- GET /api/score/jobs (list all jobs)
- GET /api/score/jobs/{id} (single job status)
Frontend:
- 评分记录 nav page with card list
- 5s auto-polling for queued/running jobs
- 查看报告 button navigates to existing 报告详情 page
Dify: change /api/score -> /api/score/async, no response parsing needed
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -514,3 +514,40 @@ class ScoreResponse(BaseModel):
|
||||
default=None,
|
||||
description="打分异常时的错误信息(HTTP 200 仍返回,scores 为空)。",
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 异步评分记录模型
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class AsyncScoreJobResponse(BaseModel):
|
||||
"""Immediate 202 response after submitting an async score job."""
|
||||
|
||||
job_id: str = Field(description="任务唯一标识符,用于后续查询结果。")
|
||||
status: str = Field(default="queued", description="初始状态:queued。")
|
||||
run_id: str | None = Field(
|
||||
default=None,
|
||||
description="评分完成后写入的 Run ID,可在「运行列表」中查看完整报告。",
|
||||
)
|
||||
|
||||
|
||||
class AsyncScoreJobStatus(BaseModel):
|
||||
"""State of one async score job (queued → running → completed/failed)."""
|
||||
|
||||
job_id: str = Field(description="任务唯一标识符。")
|
||||
status: str = Field(description="queued | running | completed | failed")
|
||||
created_at: str = Field(default="", description="创建时间(ISO 8601 UTC)。")
|
||||
finished_at: str = Field(default="", description="完成时间(ISO 8601 UTC)。")
|
||||
run_id: str | None = Field(
|
||||
default=None,
|
||||
description="完成后对应的 Run ID,可通过 GET /api/runs/{run_id} 查看完整报告。",
|
||||
)
|
||||
request_summary: dict = Field(
|
||||
default_factory=dict,
|
||||
description="请求参数快照(question 前80字、metrics、judge_model 等)。",
|
||||
)
|
||||
scores: dict[str, float | None] = Field(default_factory=dict, description="各指标得分。")
|
||||
weighted_score: float | None = Field(default=None, description="加权综合得分。")
|
||||
latency_ms: int = Field(default=0, description="评分耗时毫秒。")
|
||||
skipped_metrics: list[str] = Field(default_factory=list)
|
||||
error: str | None = Field(default=None)
|
||||
|
||||
Reference in New Issue
Block a user