@arizeai/phoenix-evals 2.7.0 → 2.7.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @arizeai/phoenix-evals
2
2
 
3
+ ## 2.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0128562: fix(phoenix-evals): keep `metadata` returned by custom evaluator functions wrapped with `createEvaluator`
8
+
3
9
  ## 2.7.0
4
10
 
5
11
  ### Minor Changes
@@ -8,7 +8,7 @@ import type { EvaluationResult } from "../types/index.js";
8
8
  *
9
9
  * - **Numbers**: Converted to `{ score: number }`
10
10
  * - **Strings**: Converted to `{ label: string }`
11
- * - **Objects**: Extracts `score`, `label`, and `explanation` properties if present
11
+ * - **Objects**: Extracts `score`, `label`, `explanation`, and `metadata` properties if present
12
12
  * - **Other types**: Returns an empty `EvaluationResult` object
13
13
  *
14
14
  * This is particularly useful when creating evaluators from functions that may
@@ -17,7 +17,7 @@ import type { EvaluationResult } from "../types/index.js";
17
17
  * @param result - The value to convert to an EvaluationResult. Can be:
18
18
  * - A number (converted to score)
19
19
  * - A string (converted to label)
20
- * - An object with optional `score`, `label`, and/or `explanation` properties
20
+ * - An object with optional `score`, `label`, `explanation`, and/or `metadata` properties
21
21
  * - Any other value (returns empty object)
22
22
  *
23
23
  * @returns An {@link EvaluationResult} object with extracted properties
@@ -37,7 +37,7 @@ import type { EvaluationResult } from "../types/index.js";
37
37
  * ```
38
38
  *
39
39
  * @example
40
- * Convert an object with all properties:
40
+ * Convert an object with multiple properties:
41
41
  * ```typescript
42
42
  * const result = toEvaluationResult({
43
43
  * score: 0.9,
@@ -1 +1 @@
1
- {"version":3,"file":"toEvaluationResult.d.ts","sourceRoot":"","sources":["../../../src/helpers/toEvaluationResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAuDjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAyBpE"}
1
+ {"version":3,"file":"toEvaluationResult.d.ts","sourceRoot":"","sources":["../../../src/helpers/toEvaluationResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA4EjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CA4BpE"}
@@ -40,6 +40,22 @@ function resultHasExplanation(result) {
40
40
  "explanation" in result &&
41
41
  typeof result.explanation === "string");
42
42
  }
43
+ /**
44
+ * Type guard to check if a value has a metadata property.
45
+ *
46
+ * @param result - The value to check
47
+ * @returns True if the value is an object with a metadata record
48
+ *
49
+ * @internal
50
+ */
51
+ function resultHasMetadata(result) {
52
+ return (typeof result === "object" &&
53
+ result !== null &&
54
+ "metadata" in result &&
55
+ typeof result.metadata === "object" &&
56
+ result.metadata !== null &&
57
+ !Array.isArray(result.metadata));
58
+ }
43
59
  /**
44
60
  * Converts an unknown value to an {@link EvaluationResult}.
45
61
  *
@@ -49,7 +65,7 @@ function resultHasExplanation(result) {
49
65
  *
50
66
  * - **Numbers**: Converted to `{ score: number }`
51
67
  * - **Strings**: Converted to `{ label: string }`
52
- * - **Objects**: Extracts `score`, `label`, and `explanation` properties if present
68
+ * - **Objects**: Extracts `score`, `label`, `explanation`, and `metadata` properties if present
53
69
  * - **Other types**: Returns an empty `EvaluationResult` object
54
70
  *
55
71
  * This is particularly useful when creating evaluators from functions that may
@@ -58,7 +74,7 @@ function resultHasExplanation(result) {
58
74
  * @param result - The value to convert to an EvaluationResult. Can be:
59
75
  * - A number (converted to score)
60
76
  * - A string (converted to label)
61
- * - An object with optional `score`, `label`, and/or `explanation` properties
77
+ * - An object with optional `score`, `label`, `explanation`, and/or `metadata` properties
62
78
  * - Any other value (returns empty object)
63
79
  *
64
80
  * @returns An {@link EvaluationResult} object with extracted properties
@@ -78,7 +94,7 @@ function resultHasExplanation(result) {
78
94
  * ```
79
95
  *
80
96
  * @example
81
- * Convert an object with all properties:
97
+ * Convert an object with multiple properties:
82
98
  * ```typescript
83
99
  * const result = toEvaluationResult({
84
100
  * score: 0.9,
@@ -126,6 +142,9 @@ export function toEvaluationResult(result) {
126
142
  if (resultHasExplanation(result)) {
127
143
  evaluationResult.explanation = result.explanation;
128
144
  }
145
+ if (resultHasMetadata(result)) {
146
+ evaluationResult.metadata = result.metadata;
147
+ }
129
148
  return evaluationResult;
130
149
  }
131
150
  return {};
@@ -1 +1 @@
1
- {"version":3,"file":"toEvaluationResult.js","sourceRoot":"","sources":["../../../src/helpers/toEvaluationResult.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,SAAS,cAAc,CAAC,MAAe;IACrC,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,OAAO,IAAI,MAAM;QACjB,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CACjC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,cAAc,CAAC,MAAe;IACrC,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,OAAO,IAAI,MAAM;QACjB,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CACjC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,MAAe;IAEf,OAAO,CACL,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,aAAa,IAAI,MAAM;QACvB,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ,CACvC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;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