vitest-evals 0.0.0 → 0.1.0
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.
- package/README.md +5 -5
- package/dist/index.d.mts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +104 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +80 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +12 -2
- package/biome.json +0 -38
- package/src/index.ts +0 -81
- package/tsconfig.json +0 -113
- package/tsup.config.ts +0 -10
package/README.md
CHANGED
|
@@ -9,8 +9,7 @@ This is heavily inspired by [Evalite](https://www.evalite.dev/), but opts for a
|
|
|
9
9
|
### Dedicated Test Suites
|
|
10
10
|
|
|
11
11
|
```javascript
|
|
12
|
-
// Inspired by the `evalite` API
|
|
13
|
-
// TODO: decide one way or another if this is too limiting.
|
|
12
|
+
// Inspired by the `evalite` API
|
|
14
13
|
describeEval("my evals", {
|
|
15
14
|
data: async () => {
|
|
16
15
|
return [
|
|
@@ -23,8 +22,9 @@ describeEval("my evals", {
|
|
|
23
22
|
const output = 'Paris';
|
|
24
23
|
return output;
|
|
25
24
|
},
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
scorers: [checkFactuality],
|
|
26
|
+
threshold: 0.8,
|
|
27
|
+
// timeout: 10000,
|
|
28
28
|
})
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -104,4 +104,4 @@ export const checkFactuality = async (opts: {
|
|
|
104
104
|
},
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
|
-
```
|
|
107
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as vitest from 'vitest';
|
|
2
|
+
|
|
3
|
+
type TaskFn = (input: string) => Promise<string>;
|
|
4
|
+
type Score = {
|
|
5
|
+
score: number | null;
|
|
6
|
+
metadata?: {
|
|
7
|
+
rationale: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type ScoreFn = (opts: {
|
|
11
|
+
input: string;
|
|
12
|
+
expected: string;
|
|
13
|
+
output: string;
|
|
14
|
+
}) => Promise<Score>;
|
|
15
|
+
type ToEval<R = unknown> = (expected: string, taskFn: TaskFn, scoreFn: ScoreFn, threshold?: number) => Promise<R>;
|
|
16
|
+
interface EvalMatchers<R = unknown> {
|
|
17
|
+
toEval: ToEval<R>;
|
|
18
|
+
}
|
|
19
|
+
declare module "vitest" {
|
|
20
|
+
interface Assertion<T = any> extends EvalMatchers<T> {
|
|
21
|
+
}
|
|
22
|
+
interface AsymmetricMatchersContaining extends EvalMatchers {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
declare function describeEval(name: string, { data, task, scorers, threshold, timeout, }: {
|
|
26
|
+
data: () => Promise<{
|
|
27
|
+
input: string;
|
|
28
|
+
expected: string;
|
|
29
|
+
}[]>;
|
|
30
|
+
task: TaskFn;
|
|
31
|
+
scorers: ScoreFn[];
|
|
32
|
+
threshold?: number | null;
|
|
33
|
+
timeout?: number;
|
|
34
|
+
}): vitest.SuiteCollector<object>;
|
|
35
|
+
|
|
36
|
+
export { type EvalMatchers, type Score, type ScoreFn, type TaskFn, type ToEval, describeEval };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as vitest from 'vitest';
|
|
2
|
+
|
|
3
|
+
type TaskFn = (input: string) => Promise<string>;
|
|
4
|
+
type Score = {
|
|
5
|
+
score: number | null;
|
|
6
|
+
metadata?: {
|
|
7
|
+
rationale: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type ScoreFn = (opts: {
|
|
11
|
+
input: string;
|
|
12
|
+
expected: string;
|
|
13
|
+
output: string;
|
|
14
|
+
}) => Promise<Score>;
|
|
15
|
+
type ToEval<R = unknown> = (expected: string, taskFn: TaskFn, scoreFn: ScoreFn, threshold?: number) => Promise<R>;
|
|
16
|
+
interface EvalMatchers<R = unknown> {
|
|
17
|
+
toEval: ToEval<R>;
|
|
18
|
+
}
|
|
19
|
+
declare module "vitest" {
|
|
20
|
+
interface Assertion<T = any> extends EvalMatchers<T> {
|
|
21
|
+
}
|
|
22
|
+
interface AsymmetricMatchersContaining extends EvalMatchers {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
declare function describeEval(name: string, { data, task, scorers, threshold, timeout, }: {
|
|
26
|
+
data: () => Promise<{
|
|
27
|
+
input: string;
|
|
28
|
+
expected: string;
|
|
29
|
+
}[]>;
|
|
30
|
+
task: TaskFn;
|
|
31
|
+
scorers: ScoreFn[];
|
|
32
|
+
threshold?: number | null;
|
|
33
|
+
timeout?: number;
|
|
34
|
+
}): vitest.SuiteCollector<object>;
|
|
35
|
+
|
|
36
|
+
export { type EvalMatchers, type Score, type ScoreFn, type TaskFn, type ToEval, describeEval };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/index.ts
|
|
41
|
+
var index_exports = {};
|
|
42
|
+
__export(index_exports, {
|
|
43
|
+
describeEval: () => describeEval
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(index_exports);
|
|
46
|
+
var import_vitest = require("vitest");
|
|
47
|
+
var import_vitest2 = require("vitest");
|
|
48
|
+
import_vitest.expect.extend({
|
|
49
|
+
toEval: function toEval(input, expected, taskFn, scoreFn, threshold = 1) {
|
|
50
|
+
return __async(this, null, function* () {
|
|
51
|
+
var _a;
|
|
52
|
+
const { isNot } = this;
|
|
53
|
+
const output = yield taskFn(input);
|
|
54
|
+
const result = yield scoreFn({ input, expected, output });
|
|
55
|
+
return {
|
|
56
|
+
pass: ((_a = result.score) != null ? _a : 0) >= threshold,
|
|
57
|
+
message: () => `Score: ${result.score} ${isNot ? "<" : ">"} ${threshold}
|
|
58
|
+
${result.metadata ? `Rationale: ${result.metadata.rationale}` : ""}`
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
function describeEval(name, {
|
|
64
|
+
data,
|
|
65
|
+
task,
|
|
66
|
+
scorers,
|
|
67
|
+
threshold = 1,
|
|
68
|
+
// increase default test timeout as 5s is usually not enough for
|
|
69
|
+
// a single factuality check
|
|
70
|
+
timeout = 1e4
|
|
71
|
+
}) {
|
|
72
|
+
return (0, import_vitest.describe)(name, () => __async(this, null, function* () {
|
|
73
|
+
for (const { input, expected } of yield data()) {
|
|
74
|
+
(0, import_vitest.it)(
|
|
75
|
+
input,
|
|
76
|
+
() => __async(this, null, function* () {
|
|
77
|
+
const output = yield task(input);
|
|
78
|
+
const scores = yield Promise.all(
|
|
79
|
+
scorers.map((scorer) => scorer({ input, expected, output }))
|
|
80
|
+
);
|
|
81
|
+
const avgScore = scores.reduce((acc, s) => {
|
|
82
|
+
var _a;
|
|
83
|
+
return acc + ((_a = s.score) != null ? _a : 0);
|
|
84
|
+
}, 0) / scores.length;
|
|
85
|
+
if (threshold) {
|
|
86
|
+
(0, import_vitest.assert)(
|
|
87
|
+
avgScore >= threshold,
|
|
88
|
+
`Score: ${avgScore} below threshold: ${threshold}
|
|
89
|
+
Output: ${output}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
{
|
|
94
|
+
timeout
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
describeEval
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { assert, describe, expect, it } from \"vitest\";\nimport \"vitest\";\n\nexport type TaskFn = (input: string) => Promise<string>;\n\nexport type Score = {\n score: number | null;\n metadata?: {\n rationale: string;\n };\n};\n\nexport type ScoreFn = (opts: {\n input: string;\n expected: string;\n output: string;\n}) => Promise<Score>;\n\nexport type ToEval<R = unknown> = (\n expected: string,\n taskFn: TaskFn,\n scoreFn: ScoreFn,\n threshold?: number,\n) => Promise<R>;\n\nexport interface EvalMatchers<R = unknown> {\n toEval: ToEval<R>;\n}\n\ndeclare module \"vitest\" {\n interface Assertion<T = any> extends EvalMatchers<T> {}\n interface AsymmetricMatchersContaining extends EvalMatchers {}\n}\n\nexpect.extend({\n toEval: async function toEval(\n input: string,\n expected: string,\n taskFn: TaskFn,\n scoreFn: ScoreFn,\n threshold = 1.0,\n ) {\n const { isNot } = this;\n\n const output = await taskFn(input);\n\n const result = await scoreFn({ input, expected, output });\n\n return {\n pass: (result.score ?? 0) >= threshold,\n message: () =>\n `Score: ${result.score} ${isNot ? \"<\" : \">\"} ${threshold}\\n${\n result.metadata ? `Rationale: ${result.metadata.rationale}` : \"\"\n }`,\n };\n },\n});\n\nexport function describeEval(\n name: string,\n {\n data,\n task,\n scorers,\n threshold = 1.0,\n // increase default test timeout as 5s is usually not enough for\n // a single factuality check\n timeout = 10000,\n }: {\n data: () => Promise<{ input: string; expected: string }[]>;\n task: TaskFn;\n scorers: ScoreFn[];\n threshold?: number | null;\n timeout?: number;\n },\n) {\n return describe(name, async () => {\n // TODO: should data just be a generator?\n for (const { input, expected } of await data()) {\n it(\n input,\n async () => {\n const output = await task(input);\n\n const scores = await Promise.all(\n scorers.map((scorer) => scorer({ input, expected, output })),\n );\n\n const avgScore =\n scores.reduce((acc, s) => acc + (s.score ?? 0), 0) / scores.length;\n if (threshold) {\n assert(\n avgScore >= threshold,\n `Score: ${avgScore} below threshold: ${threshold}\\nOutput: ${output}`,\n );\n }\n },\n {\n timeout,\n },\n );\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6C;AAC7C,IAAAA,iBAAO;AAiCP,qBAAO,OAAO;AAAA,EACZ,QAAQ,SAAe,OACrB,OACA,UACA,QACA,SACA,YAAY,GACZ;AAAA;AAzCJ;AA0CI,YAAM,EAAE,MAAM,IAAI;AAElB,YAAM,SAAS,MAAM,OAAO,KAAK;AAEjC,YAAM,SAAS,MAAM,QAAQ,EAAE,OAAO,UAAU,OAAO,CAAC;AAExD,aAAO;AAAA,QACL,QAAO,YAAO,UAAP,YAAgB,MAAM;AAAA,QAC7B,SAAS,MACP,UAAU,OAAO,KAAK,IAAI,QAAQ,MAAM,GAAG,IAAI,SAAS;AAAA,EACtD,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS,KAAK,EAChE;AAAA,MACJ;AAAA,IACF;AAAA;AACF,CAAC;AAEM,SAAS,aACd,MACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA;AAAA;AAAA,EAGZ,UAAU;AACZ,GAOA;AACA,aAAO,wBAAS,MAAM,MAAY;AAEhC,eAAW,EAAE,OAAO,SAAS,KAAK,MAAM,KAAK,GAAG;AAC9C;AAAA,QACE;AAAA,QACA,MAAY;AACV,gBAAM,SAAS,MAAM,KAAK,KAAK;AAE/B,gBAAM,SAAS,MAAM,QAAQ;AAAA,YAC3B,QAAQ,IAAI,CAAC,WAAW,OAAO,EAAE,OAAO,UAAU,OAAO,CAAC,CAAC;AAAA,UAC7D;AAEA,gBAAM,WACJ,OAAO,OAAO,CAAC,KAAK,MAAG;AAzFnC;AAyFsC,2BAAO,OAAE,UAAF,YAAW;AAAA,aAAI,CAAC,IAAI,OAAO;AAC9D,cAAI,WAAW;AACb;AAAA,cACE,YAAY;AAAA,cACZ,UAAU,QAAQ,qBAAqB,SAAS;AAAA,UAAa,MAAM;AAAA,YACrE;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,UACE;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,EAAC;AACH;","names":["import_vitest"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
import { assert, describe, expect, it } from "vitest";
|
|
24
|
+
import "vitest";
|
|
25
|
+
expect.extend({
|
|
26
|
+
toEval: function toEval(input, expected, taskFn, scoreFn, threshold = 1) {
|
|
27
|
+
return __async(this, null, function* () {
|
|
28
|
+
var _a;
|
|
29
|
+
const { isNot } = this;
|
|
30
|
+
const output = yield taskFn(input);
|
|
31
|
+
const result = yield scoreFn({ input, expected, output });
|
|
32
|
+
return {
|
|
33
|
+
pass: ((_a = result.score) != null ? _a : 0) >= threshold,
|
|
34
|
+
message: () => `Score: ${result.score} ${isNot ? "<" : ">"} ${threshold}
|
|
35
|
+
${result.metadata ? `Rationale: ${result.metadata.rationale}` : ""}`
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function describeEval(name, {
|
|
41
|
+
data,
|
|
42
|
+
task,
|
|
43
|
+
scorers,
|
|
44
|
+
threshold = 1,
|
|
45
|
+
// increase default test timeout as 5s is usually not enough for
|
|
46
|
+
// a single factuality check
|
|
47
|
+
timeout = 1e4
|
|
48
|
+
}) {
|
|
49
|
+
return describe(name, () => __async(this, null, function* () {
|
|
50
|
+
for (const { input, expected } of yield data()) {
|
|
51
|
+
it(
|
|
52
|
+
input,
|
|
53
|
+
() => __async(this, null, function* () {
|
|
54
|
+
const output = yield task(input);
|
|
55
|
+
const scores = yield Promise.all(
|
|
56
|
+
scorers.map((scorer) => scorer({ input, expected, output }))
|
|
57
|
+
);
|
|
58
|
+
const avgScore = scores.reduce((acc, s) => {
|
|
59
|
+
var _a;
|
|
60
|
+
return acc + ((_a = s.score) != null ? _a : 0);
|
|
61
|
+
}, 0) / scores.length;
|
|
62
|
+
if (threshold) {
|
|
63
|
+
assert(
|
|
64
|
+
avgScore >= threshold,
|
|
65
|
+
`Score: ${avgScore} below threshold: ${threshold}
|
|
66
|
+
Output: ${output}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
{
|
|
71
|
+
timeout
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
describeEval
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { assert, describe, expect, it } from \"vitest\";\nimport \"vitest\";\n\nexport type TaskFn = (input: string) => Promise<string>;\n\nexport type Score = {\n score: number | null;\n metadata?: {\n rationale: string;\n };\n};\n\nexport type ScoreFn = (opts: {\n input: string;\n expected: string;\n output: string;\n}) => Promise<Score>;\n\nexport type ToEval<R = unknown> = (\n expected: string,\n taskFn: TaskFn,\n scoreFn: ScoreFn,\n threshold?: number,\n) => Promise<R>;\n\nexport interface EvalMatchers<R = unknown> {\n toEval: ToEval<R>;\n}\n\ndeclare module \"vitest\" {\n interface Assertion<T = any> extends EvalMatchers<T> {}\n interface AsymmetricMatchersContaining extends EvalMatchers {}\n}\n\nexpect.extend({\n toEval: async function toEval(\n input: string,\n expected: string,\n taskFn: TaskFn,\n scoreFn: ScoreFn,\n threshold = 1.0,\n ) {\n const { isNot } = this;\n\n const output = await taskFn(input);\n\n const result = await scoreFn({ input, expected, output });\n\n return {\n pass: (result.score ?? 0) >= threshold,\n message: () =>\n `Score: ${result.score} ${isNot ? \"<\" : \">\"} ${threshold}\\n${\n result.metadata ? `Rationale: ${result.metadata.rationale}` : \"\"\n }`,\n };\n },\n});\n\nexport function describeEval(\n name: string,\n {\n data,\n task,\n scorers,\n threshold = 1.0,\n // increase default test timeout as 5s is usually not enough for\n // a single factuality check\n timeout = 10000,\n }: {\n data: () => Promise<{ input: string; expected: string }[]>;\n task: TaskFn;\n scorers: ScoreFn[];\n threshold?: number | null;\n timeout?: number;\n },\n) {\n return describe(name, async () => {\n // TODO: should data just be a generator?\n for (const { input, expected } of await data()) {\n it(\n input,\n async () => {\n const output = await task(input);\n\n const scores = await Promise.all(\n scorers.map((scorer) => scorer({ input, expected, output })),\n );\n\n const avgScore =\n scores.reduce((acc, s) => acc + (s.score ?? 0), 0) / scores.length;\n if (threshold) {\n assert(\n avgScore >= threshold,\n `Score: ${avgScore} below threshold: ${threshold}\\nOutput: ${output}`,\n );\n }\n },\n {\n timeout,\n },\n );\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,QAAQ,UAAU,QAAQ,UAAU;AAC7C,OAAO;AAiCP,OAAO,OAAO;AAAA,EACZ,QAAQ,SAAe,OACrB,OACA,UACA,QACA,SACA,YAAY,GACZ;AAAA;AAzCJ;AA0CI,YAAM,EAAE,MAAM,IAAI;AAElB,YAAM,SAAS,MAAM,OAAO,KAAK;AAEjC,YAAM,SAAS,MAAM,QAAQ,EAAE,OAAO,UAAU,OAAO,CAAC;AAExD,aAAO;AAAA,QACL,QAAO,YAAO,UAAP,YAAgB,MAAM;AAAA,QAC7B,SAAS,MACP,UAAU,OAAO,KAAK,IAAI,QAAQ,MAAM,GAAG,IAAI,SAAS;AAAA,EACtD,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS,KAAK,EAChE;AAAA,MACJ;AAAA,IACF;AAAA;AACF,CAAC;AAEM,SAAS,aACd,MACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA;AAAA;AAAA,EAGZ,UAAU;AACZ,GAOA;AACA,SAAO,SAAS,MAAM,MAAY;AAEhC,eAAW,EAAE,OAAO,SAAS,KAAK,MAAM,KAAK,GAAG;AAC9C;AAAA,QACE;AAAA,QACA,MAAY;AACV,gBAAM,SAAS,MAAM,KAAK,KAAK;AAE/B,gBAAM,SAAS,MAAM,QAAQ;AAAA,YAC3B,QAAQ,IAAI,CAAC,WAAW,OAAO,EAAE,OAAO,UAAU,OAAO,CAAC,CAAC;AAAA,UAC7D;AAEA,gBAAM,WACJ,OAAO,OAAO,CAAC,KAAK,MAAG;AAzFnC;AAyFsC,2BAAO,OAAE,UAAF,YAAW;AAAA,aAAI,CAAC,IAAI,OAAO;AAC9D,cAAI,WAAW;AACb;AAAA,cACE,YAAY;AAAA,cACZ,UAAU,QAAQ,qBAAqB,SAAS;AAAA,UAAa,MAAM;AAAA,YACrE;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,UACE;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,EAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-evals",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"import": "./dist/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
6
16
|
"scripts": {
|
|
7
17
|
"build": "tsup",
|
|
8
18
|
"format": "biome format --write",
|
package/biome.json
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
|
3
|
-
"organizeImports": {
|
|
4
|
-
"enabled": true
|
|
5
|
-
},
|
|
6
|
-
"files": {
|
|
7
|
-
"ignore": []
|
|
8
|
-
},
|
|
9
|
-
"vcs": {
|
|
10
|
-
"enabled": true,
|
|
11
|
-
"clientKind": "git",
|
|
12
|
-
"useIgnoreFile": true
|
|
13
|
-
},
|
|
14
|
-
"linter": {
|
|
15
|
-
"enabled": true,
|
|
16
|
-
"rules": {
|
|
17
|
-
"recommended": true,
|
|
18
|
-
"suspicious": {
|
|
19
|
-
"noExplicitAny": "off",
|
|
20
|
-
"noDebugger": "off",
|
|
21
|
-
"noConsoleLog": "off",
|
|
22
|
-
"noConfusingVoidType": "off"
|
|
23
|
-
},
|
|
24
|
-
"style": {
|
|
25
|
-
"noNonNullAssertion": "off",
|
|
26
|
-
"noUnusedTemplateLiteral": "off"
|
|
27
|
-
},
|
|
28
|
-
"security": {
|
|
29
|
-
"noDangerouslySetInnerHtml": "off"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"formatter": {
|
|
34
|
-
"enabled": true,
|
|
35
|
-
"indentWidth": 2,
|
|
36
|
-
"indentStyle": "space"
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import "vitest";
|
|
3
|
-
|
|
4
|
-
export type TaskFn = (input: string) => Promise<string>;
|
|
5
|
-
|
|
6
|
-
type Score = {
|
|
7
|
-
score: number | null;
|
|
8
|
-
metadata?: {
|
|
9
|
-
rationale: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// We're intentionally matching the API of evalite here
|
|
14
|
-
export type ScoreFn = (
|
|
15
|
-
input: string,
|
|
16
|
-
expected: string,
|
|
17
|
-
output: string,
|
|
18
|
-
) => Promise<Score>;
|
|
19
|
-
|
|
20
|
-
export type ToEval<R = unknown> = (
|
|
21
|
-
expected: string,
|
|
22
|
-
taskFn: TaskFn,
|
|
23
|
-
scoreFn: ScoreFn,
|
|
24
|
-
threshold?: number,
|
|
25
|
-
) => Promise<R>;
|
|
26
|
-
|
|
27
|
-
export interface EvalMatchers<R = unknown> {
|
|
28
|
-
toEval: ToEval<R>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
declare module "vitest" {
|
|
32
|
-
interface Assertion<T = any> extends EvalMatchers<T> {}
|
|
33
|
-
interface AsymmetricMatchersContaining extends EvalMatchers {}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function toEval(
|
|
37
|
-
input: string,
|
|
38
|
-
expected: string,
|
|
39
|
-
taskFn: TaskFn,
|
|
40
|
-
scoreFn: ScoreFn,
|
|
41
|
-
threshold = 1.0,
|
|
42
|
-
) {
|
|
43
|
-
const output = await taskFn(input);
|
|
44
|
-
|
|
45
|
-
const result = await scoreFn(input, expected, output);
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
pass: (result.score ?? 0) >= threshold,
|
|
49
|
-
message: () =>
|
|
50
|
-
`Score: ${result.score}\n${result.metadata ? `Rationale: ${result.metadata.rationale}` : ""}`,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
expect.extend({ toEval });
|
|
55
|
-
|
|
56
|
-
// XXX: This is very similar to the `evalite` API, but ScoreFn is currently
|
|
57
|
-
// a different signature.
|
|
58
|
-
export function describeEval(
|
|
59
|
-
name: string,
|
|
60
|
-
{
|
|
61
|
-
data,
|
|
62
|
-
task,
|
|
63
|
-
scorer,
|
|
64
|
-
threshold = 1.0,
|
|
65
|
-
}: {
|
|
66
|
-
data: () => Promise<{ input: string; expected: string }[]>;
|
|
67
|
-
task: TaskFn;
|
|
68
|
-
scorer: ScoreFn;
|
|
69
|
-
threshold?: number;
|
|
70
|
-
},
|
|
71
|
-
) {
|
|
72
|
-
return describe(name, async () => {
|
|
73
|
-
// TODO: should data just be a generator?
|
|
74
|
-
for (const { input, expected } of await data()) {
|
|
75
|
-
it(input, async () => {
|
|
76
|
-
const result = await task(input);
|
|
77
|
-
expect(result).toEval(expected, task, scorer, threshold);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Projects */
|
|
6
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
-
|
|
13
|
-
/* Language and Environment */
|
|
14
|
-
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
15
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
-
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
-
// "libReplacement": true, /* Enable lib replacement. */
|
|
18
|
-
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
19
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
-
|
|
28
|
-
/* Modules */
|
|
29
|
-
"module": "commonjs" /* Specify what module code is generated. */,
|
|
30
|
-
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
31
|
-
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
32
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
33
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
34
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
35
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
36
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
37
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
38
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
39
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
40
|
-
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
|
41
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
42
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
43
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
44
|
-
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
45
|
-
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
46
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
47
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
48
|
-
|
|
49
|
-
/* JavaScript Support */
|
|
50
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
51
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
52
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
53
|
-
|
|
54
|
-
/* Emit */
|
|
55
|
-
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
56
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
57
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
58
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
59
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
60
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
62
|
-
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
63
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
64
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
65
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
66
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
67
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
68
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
69
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
70
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
71
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
72
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
73
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
74
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
75
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
76
|
-
|
|
77
|
-
/* Interop Constraints */
|
|
78
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
79
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
80
|
-
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
81
|
-
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
|
82
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
83
|
-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
84
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
85
|
-
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
86
|
-
|
|
87
|
-
/* Type Checking */
|
|
88
|
-
"strict": true /* Enable all strict type-checking options. */,
|
|
89
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
90
|
-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
91
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
92
|
-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
93
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
94
|
-
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
95
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
96
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
97
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
98
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
99
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
100
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
101
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
102
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
103
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
104
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
105
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
106
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
107
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
108
|
-
|
|
109
|
-
/* Completeness */
|
|
110
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
111
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
112
|
-
}
|
|
113
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsup";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: ["src/index.ts"],
|
|
5
|
-
format: ["cjs", "esm"], // Build for commonJS and ESmodules
|
|
6
|
-
dts: true, // Generate declaration file (.d.ts)
|
|
7
|
-
splitting: false,
|
|
8
|
-
sourcemap: true,
|
|
9
|
-
clean: true,
|
|
10
|
-
});
|