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>
86 lines
2.8 KiB
JavaScript
86 lines
2.8 KiB
JavaScript
// api.js — 控制台后端 HTTP 接口的轻量封装。
|
||
|
||
const API = {
|
||
// 通用 JSON GET,失败时抛出带状态码的错误。
|
||
async get(path) {
|
||
const resp = await fetch(path);
|
||
if (!resp.ok) {
|
||
const detail = await API._extractError(resp);
|
||
throw new Error(detail);
|
||
}
|
||
return resp.json();
|
||
},
|
||
|
||
// 通用 JSON POST。
|
||
async post(path, body) {
|
||
const resp = await fetch(path, {
|
||
method: "POST",
|
||
headers: { "Content-Type": "application/json" },
|
||
body: JSON.stringify(body || {}),
|
||
});
|
||
if (!resp.ok) {
|
||
const detail = await API._extractError(resp);
|
||
throw new Error(detail);
|
||
}
|
||
return resp.json();
|
||
},
|
||
|
||
// 从错误响应中尽量解析出 detail 文本。
|
||
async _extractError(resp) {
|
||
try {
|
||
const data = await resp.json();
|
||
return data.detail || `请求失败 (${resp.status})`;
|
||
} catch (_e) {
|
||
return `请求失败 (${resp.status})`;
|
||
}
|
||
},
|
||
|
||
health() { return API.get("/api/health"); },
|
||
runs() { return API.get("/api/runs"); },
|
||
runDetail(runId) { return API.get(`/api/runs/${encodeURIComponent(runId)}`); },
|
||
scenarios() { return API.get("/api/scenarios"); },
|
||
triggerEvaluation(scenarioPath) {
|
||
return API.post("/api/evaluations", { scenario_path: scenarioPath });
|
||
},
|
||
taskStatus(taskId) { return API.get(`/api/evaluations/${encodeURIComponent(taskId)}`); },
|
||
|
||
// LLM Profile API
|
||
profiles() { return API.get("/api/llm-profiles"); },
|
||
createProfile(body) { return API.post("/api/llm-profiles", body); },
|
||
updateProfile(id, body) {
|
||
return fetch(`/api/llm-profiles/${encodeURIComponent(id)}`, {
|
||
method: "PUT",
|
||
headers: { "Content-Type": "application/json" },
|
||
body: JSON.stringify(body),
|
||
}).then(async r => {
|
||
if (!r.ok) { const d = await API._extractError(r); throw new Error(d); }
|
||
return r.json();
|
||
});
|
||
},
|
||
deleteProfile(id) {
|
||
return fetch(`/api/llm-profiles/${encodeURIComponent(id)}`, { method: "DELETE" })
|
||
.then(async r => {
|
||
if (!r.ok) { const d = await API._extractError(r); throw new Error(d); }
|
||
return r.json();
|
||
});
|
||
},
|
||
applyProfiles(body) { return API.post("/api/llm-profiles/apply", body); },
|
||
|
||
// 异步评分记录 API
|
||
scoreJobsAsync(body) { return API.post("/api/score/async", body); },
|
||
getScoreJob(jobId) { return API.get(`/api/score/jobs/${encodeURIComponent(jobId)}`); },
|
||
listScoreJobs() { return API.get("/api/score/jobs"); },
|
||
|
||
// 测试已保存 profile 的连通性
|
||
testProfile(id) {
|
||
return fetch(`/api/llm-profiles/${encodeURIComponent(id)}/test`, { method: "POST" })
|
||
.then(async r => {
|
||
if (!r.ok) { const d = await API._extractError(r); throw new Error(d); }
|
||
return r.json();
|
||
});
|
||
},
|
||
|
||
// 测试表单中填写的内联参数(保存前即可测试)
|
||
probeConnectivity(body) { return API.post("/api/llm-profiles/probe", body); },
|
||
};
|