@zukhruf/evals 0.0.0-stage → 0.8.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.
- package/LICENSE +21 -0
- package/NOTICE +82 -0
- package/README.md +528 -2
- package/dist/aggregation/counts.d.ts +11 -0
- package/dist/aggregation/counts.d.ts.map +1 -0
- package/dist/aggregation/counts.js +14 -0
- package/dist/aggregation/counts.js.map +1 -0
- package/dist/aggregation/f1-ratio.d.ts +8 -0
- package/dist/aggregation/f1-ratio.d.ts.map +1 -0
- package/dist/aggregation/f1-ratio.js +24 -0
- package/dist/aggregation/f1-ratio.js.map +1 -0
- package/dist/aggregation/ratio-of-sums.d.ts +8 -0
- package/dist/aggregation/ratio-of-sums.d.ts.map +1 -0
- package/dist/aggregation/ratio-of-sums.js +21 -0
- package/dist/aggregation/ratio-of-sums.js.map +1 -0
- package/dist/aggregation/ratio.d.ts +8 -0
- package/dist/aggregation/ratio.d.ts.map +1 -0
- package/dist/aggregation/ratio.js +20 -0
- package/dist/aggregation/ratio.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/promptfoo/assertion-module.d.ts +23 -0
- package/dist/promptfoo/assertion-module.d.ts.map +1 -0
- package/dist/promptfoo/assertion-module.js +45 -0
- package/dist/promptfoo/assertion-module.js.map +1 -0
- package/dist/promptfoo/index.d.ts +3 -0
- package/dist/promptfoo/index.d.ts.map +1 -0
- package/dist/promptfoo/index.js +3 -0
- package/dist/promptfoo/index.js.map +1 -0
- package/dist/promptfoo/promptfoo-assertion.d.ts +18 -0
- package/dist/promptfoo/promptfoo-assertion.d.ts.map +1 -0
- package/dist/promptfoo/promptfoo-assertion.js +31 -0
- package/dist/promptfoo/promptfoo-assertion.js.map +1 -0
- package/dist/scorers/at-least.d.ts +9 -0
- package/dist/scorers/at-least.d.ts.map +1 -0
- package/dist/scorers/at-least.js +18 -0
- package/dist/scorers/at-least.js.map +1 -0
- package/dist/scorers/f1.d.ts +9 -0
- package/dist/scorers/f1.d.ts.map +1 -0
- package/dist/scorers/f1.js +12 -0
- package/dist/scorers/f1.js.map +1 -0
- package/dist/scorers/gate.d.ts +7 -0
- package/dist/scorers/gate.d.ts.map +1 -0
- package/dist/scorers/gate.js +10 -0
- package/dist/scorers/gate.js.map +1 -0
- package/dist/scorers/matches.d.ts +5 -0
- package/dist/scorers/matches.d.ts.map +1 -0
- package/dist/scorers/matches.js +2 -0
- package/dist/scorers/matches.js.map +1 -0
- package/dist/scorers/mean-of.d.ts +8 -0
- package/dist/scorers/mean-of.d.ts.map +1 -0
- package/dist/scorers/mean-of.js +15 -0
- package/dist/scorers/mean-of.js.map +1 -0
- package/dist/scorers/penalized.d.ts +9 -0
- package/dist/scorers/penalized.d.ts.map +1 -0
- package/dist/scorers/penalized.js +28 -0
- package/dist/scorers/penalized.js.map +1 -0
- package/dist/scorers/penalty.d.ts +7 -0
- package/dist/scorers/penalty.d.ts.map +1 -0
- package/dist/scorers/penalty.js +11 -0
- package/dist/scorers/penalty.js.map +1 -0
- package/dist/scorers/precision.d.ts +9 -0
- package/dist/scorers/precision.d.ts.map +1 -0
- package/dist/scorers/precision.js +13 -0
- package/dist/scorers/precision.js.map +1 -0
- package/dist/scorers/recall.d.ts +9 -0
- package/dist/scorers/recall.d.ts.map +1 -0
- package/dist/scorers/recall.js +13 -0
- package/dist/scorers/recall.js.map +1 -0
- package/dist/scorers/sample-averaged.d.ts +10 -0
- package/dist/scorers/sample-averaged.d.ts.map +1 -0
- package/dist/scorers/sample-averaged.js +17 -0
- package/dist/scorers/sample-averaged.js.map +1 -0
- package/dist/scorers/scorer.d.ts +5 -0
- package/dist/scorers/scorer.d.ts.map +1 -0
- package/dist/scorers/scorer.js +2 -0
- package/dist/scorers/scorer.js.map +1 -0
- package/dist/scorers/shortfall-penalty.d.ts +11 -0
- package/dist/scorers/shortfall-penalty.d.ts.map +1 -0
- package/dist/scorers/shortfall-penalty.js +25 -0
- package/dist/scorers/shortfall-penalty.js.map +1 -0
- package/dist/scoring/bootstrap.d.ts +16 -0
- package/dist/scoring/bootstrap.d.ts.map +1 -0
- package/dist/scoring/bootstrap.js +31 -0
- package/dist/scoring/bootstrap.js.map +1 -0
- package/dist/scoring/scorecard-scorer.d.ts +11 -0
- package/dist/scoring/scorecard-scorer.d.ts.map +1 -0
- package/dist/scoring/scorecard-scorer.js +2 -0
- package/dist/scoring/scorecard-scorer.js.map +1 -0
- package/dist/scoring/scorecard.d.ts +15 -0
- package/dist/scoring/scorecard.d.ts.map +1 -0
- package/dist/scoring/scorecard.js +2 -0
- package/dist/scoring/scorecard.js.map +1 -0
- package/dist/scoring/totals.d.ts +9 -0
- package/dist/scoring/totals.d.ts.map +1 -0
- package/dist/scoring/totals.js +23 -0
- package/dist/scoring/totals.js.map +1 -0
- package/dist/structured/comparison/alignment.d.ts +9 -0
- package/dist/structured/comparison/alignment.d.ts.map +1 -0
- package/dist/structured/comparison/alignment.js +2 -0
- package/dist/structured/comparison/alignment.js.map +1 -0
- package/dist/structured/comparison/alignments/by-best-match.d.ts +9 -0
- package/dist/structured/comparison/alignments/by-best-match.d.ts.map +1 -0
- package/dist/structured/comparison/alignments/by-best-match.js +25 -0
- package/dist/structured/comparison/alignments/by-best-match.js.map +1 -0
- package/dist/structured/comparison/alignments/by-position.d.ts +6 -0
- package/dist/structured/comparison/alignments/by-position.d.ts.map +1 -0
- package/dist/structured/comparison/alignments/by-position.js +9 -0
- package/dist/structured/comparison/alignments/by-position.js.map +1 -0
- package/dist/structured/comparison/bag-of-words.d.ts +10 -0
- package/dist/structured/comparison/bag-of-words.d.ts.map +1 -0
- package/dist/structured/comparison/bag-of-words.js +48 -0
- package/dist/structured/comparison/bag-of-words.js.map +1 -0
- package/dist/structured/comparison/comparator.d.ts +5 -0
- package/dist/structured/comparison/comparator.d.ts.map +1 -0
- package/dist/structured/comparison/comparator.js +2 -0
- package/dist/structured/comparison/comparator.js.map +1 -0
- package/dist/structured/comparison/comparators/json-equality.d.ts +7 -0
- package/dist/structured/comparison/comparators/json-equality.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/json-equality.js +18 -0
- package/dist/structured/comparison/comparators/json-equality.js.map +1 -0
- package/dist/structured/comparison/comparators/normalized-text.d.ts +7 -0
- package/dist/structured/comparison/comparators/normalized-text.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/normalized-text.js +13 -0
- package/dist/structured/comparison/comparators/normalized-text.js.map +1 -0
- package/dist/structured/comparison/comparators/normalized.d.ts +2 -0
- package/dist/structured/comparison/comparators/normalized.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/normalized.js +3 -0
- package/dist/structured/comparison/comparators/normalized.js.map +1 -0
- package/dist/structured/comparison/comparators/number-within.d.ts +9 -0
- package/dist/structured/comparison/comparators/number-within.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/number-within.js +18 -0
- package/dist/structured/comparison/comparators/number-within.js.map +1 -0
- package/dist/structured/comparison/comparators/python-equality.d.ts +7 -0
- package/dist/structured/comparison/comparators/python-equality.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/python-equality.js +15 -0
- package/dist/structured/comparison/comparators/python-equality.js.map +1 -0
- package/dist/structured/comparison/comparators/token-overlap-at-least.d.ts +9 -0
- package/dist/structured/comparison/comparators/token-overlap-at-least.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/token-overlap-at-least.js +20 -0
- package/dist/structured/comparison/comparators/token-overlap-at-least.js.map +1 -0
- package/dist/structured/comparison/comparators/typed-comparator.d.ts +8 -0
- package/dist/structured/comparison/comparators/typed-comparator.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/typed-comparator.js +10 -0
- package/dist/structured/comparison/comparators/typed-comparator.js.map +1 -0
- package/dist/structured/comparison/comparison-spec.d.ts +17 -0
- package/dist/structured/comparison/comparison-spec.d.ts.map +1 -0
- package/dist/structured/comparison/comparison-spec.js +36 -0
- package/dist/structured/comparison/comparison-spec.js.map +1 -0
- package/dist/structured/comparison/comparison.d.ts +25 -0
- package/dist/structured/comparison/comparison.d.ts.map +1 -0
- package/dist/structured/comparison/comparison.js +94 -0
- package/dist/structured/comparison/comparison.js.map +1 -0
- package/dist/structured/comparison/field.d.ts +10 -0
- package/dist/structured/comparison/field.d.ts.map +1 -0
- package/dist/structured/comparison/field.js +29 -0
- package/dist/structured/comparison/field.js.map +1 -0
- package/dist/structured/comparison/item-pairs.d.ts +8 -0
- package/dist/structured/comparison/item-pairs.d.ts.map +1 -0
- package/dist/structured/comparison/item-pairs.js +2 -0
- package/dist/structured/comparison/item-pairs.js.map +1 -0
- package/dist/structured/comparison/json-path-query.d.ts +7 -0
- package/dist/structured/comparison/json-path-query.d.ts.map +1 -0
- package/dist/structured/comparison/json-path-query.js +133 -0
- package/dist/structured/comparison/json-path-query.js.map +1 -0
- package/dist/structured/comparison/json-value.d.ts +10 -0
- package/dist/structured/comparison/json-value.d.ts.map +1 -0
- package/dist/structured/comparison/json-value.js +47 -0
- package/dist/structured/comparison/json-value.js.map +1 -0
- package/dist/structured/comparison/leaf-pair.d.ts +24 -0
- package/dist/structured/comparison/leaf-pair.d.ts.map +1 -0
- package/dist/structured/comparison/leaf-pair.js +2 -0
- package/dist/structured/comparison/leaf-pair.js.map +1 -0
- package/dist/structured/comparison/match.d.ts +5 -0
- package/dist/structured/comparison/match.d.ts.map +1 -0
- package/dist/structured/comparison/match.js +2 -0
- package/dist/structured/comparison/match.js.map +1 -0
- package/dist/structured/comparison/name-selector.d.ts +6 -0
- package/dist/structured/comparison/name-selector.d.ts.map +1 -0
- package/dist/structured/comparison/name-selector.js +41 -0
- package/dist/structured/comparison/name-selector.js.map +1 -0
- package/dist/structured/comparison/path.d.ts +10 -0
- package/dist/structured/comparison/path.d.ts.map +1 -0
- package/dist/structured/comparison/path.js +27 -0
- package/dist/structured/comparison/path.js.map +1 -0
- package/dist/structured/comparison/tree-walk.d.ts +10 -0
- package/dist/structured/comparison/tree-walk.d.ts.map +1 -0
- package/dist/structured/comparison/tree-walk.js +136 -0
- package/dist/structured/comparison/tree-walk.js.map +1 -0
- package/dist/structured/cpython/python-text.d.ts +5 -0
- package/dist/structured/cpython/python-text.d.ts.map +1 -0
- package/dist/structured/cpython/python-text.js +79 -0
- package/dist/structured/cpython/python-text.js.map +1 -0
- package/dist/structured/index.d.ts +39 -0
- package/dist/structured/index.d.ts.map +1 -0
- package/dist/structured/index.js +29 -0
- package/dist/structured/index.js.map +1 -0
- package/dist/structured/promptfoo/scorer-assertion.d.ts +22 -0
- package/dist/structured/promptfoo/scorer-assertion.d.ts.map +1 -0
- package/dist/structured/promptfoo/scorer-assertion.js +34 -0
- package/dist/structured/promptfoo/scorer-assertion.js.map +1 -0
- package/dist/structured/schema/draft-07-schema.d.ts +3 -0
- package/dist/structured/schema/draft-07-schema.d.ts.map +1 -0
- package/dist/structured/schema/draft-07-schema.js +243 -0
- package/dist/structured/schema/draft-07-schema.js.map +1 -0
- package/dist/structured/schema/draft-2020-12-schema.d.ts +4 -0
- package/dist/structured/schema/draft-2020-12-schema.d.ts.map +1 -0
- package/dist/structured/schema/draft-2020-12-schema.js +280 -0
- package/dist/structured/schema/draft-2020-12-schema.js.map +1 -0
- package/dist/structured/schema/is-record.d.ts +2 -0
- package/dist/structured/schema/is-record.d.ts.map +1 -0
- package/dist/structured/schema/is-record.js +3 -0
- package/dist/structured/schema/is-record.js.map +1 -0
- package/dist/structured/schema/json-schema.d.ts +20 -0
- package/dist/structured/schema/json-schema.d.ts.map +1 -0
- package/dist/structured/schema/json-schema.js +244 -0
- package/dist/structured/schema/json-schema.js.map +1 -0
- package/dist/structured/schema/schema-type-walk.d.ts +11 -0
- package/dist/structured/schema/schema-type-walk.d.ts.map +1 -0
- package/dist/structured/schema/schema-type-walk.js +196 -0
- package/dist/structured/schema/schema-type-walk.js.map +1 -0
- package/dist/structured/scorers/all-matched.d.ts +10 -0
- package/dist/structured/scorers/all-matched.d.ts.map +1 -0
- package/dist/structured/scorers/all-matched.js +36 -0
- package/dist/structured/scorers/all-matched.js.map +1 -0
- package/dist/structured/scorers/exact-match.d.ts +7 -0
- package/dist/structured/scorers/exact-match.d.ts.map +1 -0
- package/dist/structured/scorers/exact-match.js +13 -0
- package/dist/structured/scorers/exact-match.js.map +1 -0
- package/dist/structured/scorers/item-matches.d.ts +7 -0
- package/dist/structured/scorers/item-matches.d.ts.map +1 -0
- package/dist/structured/scorers/item-matches.js +17 -0
- package/dist/structured/scorers/item-matches.js.map +1 -0
- package/dist/structured/scorers/leaf-matches.d.ts +14 -0
- package/dist/structured/scorers/leaf-matches.d.ts.map +1 -0
- package/dist/structured/scorers/leaf-matches.js +28 -0
- package/dist/structured/scorers/leaf-matches.js.map +1 -0
- package/dist/structured/scorers/parse-success.d.ts +7 -0
- package/dist/structured/scorers/parse-success.d.ts.map +1 -0
- package/dist/structured/scorers/parse-success.js +11 -0
- package/dist/structured/scorers/parse-success.js.map +1 -0
- package/dist/structured/scorers/path-matches.d.ts +5 -0
- package/dist/structured/scorers/path-matches.d.ts.map +1 -0
- package/dist/structured/scorers/path-matches.js +9 -0
- package/dist/structured/scorers/path-matches.js.map +1 -0
- package/dist/structured/scorers/required-key-recall.d.ts +8 -0
- package/dist/structured/scorers/required-key-recall.d.ts.map +1 -0
- package/dist/structured/scorers/required-key-recall.js +50 -0
- package/dist/structured/scorers/required-key-recall.js.map +1 -0
- package/dist/structured/scorers/schema-compliance.d.ts +8 -0
- package/dist/structured/scorers/schema-compliance.d.ts.map +1 -0
- package/dist/structured/scorers/schema-compliance.js +29 -0
- package/dist/structured/scorers/schema-compliance.js.map +1 -0
- package/dist/structured/scorers/token-f1.d.ts +14 -0
- package/dist/structured/scorers/token-f1.d.ts.map +1 -0
- package/dist/structured/scorers/token-f1.js +44 -0
- package/dist/structured/scorers/token-f1.js.map +1 -0
- package/dist/structured/scorers/type-precision.d.ts +10 -0
- package/dist/structured/scorers/type-precision.d.ts.map +1 -0
- package/dist/structured/scorers/type-precision.js +30 -0
- package/dist/structured/scorers/type-precision.js.map +1 -0
- package/dist/structured/scorers/valid-schema.d.ts +7 -0
- package/dist/structured/scorers/valid-schema.d.ts.map +1 -0
- package/dist/structured/scorers/valid-schema.js +11 -0
- package/dist/structured/scorers/valid-schema.js.map +1 -0
- package/dist/structured/scorers/value-matches.d.ts +6 -0
- package/dist/structured/scorers/value-matches.d.ts.map +1 -0
- package/dist/structured/scorers/value-matches.js +9 -0
- package/dist/structured/scorers/value-matches.js.map +1 -0
- package/dist/structured/scoring/case.d.ts +14 -0
- package/dist/structured/scoring/case.d.ts.map +1 -0
- package/dist/structured/scoring/case.js +14 -0
- package/dist/structured/scoring/case.js.map +1 -0
- package/dist/structured/scoring/config-case.d.ts +11 -0
- package/dist/structured/scoring/config-case.d.ts.map +1 -0
- package/dist/structured/scoring/config-case.js +22 -0
- package/dist/structured/scoring/config-case.js.map +1 -0
- package/dist/structured/scoring/per-field.d.ts +9 -0
- package/dist/structured/scoring/per-field.d.ts.map +1 -0
- package/dist/structured/scoring/per-field.js +23 -0
- package/dist/structured/scoring/per-field.js.map +1 -0
- package/dist/structured/scoring/scorer-set.d.ts +15 -0
- package/dist/structured/scoring/scorer-set.d.ts.map +1 -0
- package/dist/structured/scoring/scorer-set.js +60 -0
- package/dist/structured/scoring/scorer-set.js.map +1 -0
- package/dist/structured/scoring/text-vars-case.d.ts +12 -0
- package/dist/structured/scoring/text-vars-case.d.ts.map +1 -0
- package/dist/structured/scoring/text-vars-case.js +31 -0
- package/dist/structured/scoring/text-vars-case.js.map +1 -0
- package/package.json +78 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIhD,MAAM,WAAW,KAAK;IACpB,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../../src/structured/comparison/match.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name-selector.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/name-selector.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;;IAwBvB,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAUhE,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAWrC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// A name selector of RFC 9535 (section 2.3.1): the step to one member of an
|
|
2
|
+
// object, as JSONPath text.
|
|
3
|
+
export class NameSelector {
|
|
4
|
+
// member-name-shorthand (RFC 9535, section 2.5.1.1): a name that a query
|
|
5
|
+
// can write after "." without quotes.
|
|
6
|
+
static #shorthand = '[A-Za-z_\\u{80}-\\u{D7FF}\\u{E000}-\\u{10FFFF}][A-Za-z0-9_\\u{80}-\\u{D7FF}\\u{E000}-\\u{10FFFF}]*';
|
|
7
|
+
static #wholeShorthand = new RegExp(`^${NameSelector.#shorthand}$`, 'u');
|
|
8
|
+
// A Normalized Path (RFC 9535, section 2.7) escapes the control codes, the
|
|
9
|
+
// apostrophe and the backslash. A lone surrogate has no form in JSONPath,
|
|
10
|
+
// so it is escaped as \u too, for people to read.
|
|
11
|
+
static #surrogate = /^\p{Cs}$/u;
|
|
12
|
+
static #escapes = new Map([
|
|
13
|
+
['\b', '\\b'],
|
|
14
|
+
['\f', '\\f'],
|
|
15
|
+
['\n', '\\n'],
|
|
16
|
+
['\r', '\\r'],
|
|
17
|
+
['\t', '\\t'],
|
|
18
|
+
["'", "\\'"],
|
|
19
|
+
['\\', '\\\\'],
|
|
20
|
+
]);
|
|
21
|
+
// The member-name-shorthand that starts at `at` in `text`, if one does.
|
|
22
|
+
static shorthandAt(text, at) {
|
|
23
|
+
const sticky = new RegExp(NameSelector.#shorthand, 'uy');
|
|
24
|
+
sticky.lastIndex = at;
|
|
25
|
+
return sticky.exec(text)?.[0];
|
|
26
|
+
}
|
|
27
|
+
// The child segment of a member: `.name` when the name is a
|
|
28
|
+
// member-name-shorthand, else the bracketed name selector of a Normalized
|
|
29
|
+
// Path, such as `['a.b']`. The text reads back as the same step, except
|
|
30
|
+
// for a name that holds a lone surrogate, which JSONPath cannot name.
|
|
31
|
+
static segment(name) {
|
|
32
|
+
if (NameSelector.#wholeShorthand.test(name))
|
|
33
|
+
return `.${name}`;
|
|
34
|
+
const quoted = [...name].map((character) => NameSelector.#escapes.get(character) ??
|
|
35
|
+
(character < ' ' || NameSelector.#surrogate.test(character)
|
|
36
|
+
? `\\u${character.charCodeAt(0).toString(16).padStart(4, '0')}`
|
|
37
|
+
: character));
|
|
38
|
+
return `['${quoted.join('')}']`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=name-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name-selector.js","sourceRoot":"","sources":["../../../src/structured/comparison/name-selector.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4BAA4B;AAC5B,MAAM,OAAO,YAAY;IACvB,yEAAyE;IACzE,sCAAsC;IACtC,MAAM,CAAU,UAAU,GACxB,oGAAoG,CAAC;IACvG,MAAM,CAAU,eAAe,GAAG,IAAI,MAAM,CAC1C,IAAI,YAAY,CAAC,UAAU,GAAG,EAC9B,GAAG,CACJ,CAAC;IACF,2EAA2E;IAC3E,0EAA0E;IAC1E,kDAAkD;IAClD,MAAM,CAAU,UAAU,GAAG,WAAW,CAAC;IACzC,MAAM,CAAU,QAAQ,GAAgC,IAAI,GAAG,CAAC;QAC9D,CAAC,IAAI,EAAE,KAAK,CAAC;QACb,CAAC,IAAI,EAAE,KAAK,CAA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Step = string | number;
|
|
3
|
+
export declare class Path {
|
|
4
|
+
readonly steps: readonly Step[];
|
|
5
|
+
constructor(steps: readonly Step[]);
|
|
6
|
+
child(step: Step): Path;
|
|
7
|
+
toString(): string;
|
|
8
|
+
get field(): Field;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAKnC,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAKnC,qBAAa,IAAI;IACf,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;gBAEpB,KAAK,EAAE,SAAS,IAAI,EAAE;IAIlC,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAOvB,QAAQ,IAAI,MAAM;IASlB,IAAI,KAAK,IAAI,KAAK,CAIjB;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Field } from "./field.js";
|
|
2
|
+
import { NameSelector } from "./name-selector.js";
|
|
3
|
+
// The steps to one value. A path is its steps, not a string, so a key that
|
|
4
|
+
// holds "." or "[", or an empty key, is one step: {"a.b": 1} and
|
|
5
|
+
// {"a": {"b": 1}} have different paths (ADR 0011).
|
|
6
|
+
export class Path {
|
|
7
|
+
steps;
|
|
8
|
+
constructor(steps) {
|
|
9
|
+
this.steps = steps;
|
|
10
|
+
}
|
|
11
|
+
child(step) {
|
|
12
|
+
return new Path([...this.steps, step]);
|
|
13
|
+
}
|
|
14
|
+
// The path as a JSONPath query (RFC 9535), with an index selector for each
|
|
15
|
+
// position, such as $.offers[1].value.amount. The text is for people to
|
|
16
|
+
// read: a key of a ComparisonSpec names a field, never a position.
|
|
17
|
+
toString() {
|
|
18
|
+
return `$${this.steps
|
|
19
|
+
.map((step) => typeof step === 'number' ? `[${step}]` : NameSelector.segment(step))
|
|
20
|
+
.join('')}`;
|
|
21
|
+
}
|
|
22
|
+
// The path without its item positions.
|
|
23
|
+
get field() {
|
|
24
|
+
return new Field(this.steps.map((step) => (typeof step === 'number' ? Field.item : step)));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../../src/structured/comparison/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMlD,2EAA2E;AAC3E,iEAAiE;AACjE,mDAAmD;AACnD,MAAM,OAAO,IAAI;IACN,KAAK,CAAkB;IAEhC,YAAY,KAAsB;QAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,IAAU;QACd,OAAO,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,2EAA2E;IAC3E,wEAAwE;IACxE,mEAAmE;IACnE,QAAQ;QACN,OAAO,IAAI,IAAI,CAAC,KAAK;aAClB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CACpE;aACA,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;IAChB,CAAC;IAED,uCAAuC;IACvC,IAAI,KAAK;QACP,OAAO,IAAI,KAAK,CACd,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CACzE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JsonData } from '@zukhruf/python';
|
|
2
|
+
import type { Case } from '../scoring/case.ts';
|
|
3
|
+
import type { ComparisonSpec } from './comparison-spec.ts';
|
|
4
|
+
import { Comparison } from './comparison.ts';
|
|
5
|
+
export declare class TreeWalk {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(spec: ComparisonSpec);
|
|
8
|
+
compare(stated: JsonData, testCase: Case): Comparison;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=tree-walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-walk.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/tree-walk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAqB7C,qBAAa,QAAQ;;gBAGP,IAAI,EAAE,cAAc;IAIhC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,GAAG,UAAU;CAqNtD"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Comparison } from "./comparison.js";
|
|
2
|
+
import { Field } from "./field.js";
|
|
3
|
+
import { Path } from "./path.js";
|
|
4
|
+
// Walks a stated value and the expected value of its case side by side, as
|
|
5
|
+
// the spec says, and gives their Comparison. Objects line up by key, and the
|
|
6
|
+
// items of an array pair by the alignment of its field. Every other value is
|
|
7
|
+
// a leaf, null too; the comparator of its field says if the two sides agree.
|
|
8
|
+
// A value at the root is no leaf, so a stated value that is not an object or
|
|
9
|
+
// an array has no leaves. Where the two sides differ in kind, each side is
|
|
10
|
+
// walked alone. An excluded field adds no leaf pair and no item pairs, but its
|
|
11
|
+
// stated values still have their fields.
|
|
12
|
+
export class TreeWalk {
|
|
13
|
+
#spec;
|
|
14
|
+
constructor(spec) {
|
|
15
|
+
this.#spec = spec;
|
|
16
|
+
}
|
|
17
|
+
compare(stated, testCase) {
|
|
18
|
+
const found = TreeWalk.#nothingFound();
|
|
19
|
+
this.#walk(stated, testCase.expected, new Path([]), new Path([]), new Field([]), found);
|
|
20
|
+
return new Comparison(testCase, stated, found.leaves, found.statedPaths, found.arrays);
|
|
21
|
+
}
|
|
22
|
+
// The expected side goes first at each step, so the expected leaves come in
|
|
23
|
+
// the order of the expected value, as evaluate.py reads them.
|
|
24
|
+
#walk(stated, expected, statedPath, expectedPath, field, found) {
|
|
25
|
+
if (this.#spec.excludes(field)) {
|
|
26
|
+
TreeWalk.#statedPaths(stated, statedPath, found);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const root = field.steps.length === 0;
|
|
30
|
+
if (stated !== undefined && !root)
|
|
31
|
+
found.statedPaths.push(statedPath);
|
|
32
|
+
if (stated instanceof Map && expected instanceof Map)
|
|
33
|
+
this.#object(stated, expected, statedPath, expectedPath, field, found);
|
|
34
|
+
else if (Array.isArray(stated) && Array.isArray(expected))
|
|
35
|
+
this.#array(stated, expected, statedPath, expectedPath, field, found);
|
|
36
|
+
else
|
|
37
|
+
this.#apart(stated, expected, statedPath, expectedPath, field, found);
|
|
38
|
+
if (root)
|
|
39
|
+
return;
|
|
40
|
+
const expectedLeaf = TreeWalk.#leaf(expected, expectedPath);
|
|
41
|
+
const statedLeaf = TreeWalk.#leaf(stated, statedPath);
|
|
42
|
+
if (expectedLeaf !== undefined && statedLeaf !== undefined)
|
|
43
|
+
found.leaves.push({
|
|
44
|
+
expected: expectedLeaf,
|
|
45
|
+
stated: statedLeaf,
|
|
46
|
+
agrees: this.#spec
|
|
47
|
+
.comparatorOf(field)
|
|
48
|
+
.agrees(statedLeaf.value, expectedLeaf.value),
|
|
49
|
+
});
|
|
50
|
+
else if (expectedLeaf !== undefined)
|
|
51
|
+
found.leaves.push({ expected: expectedLeaf });
|
|
52
|
+
else if (statedLeaf !== undefined)
|
|
53
|
+
found.leaves.push({ stated: statedLeaf });
|
|
54
|
+
}
|
|
55
|
+
#object(stated, expected, statedPath, expectedPath, field, found) {
|
|
56
|
+
for (const [key, value] of expected)
|
|
57
|
+
this.#walk(stated.get(key), value, statedPath.child(key), expectedPath.child(key), field.child(key), found);
|
|
58
|
+
for (const [key, value] of stated)
|
|
59
|
+
if (!expected.has(key))
|
|
60
|
+
this.#walk(value, undefined, statedPath.child(key), expectedPath.child(key), field.child(key), found);
|
|
61
|
+
}
|
|
62
|
+
// The expected items in their order, each with the stated item that the
|
|
63
|
+
// alignment pairs with it, then the stated items without a pair.
|
|
64
|
+
#array(stated, expected, statedPath, expectedPath, field, found) {
|
|
65
|
+
const item = field.child(Field.item);
|
|
66
|
+
const agreement = {
|
|
67
|
+
count: (statedItem, expectedItem) => this.#agreeingLeaves(statedItem, expectedItem, item),
|
|
68
|
+
};
|
|
69
|
+
const pairs = this.#spec
|
|
70
|
+
.alignmentOf(field)
|
|
71
|
+
.pairs(stated, expected, agreement);
|
|
72
|
+
found.arrays.push({
|
|
73
|
+
field,
|
|
74
|
+
expected: expected.length,
|
|
75
|
+
stated: stated.length,
|
|
76
|
+
paired: pairs.length,
|
|
77
|
+
});
|
|
78
|
+
const statedOf = new Map(pairs.map(([statedIndex, expectedIndex]) => [expectedIndex, statedIndex]));
|
|
79
|
+
for (const [index, value] of expected.entries()) {
|
|
80
|
+
const statedIndex = statedOf.get(index);
|
|
81
|
+
this.#walk(statedIndex === undefined ? undefined : stated[statedIndex], value, statedPath.child(statedIndex ?? index), expectedPath.child(index), item, found);
|
|
82
|
+
}
|
|
83
|
+
const paired = new Set(statedOf.values());
|
|
84
|
+
for (const [index, value] of stated.entries())
|
|
85
|
+
if (!paired.has(index))
|
|
86
|
+
this.#walk(value, undefined, statedPath.child(index), expectedPath.child(index), item, found);
|
|
87
|
+
}
|
|
88
|
+
// Two values of different kinds: each side is walked alone. An array on
|
|
89
|
+
// one side has its items, and the other side has none.
|
|
90
|
+
#apart(stated, expected, statedPath, expectedPath, field, found) {
|
|
91
|
+
if (Array.isArray(stated) || Array.isArray(expected))
|
|
92
|
+
found.arrays.push({
|
|
93
|
+
field,
|
|
94
|
+
expected: Array.isArray(expected) ? expected.length : 0,
|
|
95
|
+
stated: Array.isArray(stated) ? stated.length : 0,
|
|
96
|
+
paired: 0,
|
|
97
|
+
});
|
|
98
|
+
for (const [step, fieldStep, value] of TreeWalk.#children(expected))
|
|
99
|
+
this.#walk(undefined, value, statedPath.child(step), expectedPath.child(step), field.child(fieldStep), found);
|
|
100
|
+
for (const [step, fieldStep, value] of TreeWalk.#children(stated))
|
|
101
|
+
this.#walk(value, undefined, statedPath.child(step), expectedPath.child(step), field.child(fieldStep), found);
|
|
102
|
+
}
|
|
103
|
+
// The leaf pairs of a stated item and an expected item that agree, by the
|
|
104
|
+
// rules of the spec under the field of the items.
|
|
105
|
+
#agreeingLeaves(stated, expected, item) {
|
|
106
|
+
const found = TreeWalk.#nothingFound();
|
|
107
|
+
this.#walk(stated, expected, new Path([]), new Path([]), item, found);
|
|
108
|
+
return found.leaves.filter((pair) => pair.agrees === true).length;
|
|
109
|
+
}
|
|
110
|
+
// The paths of a stated value and of each value under it.
|
|
111
|
+
static #statedPaths(stated, path, found) {
|
|
112
|
+
if (stated === undefined)
|
|
113
|
+
return;
|
|
114
|
+
if (path.steps.length > 0)
|
|
115
|
+
found.statedPaths.push(path);
|
|
116
|
+
for (const [step, , value] of TreeWalk.#children(stated))
|
|
117
|
+
TreeWalk.#statedPaths(value, path.child(step), found);
|
|
118
|
+
}
|
|
119
|
+
static *#children(value) {
|
|
120
|
+
if (value instanceof Map)
|
|
121
|
+
for (const [key, child] of value)
|
|
122
|
+
yield [key, key, child];
|
|
123
|
+
else if (Array.isArray(value))
|
|
124
|
+
for (const [index, child] of value.entries())
|
|
125
|
+
yield [index, Field.item, child];
|
|
126
|
+
}
|
|
127
|
+
static #leaf(value, path) {
|
|
128
|
+
if (value === undefined || value instanceof Map || Array.isArray(value))
|
|
129
|
+
return undefined;
|
|
130
|
+
return { path, value };
|
|
131
|
+
}
|
|
132
|
+
static #nothingFound() {
|
|
133
|
+
return { leaves: [], statedPaths: [], arrays: [] };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=tree-walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-walk.js","sourceRoot":"","sources":["../../../src/structured/comparison/tree-walk.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAkB,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAE,IAAI,EAAa,MAAM,WAAW,CAAC;AAS5C,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,2EAA2E;AAC3E,+EAA+E;AAC/E,yCAAyC;AACzC,MAAM,OAAO,QAAQ;IACV,KAAK,CAAiB;IAE/B,YAAY,IAAoB;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,MAAgB,EAAE,QAAc;QACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,CACR,MAAM,EACN,QAAQ,CAAC,QAAQ,EACjB,IAAI,IAAI,CAAC,EAAE,CAAC,EACZ,IAAI,IAAI,CAAC,EAAE,CAAC,EACZ,IAAI,KAAK,CAAC,EAAE,CAAC,EACb,KAAK,CACN,CAAC;QACF,OAAO,IAAI,UAAU,CACnB,QAAQ,EACR,MAAM,EACN,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,MAAM,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,YAAY,GAAG;YACtB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,KAAK;gBAAE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;aACvD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAC3B,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE;gBAC1C,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAA2B,EAAE,IAAU;QAClD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,YAAY,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACrE,OAAO,SAAS,CAAC;QACnB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,aAAa;QAClB,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type JsonData } from '@zukhruf/python';
|
|
2
|
+
export declare function compareStrings(left: string, right: string): number;
|
|
3
|
+
export declare function canonicalJson(value: JsonData): string;
|
|
4
|
+
export declare function pythonStr(value: bigint | number | string): string;
|
|
5
|
+
//# sourceMappingURL=python-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-text.d.ts","sourceRoot":"","sources":["../../../src/structured/cpython/python-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AAQ3D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAWlE;AAkCD,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAerD;AAID,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAIjE"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { floatRepr } from '@zukhruf/python';
|
|
2
|
+
// UTF-16 code units order the strings that have no character above U+FFFF
|
|
3
|
+
// as code points do.
|
|
4
|
+
const SURROGATE = /[\u{10000}-\u{10FFFF}]/u;
|
|
5
|
+
// Compares two strings as Python does: by Unicode code point. Copied from
|
|
6
|
+
// @zukhruf/mteb compareStrings (docs/copied-code.md).
|
|
7
|
+
export function compareStrings(left, right) {
|
|
8
|
+
if (!SURROGATE.test(left) && !SURROGATE.test(right))
|
|
9
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
10
|
+
const a = [...left];
|
|
11
|
+
const b = [...right];
|
|
12
|
+
for (let index = 0; index < Math.min(a.length, b.length); index++) {
|
|
13
|
+
const difference = (a[index]?.codePointAt(0) ?? 0) - (b[index]?.codePointAt(0) ?? 0);
|
|
14
|
+
if (difference !== 0)
|
|
15
|
+
return difference;
|
|
16
|
+
}
|
|
17
|
+
return a.length - b.length;
|
|
18
|
+
}
|
|
19
|
+
// The escapes of json.dumps with ensure_ascii=False (ESCAPE and ESCAPE_DCT,
|
|
20
|
+
// Lib/json/encoder.py): the quote, the backslash and the control characters.
|
|
21
|
+
const escapes = {
|
|
22
|
+
'"': '\\"',
|
|
23
|
+
'\\': '\\\\',
|
|
24
|
+
'\b': '\\b',
|
|
25
|
+
'\f': '\\f',
|
|
26
|
+
'\n': '\\n',
|
|
27
|
+
'\r': '\\r',
|
|
28
|
+
'\t': '\\t',
|
|
29
|
+
};
|
|
30
|
+
const jsonString = (text) => {
|
|
31
|
+
let out = '';
|
|
32
|
+
for (const char of text) {
|
|
33
|
+
const code = char.charCodeAt(0);
|
|
34
|
+
out +=
|
|
35
|
+
escapes[char] ??
|
|
36
|
+
(code < 0x20 ? `\x5Cu${code.toString(16).padStart(4, '0')}` : char);
|
|
37
|
+
}
|
|
38
|
+
return `"${out}"`;
|
|
39
|
+
};
|
|
40
|
+
const jsonFloat = (value) => {
|
|
41
|
+
if (Number.isNaN(value))
|
|
42
|
+
return 'NaN';
|
|
43
|
+
if (!Number.isFinite(value))
|
|
44
|
+
return value > 0 ? 'Infinity' : '-Infinity';
|
|
45
|
+
return floatRepr(value);
|
|
46
|
+
};
|
|
47
|
+
// json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
|
|
48
|
+
// of CPython: the canonical text that evaluate.py compares for a perfect
|
|
49
|
+
// response.
|
|
50
|
+
export function canonicalJson(value) {
|
|
51
|
+
if (value === null)
|
|
52
|
+
return 'null';
|
|
53
|
+
if (typeof value === 'boolean')
|
|
54
|
+
return value ? 'true' : 'false';
|
|
55
|
+
if (typeof value === 'bigint')
|
|
56
|
+
return value.toString();
|
|
57
|
+
if (typeof value === 'number')
|
|
58
|
+
return jsonFloat(value);
|
|
59
|
+
if (typeof value === 'string')
|
|
60
|
+
return jsonString(value);
|
|
61
|
+
if (Array.isArray(value))
|
|
62
|
+
return `[${value.map(canonicalJson).join(',')}]`;
|
|
63
|
+
if (value instanceof Map)
|
|
64
|
+
return `{${[...value]
|
|
65
|
+
.toSorted(([left], [right]) => compareStrings(left, right))
|
|
66
|
+
.map(([key, item]) => `${jsonString(key)}:${canonicalJson(item)}`)
|
|
67
|
+
.join(',')}}`;
|
|
68
|
+
throw new TypeError('A Python value is null, bool, int, float, str, list or dict');
|
|
69
|
+
}
|
|
70
|
+
// str() of a scalar: an int as its digits, a float as its repr, a str as it
|
|
71
|
+
// is. None and bool are named by the caller, as evaluate.py does.
|
|
72
|
+
export function pythonStr(value) {
|
|
73
|
+
if (typeof value === 'bigint')
|
|
74
|
+
return value.toString();
|
|
75
|
+
if (typeof value === 'number')
|
|
76
|
+
return floatRepr(value);
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=python-text.js.map
|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Q;QAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;IACxD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC3E,IAAI,KAAK,YAAY,GAAG;QACtB,OAAO,IAAI,CAAC,GAAG,KAAK,CAAC;aAClB,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aAC1D,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;aACjE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAClB,MAAM,IAAI,SAAS,CACjB,6DAA6D,CAC9D,CAAC;AACJ,CAAC;AAED,4EAA4E;AAC5E,kEAAkE;AAClE,MAAM,UAAU,SAAS,CAAC,KAA+B;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type { Agreement, Alignment, Pairs } from './comparison/alignment.ts';
|
|
2
|
+
export { ByBestMatch } from './comparison/alignments/by-best-match.ts';
|
|
3
|
+
export { ByPosition } from './comparison/alignments/by-position.ts';
|
|
4
|
+
export type { Comparator } from './comparison/comparator.ts';
|
|
5
|
+
export { JsonEquality } from './comparison/comparators/json-equality.ts';
|
|
6
|
+
export { PythonEquality } from './comparison/comparators/python-equality.ts';
|
|
7
|
+
export { NormalizedText } from './comparison/comparators/normalized-text.ts';
|
|
8
|
+
export { NumberWithin } from './comparison/comparators/number-within.ts';
|
|
9
|
+
export { TokenOverlapAtLeast } from './comparison/comparators/token-overlap-at-least.ts';
|
|
10
|
+
export type { Match } from './comparison/match.ts';
|
|
11
|
+
export { ComparisonSpec, type ComparisonSpecOptions, } from './comparison/comparison-spec.ts';
|
|
12
|
+
export { JsonValue } from './comparison/json-value.ts';
|
|
13
|
+
export type { Comparison } from './comparison/comparison.ts';
|
|
14
|
+
export type { Leaf, LeafPair, LeafValue } from './comparison/leaf-pair.ts';
|
|
15
|
+
export type { ItemPairs } from './comparison/item-pairs.ts';
|
|
16
|
+
export type { Field, FieldStep } from './comparison/field.ts';
|
|
17
|
+
export type { Path, Step } from './comparison/path.ts';
|
|
18
|
+
export { TreeWalk } from './comparison/tree-walk.ts';
|
|
19
|
+
export { ExactMatch } from './scorers/exact-match.ts';
|
|
20
|
+
export type { LeafOptions } from './scorers/leaf-matches.ts';
|
|
21
|
+
export { PathMatches } from './scorers/path-matches.ts';
|
|
22
|
+
export { ValueMatches } from './scorers/value-matches.ts';
|
|
23
|
+
export { ItemMatches } from './scorers/item-matches.ts';
|
|
24
|
+
export { AllMatched } from './scorers/all-matched.ts';
|
|
25
|
+
export { TokenF1 } from './scorers/token-f1.ts';
|
|
26
|
+
export { TypePrecision } from './scorers/type-precision.ts';
|
|
27
|
+
export { ParseSuccess } from './scorers/parse-success.ts';
|
|
28
|
+
export { RequiredKeyRecall } from './scorers/required-key-recall.ts';
|
|
29
|
+
export { SchemaCompliance } from './scorers/schema-compliance.ts';
|
|
30
|
+
export { ValidSchema } from './scorers/valid-schema.ts';
|
|
31
|
+
export { Case } from './scoring/case.ts';
|
|
32
|
+
export { ConfigCase } from './scoring/config-case.ts';
|
|
33
|
+
export { TextVarsCase } from './scoring/text-vars-case.ts';
|
|
34
|
+
export { ScorerSet } from './scoring/scorer-set.ts';
|
|
35
|
+
export { PerField } from './scoring/per-field.ts';
|
|
36
|
+
export { type Draft, JsonSchema, type Validation, } from './schema/json-schema.ts';
|
|
37
|
+
export type { SchemaTypeWalk } from './schema/schema-type-walk.ts';
|
|
38
|
+
export { ScorerAssertion } from './promptfoo/scorer-assertion.ts';
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/structured/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AACzF,YAAY,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,GAC3B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3E,YAAY,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O,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { ByBestMatch } from "./comparison/alignments/by-best-match.js";
|
|
2
|
+
export { ByPosition } from "./comparison/alignments/by-position.js";
|
|
3
|
+
export { JsonEquality } from "./comparison/comparators/json-equality.js";
|
|
4
|
+
export { PythonEquality } from "./comparison/comparators/python-equality.js";
|
|
5
|
+
export { NormalizedText } from "./comparison/comparators/normalized-text.js";
|
|
6
|
+
export { NumberWithin } from "./comparison/comparators/number-within.js";
|
|
7
|
+
export { TokenOverlapAtLeast } from "./comparison/comparators/token-overlap-at-least.js";
|
|
8
|
+
export { ComparisonSpec, } from "./comparison/comparison-spec.js";
|
|
9
|
+
export { JsonValue } from "./comparison/json-value.js";
|
|
10
|
+
export { TreeWalk } from "./comparison/tree-walk.js";
|
|
11
|
+
export { ExactMatch } from "./scorers/exact-match.js";
|
|
12
|
+
export { PathMatches } from "./scorers/path-matches.js";
|
|
13
|
+
export { ValueMatches } from "./scorers/value-matches.js";
|
|
14
|
+
export { ItemMatches } from "./scorers/item-matches.js";
|
|
15
|
+
export { AllMatched } from "./scorers/all-matched.js";
|
|
16
|
+
export { TokenF1 } from "./scorers/token-f1.js";
|
|
17
|
+
export { TypePrecision } from "./scorers/type-precision.js";
|
|
18
|
+
export { ParseSuccess } from "./scorers/parse-success.js";
|
|
19
|
+
export { RequiredKeyRecall } from "./scorers/required-key-recall.js";
|
|
20
|
+
export { SchemaCompliance } from "./scorers/schema-compliance.js";
|
|
21
|
+
export { ValidSchema } from "./scorers/valid-schema.js";
|
|
22
|
+
export { Case } from "./scoring/case.js";
|
|
23
|
+
export { ConfigCase } from "./scoring/config-case.js";
|
|
24
|
+
export { TextVarsCase } from "./scoring/text-vars-case.js";
|
|
25
|
+
export { ScorerSet } from "./scoring/scorer-set.js";
|
|
26
|
+
export { PerField } from "./scoring/per-field.js";
|
|
27
|
+
export { JsonSchema, } from "./schema/json-schema.js";
|
|
28
|
+
export { ScorerAssertion } from "./promptfoo/scorer-assertion.js";
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/structured/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AAEzF,OAAO,EACL,cAAc,GAEf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAMvD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAEL,UAAU,GAEX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Scorer } from '../../scorers/scorer.ts';
|
|
2
|
+
import type { CaseReader } from '../../scoring/scorecard-scorer.ts';
|
|
3
|
+
import { ComparisonSpec } from '../comparison/comparison-spec.ts';
|
|
4
|
+
import type { Comparison } from '../comparison/comparison.ts';
|
|
5
|
+
import type { Case } from '../scoring/case.ts';
|
|
6
|
+
export type VarsContext = {
|
|
7
|
+
readonly vars: Readonly<Record<string, unknown>>;
|
|
8
|
+
};
|
|
9
|
+
export declare class ScorerAssertion {
|
|
10
|
+
readonly metric: string | undefined;
|
|
11
|
+
readonly weight: number;
|
|
12
|
+
readonly threshold: number;
|
|
13
|
+
readonly value: (output: string, context: VarsContext) => number;
|
|
14
|
+
constructor(scorer: Scorer<Comparison>, { weight, threshold, metric, spec, cases, }: {
|
|
15
|
+
readonly weight: number;
|
|
16
|
+
readonly threshold: number;
|
|
17
|
+
readonly metric?: string;
|
|
18
|
+
readonly spec?: ComparisonSpec;
|
|
19
|
+
readonly cases?: CaseReader<Case>;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=scorer-assertion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scorer-assertion.d.ts","sourceRoot":"","sources":["../../../src/structured/promptfoo/scorer-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAG9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAM/C,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD,CAAC;AAkBF,qBAAa,eAAe;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,MAAM,CAAC;gBAG/D,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,EAC1B,EACE,MAAM,EACN,SAAS,EACT,MAAM,EACN,IAA2B,EAC3B,KAA0B,GAC3B,EAAE;QACD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC;QAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;KACnC;CASJ"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ComparisonSpec } from "../comparison/comparison-spec.js";
|
|
2
|
+
import { statedData } from "../comparison/json-value.js";
|
|
3
|
+
import { TreeWalk } from "../comparison/tree-walk.js";
|
|
4
|
+
import { TextVarsCase } from "../scoring/text-vars-case.js";
|
|
5
|
+
// One scorer with the rule of its promptfoo assertion (ADR 0007, ADR 0013):
|
|
6
|
+
// how much it counts in the score of the test (weight: the score is the sum
|
|
7
|
+
// of value × weight over the sum of the weights), when it passes (threshold:
|
|
8
|
+
// a number passes when it reaches it), and the metric it reports under when
|
|
9
|
+
// that is not its name in its assertion module (metric: promptfoo averages
|
|
10
|
+
// the values of one metric over the tests, which is a metric in the sense of
|
|
11
|
+
// ADR 0009). It is not a promptfoo assertion: promptfoo stores a config as
|
|
12
|
+
// JSON, so a config gets a file reference from its AssertionModule, and
|
|
13
|
+
// promptfoo loads value from the module. value gets the text of the harness,
|
|
14
|
+
// and gives the value of the ratio of the scorer: promptfoo takes the mean of
|
|
15
|
+
// the values of one metric, so a SampleAveraged scorer gives its samples
|
|
16
|
+
// average. The case comes from the vars of the test, as its case reader reads
|
|
17
|
+
// them (a TextVarsCase that reads each schema with the draft of its $schema,
|
|
18
|
+
// unless the caller gives one): an assertion that defaultTest shares gets
|
|
19
|
+
// only the vars of each test, and JSON text keeps 7.0 a float. The spec tells
|
|
20
|
+
// the walk how to compare the answer with the case.
|
|
21
|
+
export class ScorerAssertion {
|
|
22
|
+
metric;
|
|
23
|
+
weight;
|
|
24
|
+
threshold;
|
|
25
|
+
value;
|
|
26
|
+
constructor(scorer, { weight, threshold, metric, spec = new ComparisonSpec(), cases = new TextVarsCase(), }) {
|
|
27
|
+
this.metric = metric;
|
|
28
|
+
this.weight = weight;
|
|
29
|
+
this.threshold = threshold;
|
|
30
|
+
const walk = new TreeWalk(spec);
|
|
31
|
+
this.value = (output, { vars }) => scorer.score(walk.compare(statedData(output), cases.from(vars))).value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=scorer-assertion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scorer-assertion.js","sourceRoot":"","sources":["../../../src/structured/promptfoo/scorer-assertion.ts"],"names":[],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