@orq-ai/evaluators 1.0.8 → 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/README.md CHANGED
@@ -10,15 +10,40 @@ npm install @orq-ai/evaluators
10
10
 
11
11
  ## Usage
12
12
 
13
+ ### String Contains Evaluator
14
+
15
+ Check if the output contains the expected output (case-insensitive by default):
16
+
17
+ ```typescript
18
+ import { stringContainsEvaluator } from "@orq-ai/evaluators";
19
+
20
+ // Default: case-insensitive matching
21
+ const evaluator = stringContainsEvaluator();
22
+
23
+ // Case-sensitive matching
24
+ const strictEvaluator = stringContainsEvaluator({
25
+ caseInsensitive: false
26
+ });
27
+
28
+ // Custom name
29
+ const namedEvaluator = stringContainsEvaluator({
30
+ name: "contains-capital-city"
31
+ });
32
+ ```
33
+
34
+ The evaluator compares `output` against `data.expectedOutput` from the dataset and returns:
35
+ - `value: 1.0` and `pass: true` if output contains expected
36
+ - `value: 0.0` and `pass: false` otherwise
37
+
13
38
  ### Cosine Similarity Evaluator
14
39
 
15
40
  Compare semantic similarity between output and expected text using OpenAI embeddings:
16
41
 
17
42
  ```typescript
18
- import {
19
- cosineSimilarityEvaluator,
43
+ import {
44
+ cosineSimilarityEvaluator,
20
45
  cosineSimilarityThresholdEvaluator,
21
- simpleCosineSimilarity
46
+ simpleCosineSimilarity
22
47
  } from "@orq-ai/evaluators";
23
48
 
24
49
  // Simple usage - returns similarity score (0-1)
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./lib/cosine-similarity-evaluator.js";
2
+ export * from "./lib/string-contains-evaluator.js";
2
3
  export * from "./lib/vector-utils.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./lib/cosine-similarity-evaluator.js";
2
+ export * from "./lib/string-contains-evaluator.js";
2
3
  export * from "./lib/vector-utils.js";
@@ -0,0 +1,30 @@
1
+ import type { Evaluator } from "@orq-ai/evaluatorq";
2
+ /**
3
+ * Configuration options for the string contains evaluator
4
+ */
5
+ export interface StringContainsConfig {
6
+ /**
7
+ * Whether the comparison should be case-insensitive
8
+ * @default true
9
+ */
10
+ caseInsensitive?: boolean;
11
+ /**
12
+ * Optional name for the evaluator
13
+ * @default "string-contains"
14
+ */
15
+ name?: string;
16
+ }
17
+ /**
18
+ * Creates an evaluator that checks if the output contains the expected output.
19
+ * Uses the data.expectedOutput from the dataset to compare against.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const evaluator = stringContainsEvaluator();
24
+ *
25
+ * // With case-sensitive matching
26
+ * const strictEvaluator = stringContainsEvaluator({ caseInsensitive: false });
27
+ * ```
28
+ */
29
+ export declare function stringContainsEvaluator(config?: StringContainsConfig): Evaluator;
30
+ //# sourceMappingURL=string-contains-evaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-contains-evaluator.d.ts","sourceRoot":"","sources":["../../src/lib/string-contains-evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,GAAE,oBAAyB,GAChC,SAAS,CAiCX"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Creates an evaluator that checks if the output contains the expected output.
3
+ * Uses the data.expectedOutput from the dataset to compare against.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const evaluator = stringContainsEvaluator();
8
+ *
9
+ * // With case-sensitive matching
10
+ * const strictEvaluator = stringContainsEvaluator({ caseInsensitive: false });
11
+ * ```
12
+ */
13
+ export function stringContainsEvaluator(config = {}) {
14
+ const { caseInsensitive = true, name = "string-contains" } = config;
15
+ return {
16
+ name,
17
+ scorer: async ({ data, output }) => {
18
+ const expected = String(data.expectedOutput ?? "");
19
+ const actual = String(output ?? "");
20
+ if (!expected) {
21
+ return {
22
+ value: 0,
23
+ pass: false,
24
+ explanation: "No expected output defined",
25
+ };
26
+ }
27
+ const expectedNormalized = caseInsensitive
28
+ ? expected.toLowerCase()
29
+ : expected;
30
+ const actualNormalized = caseInsensitive ? actual.toLowerCase() : actual;
31
+ const contains = actualNormalized.includes(expectedNormalized);
32
+ return {
33
+ value: contains ? 1.0 : 0.0,
34
+ pass: contains,
35
+ explanation: contains
36
+ ? `Output contains "${expected}"`
37
+ : `Expected "${expected}" not found in: "${actual.substring(0, 100)}${actual.length > 100 ? "..." : ""}"`,
38
+ };
39
+ },
40
+ };
41
+ }