Spaces:
Running
Running
sync: 190 file da Baida98/AI@b589d1e9 (2026-08-26 10:21 UTC) [deploy-all]
#114
by Baida07 - opened
- benchmark-extended.mjs +67 -17
benchmark-extended.mjs
CHANGED
|
@@ -68,6 +68,15 @@ const F_GAP = _A.includes("--gap-analysis");
|
|
| 68 |
const _multi = _A.indexOf("--multi");
|
| 69 |
const MULTI = _multi !== -1 ? Math.max(2, Math.min(10, parseInt(_A[_multi+1])||3)) : 1;
|
| 70 |
const F_JUDGE = !_A.includes("--no-judge"); // semantic judge abilitato di default
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
const _categoriesArg = _A.find(a=>a.startsWith("--categories="));
|
| 72 |
const TARGET_CATEGORIES = _categoriesArg
|
| 73 |
? new Set(_categoriesArg.slice("--categories=".length).split(",").map(c=>c.trim()).filter(Boolean))
|
|
@@ -753,44 +762,84 @@ const _JUDGE_CACHE = new Map();
|
|
| 753 |
async function judgeWithLLM(question, response, rubric) {
|
| 754 |
if (!F_JUDGE) return null;
|
| 755 |
const apiKey = process.env.GROQ_API_KEY || process.env.CEREBRAS_API_KEY;
|
| 756 |
-
if (!apiKey)
|
|
|
|
|
|
|
|
|
|
| 757 |
const cacheKey = question.slice(0,40) + response.slice(0,40);
|
| 758 |
-
if (_JUDGE_CACHE.has(cacheKey))
|
|
|
|
|
|
|
|
|
|
| 759 |
const isGroq = !!process.env.GROQ_API_KEY;
|
| 760 |
const endpoint = isGroq
|
| 761 |
-
? "https://api.groq.com/openai/v1/chat/completions"
|
| 762 |
: "https://api.cerebras.ai/v1/chat/completions";
|
| 763 |
const model = isGroq ? "openai/gpt-oss-120b" : "llama-3.3-70b";
|
| 764 |
const dims = Object.keys(rubric);
|
| 765 |
const rubricText = dims.map(d => `- ${d} (0.0-1.0): ${rubric[d]}`).join("\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
try {
|
| 767 |
const r = await fetch(endpoint, {
|
| 768 |
method: "POST",
|
| 769 |
headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
| 770 |
-
body: JSON.stringify(
|
| 771 |
-
|
| 772 |
-
messages: [
|
| 773 |
-
{ role: "system", content: "Strict benchmark evaluator. Return ONLY valid JSON, no prose." },
|
| 774 |
-
{ role: "user", content: `TASK: ${question.slice(0,350)}\n\nRESPONSE: ${response.slice(0,1200)}\n\nScore each 0.0-1.0:\n${rubricText}\n\nJSON only: {${dims.map(d=>`"${d}":0.0`).join(",")}}` }
|
| 775 |
-
],
|
| 776 |
-
temperature: 0.05,
|
| 777 |
-
max_tokens: 120,
|
| 778 |
-
}),
|
| 779 |
-
signal: AbortSignal.timeout(9000),
|
| 780 |
});
|
| 781 |
-
if (!r.ok)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 782 |
const data = await r.json();
|
| 783 |
const content = data.choices?.[0]?.message?.content ?? "";
|
| 784 |
const m = content.match(/\{[^}]+\}/);
|
| 785 |
-
if (!m)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 786 |
const scores = JSON.parse(m[0]);
|
| 787 |
for (const d of dims) {
|
| 788 |
-
if (typeof scores[d] !== "number")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
scores[d] = Math.max(0, Math.min(1, +scores[d].toFixed(2)));
|
| 790 |
}
|
|
|
|
|
|
|
| 791 |
_JUDGE_CACHE.set(cacheKey, scores);
|
| 792 |
return scores;
|
| 793 |
-
} catch
|
|
|
|
|
|
|
|
|
|
|
|
|
| 794 |
}
|
| 795 |
|
| 796 |
function tDir(id){
|
|
@@ -2532,6 +2581,7 @@ async function runOneSeed(seed,opts={}){
|
|
| 2532 |
runtime_input:{profile:"fixed-realistic-chat-v1",persona:BENCHMARK_PERSONA,negative_constraints:true,context_messages:BENCHMARK_CONTEXT.length},
|
| 2533 |
runner_prerequisites:{typescript_required:requiresTypeScript,typescript_bin:requiresTypeScript?TSC_BIN:null},
|
| 2534 |
sse_recovery:{resume:"Last-Event-ID",deduplicate_replayed_event_ids:true,max_reconnects:1,status_endpoint:"/api/agent/tasks/{taskId}/status",cancel_on_nonterminal_incomplete:true},
|
|
|
|
| 2535 |
canonical_seed:"1337 (stesse domande per tutti gli agenti — usa --rotate per seed diverso)",
|
| 2536 |
coding:"enterprise: Acc(35%)+Stab(20%)+Auto(15%)+Perf(10%)+Spd(10%)+Cost(5%)+Tool(5%)",
|
| 2537 |
nonCoding:"content: Acc(40%)+Struct(20%)+Comp(15%)+Prec(10%)+Auto(5%)+Spd(5%)+Cost(5%)",
|
|
|
|
| 68 |
const _multi = _A.indexOf("--multi");
|
| 69 |
const MULTI = _multi !== -1 ? Math.max(2, Math.min(10, parseInt(_A[_multi+1])||3)) : 1;
|
| 70 |
const F_JUDGE = !_A.includes("--no-judge"); // semantic judge abilitato di default
|
| 71 |
+
const JUDGE_TELEMETRY = {
|
| 72 |
+
requested: 0,
|
| 73 |
+
succeeded: 0,
|
| 74 |
+
failed: 0,
|
| 75 |
+
cacheHits: 0,
|
| 76 |
+
provider: process.env.GROQ_API_KEY ? "groq" : process.env.CEREBRAS_API_KEY ? "cerebras" : null,
|
| 77 |
+
model: process.env.GROQ_API_KEY ? "openai/gpt-oss-120b" : process.env.CEREBRAS_API_KEY ? "llama-3.3-70b" : null,
|
| 78 |
+
lastFailure: null,
|
| 79 |
+
};
|
| 80 |
const _categoriesArg = _A.find(a=>a.startsWith("--categories="));
|
| 81 |
const TARGET_CATEGORIES = _categoriesArg
|
| 82 |
? new Set(_categoriesArg.slice("--categories=".length).split(",").map(c=>c.trim()).filter(Boolean))
|
|
|
|
| 762 |
async function judgeWithLLM(question, response, rubric) {
|
| 763 |
if (!F_JUDGE) return null;
|
| 764 |
const apiKey = process.env.GROQ_API_KEY || process.env.CEREBRAS_API_KEY;
|
| 765 |
+
if (!apiKey) {
|
| 766 |
+
JUDGE_TELEMETRY.lastFailure = "JUDGE_API_KEY_MISSING";
|
| 767 |
+
return null;
|
| 768 |
+
}
|
| 769 |
const cacheKey = question.slice(0,40) + response.slice(0,40);
|
| 770 |
+
if (_JUDGE_CACHE.has(cacheKey)) {
|
| 771 |
+
JUDGE_TELEMETRY.cacheHits++;
|
| 772 |
+
return _JUDGE_CACHE.get(cacheKey);
|
| 773 |
+
}
|
| 774 |
const isGroq = !!process.env.GROQ_API_KEY;
|
| 775 |
const endpoint = isGroq
|
| 776 |
+
? (process.env.BENCHMARK_GROQ_BASE_URL || "https://api.groq.com/openai/v1/chat/completions")
|
| 777 |
: "https://api.cerebras.ai/v1/chat/completions";
|
| 778 |
const model = isGroq ? "openai/gpt-oss-120b" : "llama-3.3-70b";
|
| 779 |
const dims = Object.keys(rubric);
|
| 780 |
const rubricText = dims.map(d => `- ${d} (0.0-1.0): ${rubric[d]}`).join("\n");
|
| 781 |
+
const scoreSchema = {
|
| 782 |
+
type: "object",
|
| 783 |
+
properties: Object.fromEntries(dims.map(d => [d, { type: "number", minimum: 0, maximum: 1 }])),
|
| 784 |
+
required: dims,
|
| 785 |
+
additionalProperties: false,
|
| 786 |
+
};
|
| 787 |
+
const request = {
|
| 788 |
+
model,
|
| 789 |
+
messages: [
|
| 790 |
+
{ role: "system", content: "Strict benchmark evaluator. Return only the requested numeric JSON object." },
|
| 791 |
+
{ role: "user", content: `TASK: ${question.slice(0,350)}\n\nRESPONSE: ${response.slice(0,1200)}\n\nScore each 0.0-1.0:\n${rubricText}` }
|
| 792 |
+
],
|
| 793 |
+
temperature: 0,
|
| 794 |
+
max_completion_tokens: 256,
|
| 795 |
+
};
|
| 796 |
+
if (isGroq) {
|
| 797 |
+
request.reasoning_effort = "low";
|
| 798 |
+
request.include_reasoning = false;
|
| 799 |
+
request.response_format = {
|
| 800 |
+
type: "json_schema",
|
| 801 |
+
json_schema: { name: "benchmark_scores", strict: true, schema: scoreSchema },
|
| 802 |
+
};
|
| 803 |
+
}
|
| 804 |
+
JUDGE_TELEMETRY.requested++;
|
| 805 |
try {
|
| 806 |
const r = await fetch(endpoint, {
|
| 807 |
method: "POST",
|
| 808 |
headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
| 809 |
+
body: JSON.stringify(request),
|
| 810 |
+
signal: AbortSignal.timeout(12_000),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 811 |
});
|
| 812 |
+
if (!r.ok) {
|
| 813 |
+
JUDGE_TELEMETRY.failed++;
|
| 814 |
+
JUDGE_TELEMETRY.lastFailure = `HTTP_${r.status}`;
|
| 815 |
+
return null;
|
| 816 |
+
}
|
| 817 |
const data = await r.json();
|
| 818 |
const content = data.choices?.[0]?.message?.content ?? "";
|
| 819 |
const m = content.match(/\{[^}]+\}/);
|
| 820 |
+
if (!m) {
|
| 821 |
+
JUDGE_TELEMETRY.failed++;
|
| 822 |
+
JUDGE_TELEMETRY.lastFailure = "JUDGE_EMPTY_OR_NON_JSON";
|
| 823 |
+
return null;
|
| 824 |
+
}
|
| 825 |
const scores = JSON.parse(m[0]);
|
| 826 |
for (const d of dims) {
|
| 827 |
+
if (typeof scores[d] !== "number") {
|
| 828 |
+
JUDGE_TELEMETRY.failed++;
|
| 829 |
+
JUDGE_TELEMETRY.lastFailure = "JUDGE_SCHEMA_MISMATCH";
|
| 830 |
+
return null;
|
| 831 |
+
}
|
| 832 |
scores[d] = Math.max(0, Math.min(1, +scores[d].toFixed(2)));
|
| 833 |
}
|
| 834 |
+
JUDGE_TELEMETRY.succeeded++;
|
| 835 |
+
JUDGE_TELEMETRY.lastFailure = null;
|
| 836 |
_JUDGE_CACHE.set(cacheKey, scores);
|
| 837 |
return scores;
|
| 838 |
+
} catch (error) {
|
| 839 |
+
JUDGE_TELEMETRY.failed++;
|
| 840 |
+
JUDGE_TELEMETRY.lastFailure = error?.name === "AbortError" ? "JUDGE_TIMEOUT" : "JUDGE_REQUEST_ERROR";
|
| 841 |
+
return null;
|
| 842 |
+
}
|
| 843 |
}
|
| 844 |
|
| 845 |
function tDir(id){
|
|
|
|
| 2581 |
runtime_input:{profile:"fixed-realistic-chat-v1",persona:BENCHMARK_PERSONA,negative_constraints:true,context_messages:BENCHMARK_CONTEXT.length},
|
| 2582 |
runner_prerequisites:{typescript_required:requiresTypeScript,typescript_bin:requiresTypeScript?TSC_BIN:null},
|
| 2583 |
sse_recovery:{resume:"Last-Event-ID",deduplicate_replayed_event_ids:true,max_reconnects:1,status_endpoint:"/api/agent/tasks/{taskId}/status",cancel_on_nonterminal_incomplete:true},
|
| 2584 |
+
semantic_judge:{enabled:F_JUDGE,provider:JUDGE_TELEMETRY.provider,model:JUDGE_TELEMETRY.model,requested:JUDGE_TELEMETRY.requested,succeeded:JUDGE_TELEMETRY.succeeded,failed:JUDGE_TELEMETRY.failed,cache_hits:JUDGE_TELEMETRY.cacheHits,last_failure:JUDGE_TELEMETRY.lastFailure},
|
| 2585 |
canonical_seed:"1337 (stesse domande per tutti gli agenti — usa --rotate per seed diverso)",
|
| 2586 |
coding:"enterprise: Acc(35%)+Stab(20%)+Auto(15%)+Perf(10%)+Spd(10%)+Cost(5%)+Tool(5%)",
|
| 2587 |
nonCoding:"content: Acc(40%)+Struct(20%)+Comp(15%)+Prec(10%)+Auto(5%)+Spd(5%)+Cost(5%)",
|