@orq-ai/evaluators 1.0.9 → 1.1.0-rc.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orq-ai/evaluators",
3
- "version": "1.0.9",
3
+ "version": "1.1.0-rc.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -50,6 +50,6 @@
50
50
  "tslib": "^2.3.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@orq-ai/evaluatorq": "^1.0.9"
53
+ "@orq-ai/evaluatorq": "^1.1.0-rc.2"
54
54
  }
55
55
  }
@@ -1,26 +0,0 @@
1
- import type { Evaluator } from "@orq-ai/evaluatorq";
2
- /**
3
- * Validates exact equality between output and expected output
4
- */
5
- export declare const exactMatch: Evaluator;
6
- /**
7
- * Validates fuzzy equality (case-insensitive, trimmed strings)
8
- */
9
- export declare const fuzzyMatch: Evaluator;
10
- /**
11
- * Validates that a numeric output is within a tolerance of the expected value
12
- */
13
- export declare function withinTolerance(tolerance: number): Evaluator;
14
- /**
15
- * Validates that a numeric output is greater than a threshold
16
- */
17
- export declare function greaterThan(threshold: number): Evaluator;
18
- /**
19
- * Validates that a numeric output is less than a threshold
20
- */
21
- export declare function lessThan(threshold: number): Evaluator;
22
- /**
23
- * Validates that a numeric output is within a range (inclusive)
24
- */
25
- export declare function inRange(min: number, max: number): Evaluator;
26
- //# sourceMappingURL=comparison-evaluators.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"comparison-evaluators.d.ts","sourceRoot":"","sources":["../../src/lib/comparison-evaluators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,SAmBxB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,SAqBxB,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAgC5D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAuBxD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAuBrD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAuB3D"}
@@ -1,148 +0,0 @@
1
- /**
2
- * Validates exact equality between output and expected output
3
- */
4
- export const exactMatch = {
5
- name: "exact-match",
6
- scorer: async ({ output, data }) => {
7
- if (data.expectedOutput === undefined) {
8
- return {
9
- value: true,
10
- explanation: "No expected output provided, skipping validation",
11
- };
12
- }
13
- const matches = JSON.stringify(output) === JSON.stringify(data.expectedOutput);
14
- return {
15
- value: matches,
16
- explanation: matches
17
- ? "Output exactly matches expected"
18
- : "Output does not match expected",
19
- };
20
- },
21
- };
22
- /**
23
- * Validates fuzzy equality (case-insensitive, trimmed strings)
24
- */
25
- export const fuzzyMatch = {
26
- name: "fuzzy-match",
27
- scorer: async ({ output, data }) => {
28
- if (data.expectedOutput === undefined) {
29
- return {
30
- value: true,
31
- explanation: "No expected output provided, skipping validation",
32
- };
33
- }
34
- const outputStr = String(output).trim().toLowerCase();
35
- const expectedStr = String(data.expectedOutput).trim().toLowerCase();
36
- const matches = outputStr === expectedStr;
37
- return {
38
- value: matches,
39
- explanation: matches
40
- ? "Output matches expected (case-insensitive)"
41
- : "Output does not match expected",
42
- };
43
- },
44
- };
45
- /**
46
- * Validates that a numeric output is within a tolerance of the expected value
47
- */
48
- export function withinTolerance(tolerance) {
49
- return {
50
- name: `within-tolerance-${tolerance}`,
51
- scorer: async ({ output, data }) => {
52
- if (data.expectedOutput === undefined) {
53
- return {
54
- value: true,
55
- explanation: "No expected output provided, skipping validation",
56
- };
57
- }
58
- const outputNum = Number(output);
59
- const expectedNum = Number(data.expectedOutput);
60
- if (Number.isNaN(outputNum) || Number.isNaN(expectedNum)) {
61
- return {
62
- value: false,
63
- explanation: "Output or expected value is not a valid number",
64
- };
65
- }
66
- const difference = Math.abs(outputNum - expectedNum);
67
- const isWithinTolerance = difference <= tolerance;
68
- return {
69
- value: isWithinTolerance,
70
- explanation: isWithinTolerance
71
- ? `Value ${outputNum} is within ${tolerance} of expected ${expectedNum}`
72
- : `Value ${outputNum} differs by ${difference} from expected ${expectedNum} (tolerance: ${tolerance})`,
73
- };
74
- },
75
- };
76
- }
77
- /**
78
- * Validates that a numeric output is greater than a threshold
79
- */
80
- export function greaterThan(threshold) {
81
- return {
82
- name: `greater-than-${threshold}`,
83
- scorer: async ({ output }) => {
84
- const value = Number(output);
85
- if (Number.isNaN(value)) {
86
- return {
87
- value: false,
88
- explanation: "Output is not a valid number",
89
- };
90
- }
91
- const isGreater = value > threshold;
92
- return {
93
- value: isGreater,
94
- explanation: isGreater
95
- ? `Value ${value} is greater than ${threshold}`
96
- : `Value ${value} is not greater than ${threshold}`,
97
- };
98
- },
99
- };
100
- }
101
- /**
102
- * Validates that a numeric output is less than a threshold
103
- */
104
- export function lessThan(threshold) {
105
- return {
106
- name: `less-than-${threshold}`,
107
- scorer: async ({ output }) => {
108
- const value = Number(output);
109
- if (Number.isNaN(value)) {
110
- return {
111
- value: false,
112
- explanation: "Output is not a valid number",
113
- };
114
- }
115
- const isLess = value < threshold;
116
- return {
117
- value: isLess,
118
- explanation: isLess
119
- ? `Value ${value} is less than ${threshold}`
120
- : `Value ${value} is not less than ${threshold}`,
121
- };
122
- },
123
- };
124
- }
125
- /**
126
- * Validates that a numeric output is within a range (inclusive)
127
- */
128
- export function inRange(min, max) {
129
- return {
130
- name: `in-range-${min}-${max}`,
131
- scorer: async ({ output }) => {
132
- const value = Number(output);
133
- if (Number.isNaN(value)) {
134
- return {
135
- value: false,
136
- explanation: "Output is not a valid number",
137
- };
138
- }
139
- const isInRange = value >= min && value <= max;
140
- return {
141
- value: isInRange,
142
- explanation: isInRange
143
- ? `Value ${value} is within range [${min}, ${max}]`
144
- : `Value ${value} is outside range [${min}, ${max}]`,
145
- };
146
- },
147
- };
148
- }
@@ -1,2 +0,0 @@
1
- export declare function evaluators(): string;
2
- //# sourceMappingURL=evaluators.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"evaluators.d.ts","sourceRoot":"","sources":["../../src/lib/evaluators.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
@@ -1,3 +0,0 @@
1
- export function evaluators() {
2
- return "evaluators";
3
- }
@@ -1,25 +0,0 @@
1
- import type { Evaluator } from "@orq-ai/evaluatorq";
2
- /**
3
- * Validates that the output is valid JSON
4
- */
5
- export declare const isValidJson: Evaluator;
6
- /**
7
- * Validates that the output contains specific JSON fields
8
- */
9
- export declare function hasJsonFields(requiredFields: string[]): Evaluator;
10
- /**
11
- * Validates JSON schema compliance
12
- */
13
- export declare function matchesJsonStructure(validator: (obj: any) => {
14
- valid: boolean;
15
- message?: string;
16
- }): Evaluator;
17
- /**
18
- * Validates that JSON array has a specific length
19
- */
20
- export declare function jsonArrayLength(expectedLength: number): Evaluator;
21
- /**
22
- * Validates that JSON array contains specific number of items within a range
23
- */
24
- export declare function jsonArrayLengthInRange(min: number, max: number): Evaluator;
25
- //# sourceMappingURL=json-evaluators.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-evaluators.d.ts","sourceRoot":"","sources":["../../src/lib/json-evaluators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,SAwBzB,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,SAAS,CA2CjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CACnC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3D,SAAS,CA2BX;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAqCjE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAqC1E"}
@@ -1,177 +0,0 @@
1
- /**
2
- * Validates that the output is valid JSON
3
- */
4
- export const isValidJson = {
5
- name: "is-valid-json",
6
- scorer: async ({ output }) => {
7
- if (output === undefined || output === null) {
8
- return {
9
- value: false,
10
- explanation: "Output is null or undefined",
11
- };
12
- }
13
- try {
14
- const str = typeof output === "string" ? output : JSON.stringify(output);
15
- JSON.parse(str);
16
- return {
17
- value: true,
18
- explanation: "Output is valid JSON",
19
- };
20
- }
21
- catch {
22
- return {
23
- value: false,
24
- explanation: "Output is not valid JSON",
25
- };
26
- }
27
- },
28
- };
29
- /**
30
- * Validates that the output contains specific JSON fields
31
- */
32
- export function hasJsonFields(requiredFields) {
33
- const fieldList = requiredFields.join("-");
34
- return {
35
- name: `has-fields-${fieldList.slice(0, 30)}`,
36
- scorer: async ({ output }) => {
37
- if (output === undefined || output === null) {
38
- return {
39
- value: false,
40
- explanation: "Output is null or undefined",
41
- };
42
- }
43
- try {
44
- const obj = typeof output === "string" ? JSON.parse(output) : output;
45
- if (typeof obj !== "object" || Array.isArray(obj)) {
46
- return {
47
- value: false,
48
- explanation: "Output is not a JSON object",
49
- };
50
- }
51
- const missingFields = requiredFields.filter((field) => !(field in obj));
52
- if (missingFields.length === 0) {
53
- return {
54
- value: true,
55
- explanation: `All required fields present: ${requiredFields.join(", ")}`,
56
- };
57
- }
58
- return {
59
- value: false,
60
- explanation: `Missing fields: ${missingFields.join(", ")}`,
61
- };
62
- }
63
- catch {
64
- return {
65
- value: false,
66
- explanation: "Output is not valid JSON",
67
- };
68
- }
69
- },
70
- };
71
- }
72
- /**
73
- * Validates JSON schema compliance
74
- */
75
- export function matchesJsonStructure(validator) {
76
- return {
77
- name: "matches-json-structure",
78
- scorer: async ({ output }) => {
79
- if (output === undefined || output === null) {
80
- return {
81
- value: false,
82
- explanation: "Output is null or undefined",
83
- };
84
- }
85
- try {
86
- const obj = typeof output === "string" ? JSON.parse(output) : output;
87
- const result = validator(obj);
88
- return {
89
- value: result.valid,
90
- explanation: result.message || (result.valid ? "JSON structure is valid" : "JSON structure is invalid"),
91
- };
92
- }
93
- catch (error) {
94
- return {
95
- value: false,
96
- explanation: `Failed to parse JSON: ${error instanceof Error ? error.message : "Unknown error"}`,
97
- };
98
- }
99
- },
100
- };
101
- }
102
- /**
103
- * Validates that JSON array has a specific length
104
- */
105
- export function jsonArrayLength(expectedLength) {
106
- return {
107
- name: `json-array-length-${expectedLength}`,
108
- scorer: async ({ output }) => {
109
- if (output === undefined || output === null) {
110
- return {
111
- value: false,
112
- explanation: "Output is null or undefined",
113
- };
114
- }
115
- try {
116
- const arr = typeof output === "string" ? JSON.parse(output) : output;
117
- if (!Array.isArray(arr)) {
118
- return {
119
- value: false,
120
- explanation: "Output is not a JSON array",
121
- };
122
- }
123
- const hasExpectedLength = arr.length === expectedLength;
124
- return {
125
- value: hasExpectedLength,
126
- explanation: hasExpectedLength
127
- ? `Array has expected length of ${expectedLength}`
128
- : `Array length ${arr.length} does not match expected ${expectedLength}`,
129
- };
130
- }
131
- catch {
132
- return {
133
- value: false,
134
- explanation: "Output is not valid JSON",
135
- };
136
- }
137
- },
138
- };
139
- }
140
- /**
141
- * Validates that JSON array contains specific number of items within a range
142
- */
143
- export function jsonArrayLengthInRange(min, max) {
144
- return {
145
- name: `json-array-length-${min}-${max}`,
146
- scorer: async ({ output }) => {
147
- if (output === undefined || output === null) {
148
- return {
149
- value: false,
150
- explanation: "Output is null or undefined",
151
- };
152
- }
153
- try {
154
- const arr = typeof output === "string" ? JSON.parse(output) : output;
155
- if (!Array.isArray(arr)) {
156
- return {
157
- value: false,
158
- explanation: "Output is not a JSON array",
159
- };
160
- }
161
- const isInRange = arr.length >= min && arr.length <= max;
162
- return {
163
- value: isInRange,
164
- explanation: isInRange
165
- ? `Array length ${arr.length} is within range [${min}, ${max}]`
166
- : `Array length ${arr.length} is outside range [${min}, ${max}]`,
167
- };
168
- }
169
- catch {
170
- return {
171
- value: false,
172
- explanation: "Output is not valid JSON",
173
- };
174
- }
175
- },
176
- };
177
- }
@@ -1,30 +0,0 @@
1
- import type { Evaluator } from "@orq-ai/evaluatorq";
2
- /**
3
- * Validates that a string output does not exceed a maximum length
4
- */
5
- export declare function maxLength(max: number): Evaluator;
6
- /**
7
- * Validates that a string output meets a minimum length requirement
8
- */
9
- export declare function minLength(min: number): Evaluator;
10
- /**
11
- * Validates that the output contains a specific substring
12
- */
13
- export declare function contains(substring: string, caseSensitive?: boolean): Evaluator;
14
- /**
15
- * Validates that the output matches a regular expression pattern
16
- */
17
- export declare function matchesPattern(pattern: RegExp | string, description?: string): Evaluator;
18
- /**
19
- * Validates that the output starts with a specific prefix
20
- */
21
- export declare function startsWith(prefix: string): Evaluator;
22
- /**
23
- * Validates that the output ends with a specific suffix
24
- */
25
- export declare function endsWith(suffix: string): Evaluator;
26
- /**
27
- * Validates that the output is not empty or whitespace-only
28
- */
29
- export declare const notEmpty: Evaluator;
30
- //# sourceMappingURL=string-evaluators.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string-evaluators.d.ts","sourceRoot":"","sources":["../../src/lib/string-evaluators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAsBhD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAsBhD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,UAAO,GAAG,SAAS,CAyB3E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CA0BxF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAqBpD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAqBlD;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,SAkBtB,CAAC"}
@@ -1,168 +0,0 @@
1
- /**
2
- * Validates that a string output does not exceed a maximum length
3
- */
4
- export function maxLength(max) {
5
- return {
6
- name: `max-length-${max}`,
7
- scorer: async ({ output }) => {
8
- if (output === undefined || output === null) {
9
- return {
10
- value: false,
11
- explanation: "Output is null or undefined",
12
- };
13
- }
14
- const length = typeof output === "string" ? output.length : String(output).length;
15
- const isValid = length <= max;
16
- return {
17
- value: isValid,
18
- explanation: isValid
19
- ? `Length ${length} is within limit (≤${max})`
20
- : `Length ${length} exceeds limit of ${max}`,
21
- };
22
- },
23
- };
24
- }
25
- /**
26
- * Validates that a string output meets a minimum length requirement
27
- */
28
- export function minLength(min) {
29
- return {
30
- name: `min-length-${min}`,
31
- scorer: async ({ output }) => {
32
- if (output === undefined || output === null) {
33
- return {
34
- value: false,
35
- explanation: "Output is null or undefined",
36
- };
37
- }
38
- const length = typeof output === "string" ? output.length : String(output).length;
39
- const isValid = length >= min;
40
- return {
41
- value: isValid,
42
- explanation: isValid
43
- ? `Length ${length} meets minimum (≥${min})`
44
- : `Length ${length} is below minimum ${min}`,
45
- };
46
- },
47
- };
48
- }
49
- /**
50
- * Validates that the output contains a specific substring
51
- */
52
- export function contains(substring, caseSensitive = true) {
53
- return {
54
- name: `contains-${substring.toLowerCase().replace(/\s+/g, "-")}`,
55
- scorer: async ({ output }) => {
56
- if (output === undefined || output === null) {
57
- return {
58
- value: false,
59
- explanation: "Output is null or undefined",
60
- };
61
- }
62
- const outputStr = String(output);
63
- const searchStr = substring;
64
- const found = caseSensitive
65
- ? outputStr.includes(searchStr)
66
- : outputStr.toLowerCase().includes(searchStr.toLowerCase());
67
- return {
68
- value: found,
69
- explanation: found
70
- ? `Output contains "${substring}"`
71
- : `Output does not contain "${substring}"`,
72
- };
73
- },
74
- };
75
- }
76
- /**
77
- * Validates that the output matches a regular expression pattern
78
- */
79
- export function matchesPattern(pattern, description) {
80
- const regex = typeof pattern === "string" ? new RegExp(pattern) : pattern;
81
- const patternStr = regex.source;
82
- return {
83
- name: `matches-pattern-${patternStr.slice(0, 20).replace(/[^a-z0-9]/gi, "-")}`,
84
- scorer: async ({ output }) => {
85
- if (output === undefined || output === null) {
86
- return {
87
- value: false,
88
- explanation: "Output is null or undefined",
89
- };
90
- }
91
- const matches = regex.test(String(output));
92
- return {
93
- value: matches,
94
- explanation: matches
95
- ? description || `Output matches pattern /${patternStr}/`
96
- : description
97
- ? `Output does not match required pattern: ${description}`
98
- : `Output does not match pattern /${patternStr}/`,
99
- };
100
- },
101
- };
102
- }
103
- /**
104
- * Validates that the output starts with a specific prefix
105
- */
106
- export function startsWith(prefix) {
107
- return {
108
- name: `starts-with-${prefix.toLowerCase().replace(/\s+/g, "-")}`,
109
- scorer: async ({ output }) => {
110
- if (output === undefined || output === null) {
111
- return {
112
- value: false,
113
- explanation: "Output is null or undefined",
114
- };
115
- }
116
- const starts = String(output).startsWith(prefix);
117
- return {
118
- value: starts,
119
- explanation: starts
120
- ? `Output starts with "${prefix}"`
121
- : `Output does not start with "${prefix}"`,
122
- };
123
- },
124
- };
125
- }
126
- /**
127
- * Validates that the output ends with a specific suffix
128
- */
129
- export function endsWith(suffix) {
130
- return {
131
- name: `ends-with-${suffix.toLowerCase().replace(/\s+/g, "-")}`,
132
- scorer: async ({ output }) => {
133
- if (output === undefined || output === null) {
134
- return {
135
- value: false,
136
- explanation: "Output is null or undefined",
137
- };
138
- }
139
- const ends = String(output).endsWith(suffix);
140
- return {
141
- value: ends,
142
- explanation: ends
143
- ? `Output ends with "${suffix}"`
144
- : `Output does not end with "${suffix}"`,
145
- };
146
- },
147
- };
148
- }
149
- /**
150
- * Validates that the output is not empty or whitespace-only
151
- */
152
- export const notEmpty = {
153
- name: "not-empty",
154
- scorer: async ({ output }) => {
155
- if (output === undefined || output === null) {
156
- return {
157
- value: false,
158
- explanation: "Output is null or undefined",
159
- };
160
- }
161
- const trimmed = String(output).trim();
162
- const isNotEmpty = trimmed.length > 0;
163
- return {
164
- value: isNotEmpty,
165
- explanation: isNotEmpty ? "Output is not empty" : "Output is empty or whitespace-only",
166
- };
167
- },
168
- };