UNPKG

node-llm-test

Version:

Generate tests to evaluate the intelligence of large language models.

75 lines (74 loc) 2.47 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var randomfile_exports = {}; __export(randomfile_exports, { getRandomSelection: () => getRandomSelection, getRandomWords: () => getRandomWords }); module.exports = __toCommonJS(randomfile_exports); var import_node_fs = require("node:fs"); var import_node_readline = require("node:readline"); var import_random = require("./random"); const DICT_PATHS = ["/usr/share/dict/words", "/usr/dict/words"]; async function getRandomWords(count = 10, seed = 12345) { for (const path of DICT_PATHS) { try { const rp = (0, import_node_fs.realpathSync)(path); const words = await readAllWords(rp); return getRandomSelection(words, count, seed); } catch (error) { continue; } } throw new Error("No dictionary found on system"); } async function readAllWords(path) { const words = []; const p = new Promise((resolve, reject) => { const fileStream = (0, import_node_fs.createReadStream)(path); const rl = (0, import_node_readline.createInterface)({ input: fileStream, crlfDelay: Infinity }); rl.on("line", (line) => { const word = line.trim(); if (word.length < 8 && word.length > 2) { words.push(word); } }); rl.on("close", () => { resolve(words); }); const rej = () => { reject(); }; rl.on("error", rej); fileStream.on("error", rej); }); await p; return words; } function getRandomSelection(words, count, seed) { const rand = (0, import_random.mulberry32)(seed); const selected = []; for (let i = 0; i < count; i++) { const randomIndex = Math.floor(rand() * words.length); selected.push(words[randomIndex]); } return selected; }