@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.
@@ -8,7 +8,7 @@ import type { EvaluationResult } from "../types";
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";
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";
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"}
@@ -43,6 +43,22 @@ function resultHasExplanation(result) {
43
43
  "explanation" in result &&
44
44
  typeof result.explanation === "string");
45
45
  }
46
+ /**
47
+ * Type guard to check if a value has a metadata property.
48
+ *
49
+ * @param result - The value to check
50
+ * @returns True if the value is an object with a metadata record
51
+ *
52
+ * @internal
53
+ */
54
+ function resultHasMetadata(result) {
55
+ return (typeof result === "object" &&
56
+ result !== null &&
57
+ "metadata" in result &&
58
+ typeof result.metadata === "object" &&
59
+ result.metadata !== null &&
60
+ !Array.isArray(result.metadata));
61
+ }
46
62
  /**
47
63
  * Converts an unknown value to an {@link EvaluationResult}.
48
64
  *
@@ -52,7 +68,7 @@ function resultHasExplanation(result) {
52
68
  *
53
69
  * - **Numbers**: Converted to `{ score: number }`
54
70
  * - **Strings**: Converted to `{ label: string }`
55
- * - **Objects**: Extracts `score`, `label`, and `explanation` properties if present
71
+ * - **Objects**: Extracts `score`, `label`, `explanation`, and `metadata` properties if present
56
72
  * - **Other types**: Returns an empty `EvaluationResult` object
57
73
  *
58
74
  * This is particularly useful when creating evaluators from functions that may
@@ -61,7 +77,7 @@ function resultHasExplanation(result) {
61
77
  * @param result - The value to convert to an EvaluationResult. Can be:
62
78
  * - A number (converted to score)
63
79
  * - A string (converted to label)
64
- * - An object with optional `score`, `label`, and/or `explanation` properties
80
+ * - An object with optional `score`, `label`, `explanation`, and/or `metadata` properties
65
81
  * - Any other value (returns empty object)
66
82
  *
67
83
  * @returns An {@link EvaluationResult} object with extracted properties
@@ -81,7 +97,7 @@ function resultHasExplanation(result) {
81
97
  * ```
82
98
  *
83
99
  * @example
84
- * Convert an object with all properties:
100
+ * Convert an object with multiple properties:
85
101
  * ```typescript
86
102
  * const result = toEvaluationResult({
87
103
  * score: 0.9,
@@ -129,6 +145,9 @@ function toEvaluationResult(result) {
129
145
  if (resultHasExplanation(result)) {
130
146
  evaluationResult.explanation = result.explanation;
131
147
  }
148
+ if (resultHasMetadata(result)) {
149
+ evaluationResult.metadata = result.metadata;
150
+ }
132
151
  return evaluationResult;
133
152
  }
134
153
  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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,4BAAmC,MAAe;IAChD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO;YACL,KAAK,EAAE,MAAM;SACd,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC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