@eidentic/bench 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,98 @@
1
+ // src/lme-loader.ts
2
+ import { readFile, stat } from "node:fs/promises";
3
+ var LONGMEMEVAL_SOURCE = {
4
+ url: "https://huggingface.co/datasets/xiaowu0162/longmemeval",
5
+ snapshotSha: "2ec2a557f339b6c0369619b1ed5793734cc87533",
6
+ file: "longmemeval_s",
7
+ license: "MIT"
8
+ };
9
+ var DEFAULT_MAX_BYTES = 512 * 1024 * 1024;
10
+ async function assertFileSize(filePath, maxBytes) {
11
+ let fileSize;
12
+ try {
13
+ const s = await stat(filePath);
14
+ fileSize = s.size;
15
+ } catch (err) {
16
+ throw new Error(
17
+ `bench loader: cannot stat file "${filePath}": ${err.message}`
18
+ );
19
+ }
20
+ if (fileSize > maxBytes) {
21
+ const mb = (fileSize / (1024 * 1024)).toFixed(1);
22
+ const capMb = (maxBytes / (1024 * 1024)).toFixed(0);
23
+ throw new Error(
24
+ `bench loader: file "${filePath}" is ${mb} MiB, which exceeds the ${capMb} MiB cap. Pass a larger maxBytes option if this is intentional.`
25
+ );
26
+ }
27
+ }
28
+ function parseLmeDateTimeString(raw) {
29
+ if (!raw) return 0;
30
+ const cleaned = raw.replace(/\s*\([A-Za-z]+\)\s*/, " ").trim();
31
+ const iso = cleaned.replace(/^(\d{4})\/(\d{2})\/(\d{2})/, "$1-$2-$3");
32
+ const ms = Date.parse(iso);
33
+ if (Number.isNaN(ms)) return 0;
34
+ return ms;
35
+ }
36
+ function extractBaseType(rawType) {
37
+ if (rawType.endsWith("_abs")) {
38
+ return rawType.slice(0, -4);
39
+ }
40
+ return rawType;
41
+ }
42
+ function parseSession(id, dateTime, rawTurns) {
43
+ const turns = rawTurns.map((t) => ({
44
+ role: t.role === "assistant" ? "assistant" : "user",
45
+ content: t.content ?? "",
46
+ hasAnswer: t.has_answer === true
47
+ }));
48
+ return {
49
+ id,
50
+ dateTime,
51
+ dateTimeMs: parseLmeDateTimeString(dateTime),
52
+ turns
53
+ };
54
+ }
55
+ async function loadLongMemEval(jsonPath, opts) {
56
+ await assertFileSize(jsonPath, opts?.maxBytes ?? DEFAULT_MAX_BYTES);
57
+ const raw = JSON.parse(await readFile(jsonPath, "utf-8"));
58
+ if (!Array.isArray(raw)) {
59
+ throw new Error(
60
+ `bench loader: expected the LongMemEval JSON root to be an array, but got ${typeof raw}. Did you pass the correct file?`
61
+ );
62
+ }
63
+ const rawQuestions = raw;
64
+ const questions = rawQuestions.map((q, i) => {
65
+ const id = q.question_id ?? String(i);
66
+ const rawType = q.question_type ?? "single-session-user";
67
+ const baseType = extractBaseType(rawType);
68
+ const isAbstention = rawType.endsWith("_abs");
69
+ const rawSessions = Array.isArray(q.haystack_sessions) ? q.haystack_sessions : [];
70
+ const dates = Array.isArray(q.haystack_dates) ? q.haystack_dates : [];
71
+ const sessionIds = Array.isArray(q.haystack_session_ids) ? q.haystack_session_ids : [];
72
+ const sessions = rawSessions.map((turns, idx) => {
73
+ const sessId = sessionIds[idx] ?? `sess-${idx}`;
74
+ const dateTime = dates[idx] ?? "";
75
+ return parseSession(sessId, dateTime, Array.isArray(turns) ? turns : []);
76
+ });
77
+ sessions.sort((a, b) => a.dateTimeMs - b.dateTimeMs);
78
+ return {
79
+ id,
80
+ type: rawType,
81
+ baseType,
82
+ isAbstention,
83
+ question: q.question ?? "",
84
+ answer: q.answer ?? "",
85
+ questionDate: q.question_date ?? "",
86
+ questionDateMs: parseLmeDateTimeString(q.question_date ?? ""),
87
+ sessions,
88
+ answerSessionIds: Array.isArray(q.answer_session_ids) ? q.answer_session_ids : []
89
+ };
90
+ });
91
+ return { questions };
92
+ }
93
+
94
+ export {
95
+ LONGMEMEVAL_SOURCE,
96
+ parseLmeDateTimeString,
97
+ loadLongMemEval
98
+ };