zelk12 commited on
Commit
d7089de
·
verified ·
1 Parent(s): 6b566f7

Upload 3 files

Browse files
GPQA-mini/benchlocal.pack.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schemaVersion": 1,
3
+ "protocolVersion": 1,
4
+ "id": "GPQA-mini",
5
+ "name": "GPQA-Polyglot (45 задач STEM уровня PhD)",
6
+ "version": "1.0.0",
7
+ "description": "Сложный Google-Proof бенчмарк уровня аспирантуры (10 вариантов ответов A-J, случайный порог 10%): 15 RU, 15 EN и 15 MIX задач",
8
+ "entry": "./index.mjs",
9
+ "samplingDefaults": {
10
+ "temperature": 0.0
11
+ },
12
+ "capabilities": {
13
+ "tools": false,
14
+ "multiTurn": false,
15
+ "streamingProgress": false,
16
+ "verification": false
17
+ }
18
+ }
GPQA-mini/index.mjs ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
+
7
+ const manifestPath = fs.existsSync(path.join(__dirname, "benchlocal.pack.json"))
8
+ ? path.join(__dirname, "benchlocal.pack.json")
9
+ : path.join(__dirname, "benchlocal.pack.txt");
10
+
11
+ const scenariosPath = fs.existsSync(path.join(__dirname, "scenarios.json"))
12
+ ? path.join(__dirname, "scenarios.json")
13
+ : path.join(__dirname, "scenarios.txt");
14
+
15
+ function readJsonSafe(filePath, fallback) {
16
+ try {
17
+ if (fs.existsSync(filePath)) {
18
+ const raw = fs.readFileSync(filePath, "utf8").replace(/^\uFEFF/, "").trim();
19
+ return JSON.parse(raw);
20
+ }
21
+ } catch (err) {
22
+ console.error(`[GPQA-Polyglot] Ошибка чтения ${filePath}:`, err.message);
23
+ }
24
+ return fallback;
25
+ }
26
+
27
+ const defaultManifest = {
28
+ schemaVersion: 1,
29
+ protocolVersion: 1,
30
+ id: "GPQA-mini",
31
+ name: "GPQA-Polyglot (45 задач STEM уровня PhD)",
32
+ version: "1.0.0",
33
+ description: "Сложный Google-Proof бенчмарк уровня аспирантуры (10 вариантов ответов A-J, случайный порог 10%): 15 RU, 15 EN и 15 MIX задач",
34
+ entry: "./index.mjs", // ИСПРАВЛЕНО (было: entry": "./index.mjs",)
35
+ samplingDefaults: { temperature: 0.0 },
36
+ capabilities: { tools: false, multiTurn: false, streamingProgress: false, verification: false }
37
+ };
38
+
39
+ export const manifest = readJsonSafe(manifestPath, defaultManifest);
40
+
41
+ function loadScenarios() {
42
+ return readJsonSafe(scenariosPath, []);
43
+ }
44
+
45
+ export function listScenarios() {
46
+ return loadScenarios().map(s => ({
47
+ id: s.id,
48
+ name: s.name,
49
+ category: s.category || "Общие",
50
+ description: s.name
51
+ }));
52
+ }
53
+
54
+ export function getScenarios() {
55
+ return listScenarios();
56
+ }
57
+
58
+ /**
59
+ * Валидатор извлечения ответа:
60
+ * 1. Ищет конструкцию "Final Answer: (X)" или "Final Answer: X".
61
+ * 2. Если префикс опущен, ищет последнюю пару скобок с буквой: (X) или [X].
62
+ */
63
+ export function extractAnswer(rawText) {
64
+ const text = (rawText || "").trim();
65
+ if (!text) return null;
66
+
67
+ // Поддерживает как вариант со скобками: (A), так и без них: Final Answer: A
68
+ const pattern = /(?:final\s*(?:verdict|answer)|итоговый\s*(?:ответ|вердикт)|ответ)[\s:=]*[\[\(]?\s*([A-J])\s*[\]\)]?/gi;
69
+ const explicitMatches = Array.from(text.matchAll(pattern));
70
+ if (explicitMatches.length > 0) {
71
+ return explicitMatches[explicitMatches.length - 1][1].toUpperCase();
72
+ }
73
+
74
+ const bracketMatches = Array.from(text.matchAll(/[\[\(]([A-J])[\]\)]/g));
75
+ if (bracketMatches.length > 0) {
76
+ return bracketMatches[bracketMatches.length - 1][1].toUpperCase();
77
+ }
78
+
79
+ return null;
80
+ }
81
+
82
+ function resolveHelpers(context) {
83
+ if (context && typeof context.getRequiredProvider === "function") {
84
+ return context;
85
+ }
86
+ if (context?.helpers && typeof context.helpers.getRequiredProvider === "function") {
87
+ return context.helpers;
88
+ }
89
+ return {
90
+ getRequiredProvider(providerId) {
91
+ const providers = context?.providers || [];
92
+ const found = Array.isArray(providers)
93
+ ? providers.find((p) => p.id === providerId || p.provider === providerId)
94
+ : providers[providerId];
95
+ return found || { baseUrl: "http://127.0.0.1:11434/v1", apiKey: "none" };
96
+ },
97
+ getInferenceEndpoint(modelId) {
98
+ return context?.endpoints?.[modelId] || null;
99
+ }
100
+ };
101
+ }
102
+
103
+ export async function prepare(context) {
104
+ const helpers = resolveHelpers(context);
105
+
106
+ return {
107
+ async runScenario(input) {
108
+ const allScenarios = loadScenarios();
109
+ const scenario = allScenarios.find(s => s.id === input.scenario.id);
110
+ if (!scenario) {
111
+ return {
112
+ scenarioId: input.scenario.id,
113
+ status: "fail",
114
+ score: 0,
115
+ summary: "Сценарий не найден",
116
+ rawLog: "error=Scenario not found"
117
+ };
118
+ }
119
+
120
+ const provider = helpers.getRequiredProvider(input.model.provider, { enabledOnly: true });
121
+ const inference = helpers.getInferenceEndpoint ? helpers.getInferenceEndpoint(input.model.id) : null;
122
+
123
+ const rawBaseUrl = (inference && inference.status === "running" ? inference.baseUrl : provider?.baseUrl) || "http://127.0.0.1:11434/v1";
124
+ const baseUrl = rawBaseUrl.replace(/\/+$/, "");
125
+ const apiKey = provider?.apiKey || "none";
126
+
127
+ const requestBody = {
128
+ model: input.model.model,
129
+ messages: [{ role: "user", content: scenario.prompt }],
130
+ temperature: 0,
131
+ max_tokens: 4096
132
+ };
133
+
134
+ let text = "";
135
+ let rawResponseData = null;
136
+
137
+ try {
138
+ const response = await fetch(`${baseUrl}/chat/completions`, {
139
+ method: "POST",
140
+ headers: {
141
+ "Content-Type": "application/json",
142
+ Authorization: `Bearer ${apiKey}`
143
+ },
144
+ body: JSON.stringify(requestBody)
145
+ });
146
+
147
+ if (!response.ok) {
148
+ throw new Error(`HTTP ${response.status} ${response.statusText}`);
149
+ }
150
+
151
+ rawResponseData = await response.json();
152
+ text = (rawResponseData.choices?.[0]?.message?.content || "").trim();
153
+ } catch (err) {
154
+ return {
155
+ scenarioId: scenario.id,
156
+ status: "fail",
157
+ score: 0,
158
+ summary: `Ошибка API: ${err.message}`,
159
+ rawLog: `error=${err.message}`
160
+ };
161
+ }
162
+
163
+ const extracted = extractAnswer(text);
164
+ const passed = extracted === scenario.correct_answer.toUpperCase();
165
+
166
+ const rawLog = [
167
+ `model=${input.model.model}`,
168
+ `scenario=${scenario.id} ${scenario.name}`,
169
+ `category=${scenario.category}`,
170
+ `user_turn_1=${scenario.prompt}`,
171
+ `assistant_turn_1=${text}`,
172
+ `extracted_choice=${extracted || "NONE"}`,
173
+ `expected_choice=${scenario.correct_answer}`,
174
+ `verdict=${passed ? "pass" : "fail"}`,
175
+ `score=${passed ? 100 : 0}`,
176
+ `summary=${passed ? "Правильный ответ" : `Неверно (выбрано: ${extracted || 'ничего'}, ожидалось: ${scenario.correct_answer})`}`,
177
+ `\n--- RAW API RESPONSE ---`,
178
+ JSON.stringify(rawResponseData, null, 2)
179
+ ].join("\n");
180
+
181
+ return {
182
+ scenarioId: scenario.id,
183
+ status: passed ? "pass" : "fail",
184
+ score: passed ? 100 : 0,
185
+ summary: passed ? "Правильный ответ" : `Выбрано '${extracted || "нет"}', ожидалось '${scenario.correct_answer}'`,
186
+ rawLog: rawLog
187
+ };
188
+ },
189
+
190
+ async dispose() {}
191
+ };
192
+ }
193
+
194
+ export function scoreModelResults(results) {
195
+ const scored = results || [];
196
+ const allScenarios = loadScenarios();
197
+ const scenarioMap = new Map(allScenarios.map(s => [s.id, s]));
198
+
199
+ const total = scored.reduce((sum, r) => sum + (r.score || 0), 0);
200
+ const max = scored.length * 100;
201
+
202
+ const categoryStats = {};
203
+ for (const r of scored) {
204
+ const s = scenarioMap.get(r.scenarioId);
205
+ const cat = s?.category || "Общие";
206
+ if (!categoryStats[cat]) {
207
+ categoryStats[cat] = { total: 0, count: 0 };
208
+ }
209
+ categoryStats[cat].total += (r.score || 0);
210
+ categoryStats[cat].count += 1;
211
+ }
212
+
213
+ const categories = Object.entries(categoryStats).map(([name, stat]) => ({
214
+ name,
215
+ score: stat.count > 0 ? Math.round((stat.total / (stat.count * 100)) * 100) : 0
216
+ }));
217
+
218
+ return {
219
+ totalScore: max > 0 ? Math.round((total / max) * 100) : 0,
220
+ categories
221
+ };
222
+ }
223
+
224
+ export default {
225
+ manifest,
226
+ listScenarios,
227
+ getScenarios,
228
+ prepare,
229
+ createRuntime: prepare,
230
+ scoreModelResults
231
+ };
GPQA-mini/scenarios.json ADDED
The diff for this file is too large to render. See raw diff