@arizeai/phoenix-evals 0.5.0 → 0.5.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/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 +3 -3
- package/dist/esm/template/applyTemplate.d.ts.map +1 -1
- package/dist/esm/template/applyTemplate.js +15 -1
- package/dist/esm/template/applyTemplate.js.map +1 -1
- package/dist/esm/template/createTemplateVariablesProxy.d.ts +1 -1
- package/dist/esm/template/createTemplateVariablesProxy.d.ts.map +1 -1
- package/dist/esm/template/createTemplateVariablesProxy.js.map +1 -1
- package/dist/esm/template/getTemplateVariables.d.ts +2 -2
- package/dist/esm/template/getTemplateVariables.d.ts.map +1 -1
- package/dist/esm/template/getTemplateVariables.js +16 -0
- package/dist/esm/template/getTemplateVariables.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/evals.d.ts +2 -2
- package/dist/esm/types/evals.d.ts.map +1 -1
- package/dist/esm/types/templating.d.ts +8 -6
- 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/template/applyTemplate.d.ts +3 -3
- package/dist/src/template/applyTemplate.d.ts.map +1 -1
- package/dist/src/template/applyTemplate.js +12 -1
- package/dist/src/template/applyTemplate.js.map +1 -1
- package/dist/src/template/createTemplateVariablesProxy.d.ts +1 -1
- package/dist/src/template/createTemplateVariablesProxy.d.ts.map +1 -1
- package/dist/src/template/createTemplateVariablesProxy.js.map +1 -1
- package/dist/src/template/getTemplateVariables.d.ts +2 -2
- package/dist/src/template/getTemplateVariables.d.ts.map +1 -1
- package/dist/src/template/getTemplateVariables.js +16 -0
- package/dist/src/template/getTemplateVariables.js.map +1 -1
- package/dist/src/types/evals.d.ts +2 -2
- package/dist/src/types/evals.d.ts.map +1 -1
- package/dist/src/types/templating.d.ts +8 -6
- package/dist/src/types/templating.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/llm/ClassificationEvaluator.ts +2 -2
- package/src/template/applyTemplate.ts +22 -9
- package/src/template/createTemplateVariablesProxy.ts +3 -3
- package/src/template/getTemplateVariables.ts +18 -2
- package/src/types/evals.ts +2 -2
- package/src/types/templating.ts +9 -6
|
@@ -13,7 +13,18 @@ const mustache_1 = __importDefault(require("mustache"));
|
|
|
13
13
|
function formatTemplate(args) {
|
|
14
14
|
const { template, variables } = args;
|
|
15
15
|
const variablesProxy = (0, createTemplateVariablesProxy_1.createTemplateVariablesProxy)(variables);
|
|
16
|
+
if (typeof template === "string") {
|
|
17
|
+
return renderTemplateString(template, variablesProxy);
|
|
18
|
+
}
|
|
19
|
+
return template.map((message) => {
|
|
20
|
+
if (message.content !== undefined && typeof message.content === "string") {
|
|
21
|
+
return Object.assign(Object.assign({}, message), { content: renderTemplateString(message.content, variablesProxy) });
|
|
22
|
+
}
|
|
23
|
+
return message;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function renderTemplateString(template, variables) {
|
|
16
27
|
// Disable HTML escaping by providing a custom escape function that returns text as-is
|
|
17
|
-
return mustache_1.default.render(template,
|
|
28
|
+
return mustache_1.default.render(template, variables, {}, { escape: (text) => text });
|
|
18
29
|
}
|
|
19
30
|
//# sourceMappingURL=applyTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTemplate.js","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":";;;;;AAUA,
|
|
1
|
+
{"version":3,"file":"applyTemplate.js","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":";;;;;AAUA,wCAkBC;AA1BD,iFAA8E;AAE9E,wDAAgC;AAEhC;;;GAGG;AACH,SAAgB,cAAc,CAAC,IAG9B;IACC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACrC,MAAM,cAAc,GAAG,IAAA,2DAA4B,EAAC,SAAS,CAAC,CAAC;IAC/D,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,oBAAoB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACzE,uCACK,OAAO,KACV,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAC9D;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAmB,CAAC;AACvB,CAAC;AAED,SAAS,oBAAoB,CAC3B,QAAgB,EAChB,SAAkC;IAElC,sFAAsF;IACtF,OAAO,kBAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* This allows Mustache to access properties of objects (e.g., {{user.name}}) while
|
|
4
4
|
* stringifying objects that are accessed as leaf values (e.g., {{user.profile}}).
|
|
5
5
|
*/
|
|
6
|
-
export declare function createTemplateVariablesProxy(obj:
|
|
6
|
+
export declare function createTemplateVariablesProxy<T>(obj: T): T;
|
|
7
7
|
//# sourceMappingURL=createTemplateVariablesProxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTemplateVariablesProxy.d.ts","sourceRoot":"","sources":["../../../src/template/createTemplateVariablesProxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"createTemplateVariablesProxy.d.ts","sourceRoot":"","sources":["../../../src/template/createTemplateVariablesProxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CA+DzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTemplateVariablesProxy.js","sourceRoot":"","sources":["../../../src/template/createTemplateVariablesProxy.ts"],"names":[],"mappings":";;AAKA,oEA+DC;AApED;;;;GAIG;AACH,SAAgB,4BAA4B,
|
|
1
|
+
{"version":3,"file":"createTemplateVariablesProxy.js","sourceRoot":"","sources":["../../../src/template/createTemplateVariablesProxy.ts"],"names":[],"mappings":";;AAKA,oEA+DC;AApED;;;;GAIG;AACH,SAAgB,4BAA4B,CAAI,GAAM;IACpD,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,GAAG,CAAC,4BAA4B,CAAM,CAAC;IACpD,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE;YACpB,GAAG,CAAC,MAAM,EAAE,IAAqB;gBAC/B,6EAA6E;gBAC7E,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;oBACxB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACtC,CAAC;gBACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC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,"file":"getTemplateVariables.d.ts","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"getTemplateVariables.d.ts","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AACF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,EAAE,CAW5E"}
|
|
@@ -12,6 +12,22 @@ const mustache_1 = __importDefault(require("mustache"));
|
|
|
12
12
|
*/
|
|
13
13
|
function getTemplateVariables(args) {
|
|
14
14
|
const { template } = args;
|
|
15
|
+
if (typeof template === "string") {
|
|
16
|
+
return getTemplateVariablesFromString(template);
|
|
17
|
+
}
|
|
18
|
+
return template.reduce((acc, message) => {
|
|
19
|
+
if (message.content !== undefined && typeof message.content === "string") {
|
|
20
|
+
return [...acc, ...getTemplateVariablesFromString(message.content)];
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
}, []);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse out the template variables of a string template
|
|
27
|
+
* @param template - The template to get the variables from
|
|
28
|
+
* @returns {string[]} a list of prompt template variables
|
|
29
|
+
*/
|
|
30
|
+
function getTemplateVariablesFromString(template) {
|
|
15
31
|
const templateSpans = mustache_1.default.parse(template);
|
|
16
32
|
return templateSpans.reduce((acc, templateSpan) => {
|
|
17
33
|
const [spanType, value] = templateSpan;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTemplateVariables.js","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":";;;;;AAYA,
|
|
1
|
+
{"version":3,"file":"getTemplateVariables.js","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":";;;;;AAYA,oDAWC;AArBD,wDAAgC;AAKhC;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,IAA6B;IAChE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC1B,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,8BAA8B,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QACtC,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACzE,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,8BAA8B,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAc,CAAC,CAAC;AACrB,CAAC;AACD;;;;GAIG;AACH,SAAS,8BAA8B,CAAC,QAAgB;IACtD,MAAM,aAAa,GAAG,kBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/C,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE;QAChD,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,YAAY,CAAC;QACvC,IAAI,QAAQ,KAAK,MAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrD,GAAG,GAAG,CAAC,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAc,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WithTelemetry } from "./otel";
|
|
2
|
-
import {
|
|
2
|
+
import { PromptTemplate } from "./templating";
|
|
3
3
|
import { LanguageModel } from "ai";
|
|
4
4
|
/**
|
|
5
5
|
* A specific AI example that is under evaluation
|
|
@@ -66,7 +66,7 @@ export interface CreateClassifierArgs extends WithTelemetry {
|
|
|
66
66
|
/**
|
|
67
67
|
* The prompt template to use for classification
|
|
68
68
|
*/
|
|
69
|
-
promptTemplate:
|
|
69
|
+
promptTemplate: PromptTemplate;
|
|
70
70
|
}
|
|
71
71
|
export interface CreateEvaluatorArgs {
|
|
72
72
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evals.d.ts","sourceRoot":"","sources":["../../../src/types/evals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"evals.d.ts","sourceRoot":"","sources":["../../../src/types/evals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,UAAU,EAAE,SAAS;IAClD,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,aAAa,CAAC;CACtB;AAGD,MAAM,WAAW,iBAAkB,SAAQ,OAAO;CAAG;AAErD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,C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CAAC;CACpC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ModelMessage } from "ai";
|
|
2
|
+
export type PromptTemplate = string | Array<ModelMessage>;
|
|
3
|
+
export type RenderedPrompt = string | Array<ModelMessage>;
|
|
2
4
|
export type TemplateVariables = Record<string, unknown>;
|
|
3
|
-
/**
|
|
4
|
-
* A class or object that has a prompt template
|
|
5
|
-
*/
|
|
6
5
|
export interface WithPromptTemplate {
|
|
7
|
-
readonly promptTemplate:
|
|
8
|
-
|
|
6
|
+
readonly promptTemplate: PromptTemplate;
|
|
7
|
+
/**
|
|
8
|
+
* List out the prompt template variables needed to perform evaluation
|
|
9
|
+
*/
|
|
10
|
+
readonly promptTemplateVariables: string[];
|
|
9
11
|
}
|
|
10
12
|
//# sourceMappingURL=templating.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../../src/types/templating.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../../src/types/templating.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAEvC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;AAC1D,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC;;OAEG;IACH,QAAQ,CAAC,uBAAuB,EAAE,MAAM,EAAE,CAAC;CAC5C"}
|