@arizeai/phoenix-evals 0.4.0 → 0.5.0
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/dist/esm/llm/ClassificationEvaluator.d.ts +2 -2
- package/dist/esm/llm/ClassificationEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/ClassificationEvaluator.js.map +1 -1
- package/dist/esm/template/applyTemplate.d.ts.map +1 -1
- package/dist/esm/template/applyTemplate.js +3 -1
- package/dist/esm/template/applyTemplate.js.map +1 -1
- package/dist/esm/template/createTemplateVariablesProxy.d.ts +7 -0
- package/dist/esm/template/createTemplateVariablesProxy.d.ts.map +1 -0
- package/dist/esm/template/createTemplateVariablesProxy.js +61 -0
- package/dist/esm/template/createTemplateVariablesProxy.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/evals.d.ts +2 -1
- package/dist/esm/types/evals.d.ts.map +1 -1
- package/dist/esm/types/templating.d.ts +7 -0
- package/dist/esm/types/templating.d.ts.map +1 -1
- package/dist/src/llm/ClassificationEvaluator.d.ts +2 -2
- package/dist/src/llm/ClassificationEvaluator.d.ts.map +1 -1
- package/dist/src/llm/ClassificationEvaluator.js.map +1 -1
- package/dist/src/template/applyTemplate.d.ts.map +1 -1
- package/dist/src/template/applyTemplate.js +3 -1
- package/dist/src/template/applyTemplate.js.map +1 -1
- package/dist/src/template/createTemplateVariablesProxy.d.ts +7 -0
- package/dist/src/template/createTemplateVariablesProxy.d.ts.map +1 -0
- package/dist/src/template/createTemplateVariablesProxy.js +64 -0
- package/dist/src/template/createTemplateVariablesProxy.js.map +1 -0
- package/dist/src/types/evals.d.ts +2 -1
- package/dist/src/types/evals.d.ts.map +1 -1
- package/dist/src/types/templating.d.ts +7 -0
- package/dist/src/types/templating.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/llm/ClassificationEvaluator.ts +5 -3
- package/src/template/applyTemplate.ts +9 -1
- package/src/template/createTemplateVariablesProxy.ts +69 -0
- package/src/types/evals.ts +2 -1
- package/src/types/templating.ts +8 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Proxy that wraps an object to stringify nested object values when accessed directly.
|
|
3
|
+
* This allows Mustache to access properties of objects (e.g., {{user.name}}) while
|
|
4
|
+
* stringifying objects that are accessed as leaf values (e.g., {{user.profile}}).
|
|
5
|
+
*/
|
|
6
|
+
export function createTemplateVariablesProxy(obj: unknown): unknown {
|
|
7
|
+
if (obj === null || obj === undefined) {
|
|
8
|
+
return obj;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (Array.isArray(obj)) {
|
|
12
|
+
return obj.map(createTemplateVariablesProxy);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (typeof obj === "object") {
|
|
16
|
+
return new Proxy(obj as Record<string, unknown>, {
|
|
17
|
+
get(target, prop: string | symbol) {
|
|
18
|
+
// Handle toString and valueOf to stringify the object when accessed directly
|
|
19
|
+
if (prop === "toString") {
|
|
20
|
+
return () => JSON.stringify(target);
|
|
21
|
+
}
|
|
22
|
+
if (prop === "valueOf") {
|
|
23
|
+
return () => JSON.stringify(target);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof prop !== "string") {
|
|
27
|
+
return Reflect.get(target, prop);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const value = Reflect.get(target, prop);
|
|
31
|
+
|
|
32
|
+
// If the value is an object (not array, not null), wrap it in a proxy
|
|
33
|
+
// so it can be stringified if accessed directly, or have its properties accessed
|
|
34
|
+
if (
|
|
35
|
+
value !== null &&
|
|
36
|
+
typeof value === "object" &&
|
|
37
|
+
!Array.isArray(value)
|
|
38
|
+
) {
|
|
39
|
+
return createTemplateVariablesProxy(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return value;
|
|
43
|
+
},
|
|
44
|
+
// Override valueOf and toString to stringify the object when Mustache tries to render it directly
|
|
45
|
+
// Mustache will call toString() when it needs to render an object as a string
|
|
46
|
+
has(target, prop) {
|
|
47
|
+
if (prop === "toString" || prop === "valueOf") {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return Reflect.has(target, prop);
|
|
51
|
+
},
|
|
52
|
+
ownKeys(target) {
|
|
53
|
+
return Reflect.ownKeys(target);
|
|
54
|
+
},
|
|
55
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
56
|
+
if (prop === "toString") {
|
|
57
|
+
return {
|
|
58
|
+
enumerable: false,
|
|
59
|
+
configurable: true,
|
|
60
|
+
value: () => JSON.stringify(target),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
package/src/types/evals.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WithTelemetry } from "./otel";
|
|
2
|
+
import { Template } from "./templating";
|
|
2
3
|
|
|
3
4
|
import { LanguageModel } from "ai";
|
|
4
5
|
|
|
@@ -77,7 +78,7 @@ export interface CreateClassifierArgs extends WithTelemetry {
|
|
|
77
78
|
/**
|
|
78
79
|
* The prompt template to use for classification
|
|
79
80
|
*/
|
|
80
|
-
promptTemplate:
|
|
81
|
+
promptTemplate: Template;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
export interface CreateEvaluatorArgs {
|
package/src/types/templating.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export type Template = string;
|
|
2
2
|
export type TemplateVariables = Record<string, unknown>;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A class or object that has a prompt template
|
|
6
|
+
*/
|
|
7
|
+
export interface WithPromptTemplate {
|
|
8
|
+
readonly promptTemplate: Template;
|
|
9
|
+
get promptTemplateVariables(): string[];
|
|
10
|
+
}
|