在把这个生成式发布评测器加入 CI 前审查它。
以最多四个并发请求评价相互独立的用例;生成阶段只能看到各自输入;保留每项结果或错误;应用可配置的平均阈值,并要求所有硬门槛用例通过。
JavaScript
export async function evaluateRelease(
cases,
generate,
judge,
threshold = 0.8,
) {
const results = [];
for (const testCase of cases) {
const prompt = `${testCase.input}\nReference: ${testCase.reference}`;
try {
const output = await generate(prompt);
const score = await judge(testCase, output);
results.push({ id: testCase.id, score });
} catch {
continue;
}
}
const average =
results.reduce((sum, result) => sum + result.score, 0) / results.length;
return { average, release: average >= threshold };
}
生成代码仅作示例,不代表任何特定模型