cowqa / test-rapid.js
sapbot's picture
Upload test-rapid.js
7f76651 verified
Raw
History Blame Contribute Delete
1.82 kB
const fs = require("fs");
const readline = require("readline");
// Загружаем датасет
const dataset = JSON.parse(fs.readFileSync("dataset.json"));
// Формируем единый промпт
let prompt = `Answer the following multiple choice questions. For each question, output the number of the question followed by a dot and the letter of the correct answer (A, B, or C). Output one answer per line, in order from 1 to N.
`;
dataset.forEach((item, idx) => {
const num = idx + 1;
prompt += `${num}. ${item.question}\n`;
prompt += `A. ${item.A}\n`;
prompt += `B. ${item.B}\n`;
prompt += `C. ${item.C}\n\n`;
});
console.log(prompt);
console.log("=== PUT HERE AI RESPONSE: ===");
console.log("1.A");
console.log("2.B");
console.log("3.C");
console.log("...");
console.log("(Then enter Ctrl+D)\n");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
let llmResponse = "";
rl.on("line", (line) => {
llmResponse += line + "\n";
});
rl.on("close", () => {
const lines = llmResponse.split(/\r?\n/);
const answers = {};
for (const line of lines) {
const match = line.match(/^(\d+)\.\s*([ABC])$/i);
if (match) {
const qNum = parseInt(match[1], 10);
const answerLetter = match[2].toUpperCase();
answers[qNum] = answerLetter;
}
}
let correct = 0;
for (let i = 0; i < dataset.length; i++) {
const expected = dataset[i].correct;
const predicted = answers[i + 1];
if (predicted && predicted === expected) {
correct++;
}
}
console.log(`\nFinal CowQA-Rapid score: ${correct}/${dataset.length} (${Math.round((correct / dataset.length) * 100 * 100) / 100})%`);
process.exit(0);
});