@arizeai/phoenix-evals 0.5.0 → 0.6.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/README.md +42 -0
- package/dist/esm/core/EvaluatorBase.d.ts +19 -0
- package/dist/esm/core/EvaluatorBase.d.ts.map +1 -0
- package/dist/esm/core/EvaluatorBase.js +18 -0
- package/dist/esm/core/EvaluatorBase.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/llm/ClassificationEvaluator.d.ts +20 -3
- package/dist/esm/llm/ClassificationEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/ClassificationEvaluator.js +29 -2
- package/dist/esm/llm/ClassificationEvaluator.js.map +1 -1
- package/dist/esm/llm/LLMEvaluator.d.ts +4 -7
- package/dist/esm/llm/LLMEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/LLMEvaluator.js +4 -7
- package/dist/esm/llm/LLMEvaluator.js.map +1 -1
- package/dist/esm/llm/createClassificationEvaluator.d.ts +1 -1
- package/dist/esm/llm/createClassificationEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/createClassificationEvaluator.js.map +1 -1
- package/dist/esm/llm/createDocumentRelevancyEvaluator.d.ts +8 -7
- package/dist/esm/llm/createDocumentRelevancyEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/createDocumentRelevancyEvaluator.js +1 -2
- package/dist/esm/llm/createDocumentRelevancyEvaluator.js.map +1 -1
- package/dist/esm/llm/createHallucinationEvaluator.d.ts +6 -6
- package/dist/esm/llm/createHallucinationEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/createHallucinationEvaluator.js +1 -2
- package/dist/esm/llm/createHallucinationEvaluator.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/data.d.ts +194 -0
- package/dist/esm/types/data.d.ts.map +1 -0
- package/dist/esm/types/data.js +2 -0
- package/dist/esm/types/data.js.map +1 -0
- package/dist/esm/types/evals.d.ts +19 -5
- package/dist/esm/types/evals.d.ts.map +1 -1
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/otel.d.ts +14 -13
- package/dist/esm/types/otel.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/esm/utils/bindEvaluator.d.ts +219 -0
- package/dist/esm/utils/bindEvaluator.d.ts.map +1 -0
- package/dist/esm/utils/bindEvaluator.js +163 -0
- package/dist/esm/utils/bindEvaluator.js.map +1 -0
- package/dist/esm/utils/index.d.ts +2 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/objectMappingUtils.d.ts +166 -0
- package/dist/esm/utils/objectMappingUtils.d.ts.map +1 -0
- package/dist/esm/utils/objectMappingUtils.js +191 -0
- package/dist/esm/utils/objectMappingUtils.js.map +1 -0
- package/dist/src/core/EvaluatorBase.d.ts +19 -0
- package/dist/src/core/EvaluatorBase.d.ts.map +1 -0
- package/dist/src/core/EvaluatorBase.js +17 -0
- package/dist/src/core/EvaluatorBase.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/llm/ClassificationEvaluator.d.ts +20 -3
- package/dist/src/llm/ClassificationEvaluator.d.ts.map +1 -1
- package/dist/src/llm/ClassificationEvaluator.js +13 -2
- package/dist/src/llm/ClassificationEvaluator.js.map +1 -1
- package/dist/src/llm/LLMEvaluator.d.ts +4 -7
- package/dist/src/llm/LLMEvaluator.d.ts.map +1 -1
- package/dist/src/llm/LLMEvaluator.js +16 -5
- package/dist/src/llm/LLMEvaluator.js.map +1 -1
- package/dist/src/llm/createClassificationEvaluator.d.ts +1 -1
- package/dist/src/llm/createClassificationEvaluator.d.ts.map +1 -1
- package/dist/src/llm/createClassificationEvaluator.js.map +1 -1
- package/dist/src/llm/createDocumentRelevancyEvaluator.d.ts +8 -7
- package/dist/src/llm/createDocumentRelevancyEvaluator.d.ts.map +1 -1
- package/dist/src/llm/createDocumentRelevancyEvaluator.js +2 -2
- package/dist/src/llm/createDocumentRelevancyEvaluator.js.map +1 -1
- package/dist/src/llm/createHallucinationEvaluator.d.ts +6 -6
- package/dist/src/llm/createHallucinationEvaluator.d.ts.map +1 -1
- package/dist/src/llm/createHallucinationEvaluator.js +2 -2
- package/dist/src/llm/createHallucinationEvaluator.js.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/data.d.ts +194 -0
- package/dist/src/types/data.d.ts.map +1 -0
- package/dist/src/types/data.js +3 -0
- package/dist/src/types/data.js.map +1 -0
- package/dist/src/types/evals.d.ts +19 -5
- package/dist/src/types/evals.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +1 -0
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +1 -0
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/otel.d.ts +14 -13
- package/dist/src/types/otel.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/src/utils/bindEvaluator.d.ts +219 -0
- package/dist/src/utils/bindEvaluator.d.ts.map +1 -0
- package/dist/src/utils/bindEvaluator.js +166 -0
- package/dist/src/utils/bindEvaluator.js.map +1 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +18 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/objectMappingUtils.d.ts +166 -0
- package/dist/src/utils/objectMappingUtils.d.ts.map +1 -0
- package/dist/src/utils/objectMappingUtils.js +191 -0
- package/dist/src/utils/objectMappingUtils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
- package/src/core/EvaluatorBase.ts +43 -0
- package/src/index.ts +1 -0
- package/src/llm/ClassificationEvaluator.ts +41 -5
- package/src/llm/LLMEvaluator.ts +7 -16
- package/src/llm/createClassificationEvaluator.ts +1 -1
- package/src/llm/createDocumentRelevancyEvaluator.ts +17 -12
- package/src/llm/createHallucinationEvaluator.ts +12 -10
- package/src/template/applyTemplate.ts +22 -9
- package/src/template/createTemplateVariablesProxy.ts +3 -3
- package/src/template/getTemplateVariables.ts +18 -2
- package/src/types/data.ts +200 -0
- package/src/types/evals.ts +27 -7
- package/src/types/index.ts +1 -0
- package/src/types/otel.ts +15 -13
- package/src/types/templating.ts +9 -6
- package/src/utils/bindEvaluator.ts +229 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/objectMappingUtils.ts +202 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClassificationEvaluator = void 0;
|
|
4
4
|
const template_1 = require("../template");
|
|
5
|
+
const objectMappingUtils_1 = require("../utils/objectMappingUtils");
|
|
5
6
|
const createClassifierFn_1 = require("./createClassifierFn");
|
|
6
7
|
const LLMEvaluator_1 = require("./LLMEvaluator");
|
|
7
8
|
/**
|
|
@@ -11,10 +12,14 @@ class ClassificationEvaluator extends LLMEvaluator_1.LLMEvaluator {
|
|
|
11
12
|
constructor(args) {
|
|
12
13
|
super(args);
|
|
13
14
|
this.evaluate = (example) => {
|
|
14
|
-
return this.evaluatorFn(
|
|
15
|
+
return this.evaluatorFn(this.inputMapping
|
|
16
|
+
? (0, objectMappingUtils_1.remapObject)(example, this.inputMapping)
|
|
17
|
+
: example);
|
|
15
18
|
};
|
|
16
19
|
this.promptTemplate = args.promptTemplate;
|
|
17
|
-
this.
|
|
20
|
+
this.model = args.model;
|
|
21
|
+
this.choices = args.choices;
|
|
22
|
+
this.evaluatorFn = (0, createClassifierFn_1.createClassifierFn)(Object.assign({}, args));
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
20
25
|
* List out the prompt template variables needed to perform evaluation
|
|
@@ -29,6 +34,12 @@ class ClassificationEvaluator extends LLMEvaluator_1.LLMEvaluator {
|
|
|
29
34
|
// Give a copy of the variables
|
|
30
35
|
return [...this._promptTemplateVariables];
|
|
31
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Binds the input mapping to the evaluator. It makes a a copy of the evaluator and returns it.
|
|
39
|
+
*/
|
|
40
|
+
bindInputMapping(inputMapping) {
|
|
41
|
+
return new ClassificationEvaluator(Object.assign(Object.assign({}, this), { inputMapping }));
|
|
42
|
+
}
|
|
32
43
|
}
|
|
33
44
|
exports.ClassificationEvaluator = ClassificationEvaluator;
|
|
34
45
|
//# sourceMappingURL=ClassificationEvaluator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":";;;AAAA,0CAAmD;
|
|
1
|
+
{"version":3,"file":"ClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":";;;AAAA,0CAAmD;AASnD,oEAA0D;AAE1D,6DAA0D;AAC1D,iDAA8C;AAI9C;;GAEG;AACH,MAAa,uBACX,SAAQ,2BAAwB;IAkBhC,YAAY,IAAmD;QAC7D,KAAK,CAAC,IAAI,CAAC,CAAC;QAQd,aAAQ,GAAG,CAAC,OAAmB,EAAE,EAAE;YACjC,OAAO,IAAI,CAAC,WAAW,CACrB,IAAI,CAAC,YAAY;gBACf,CAAC,CAAC,IAAA,gCAAW,EAAa,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC;gBACrD,CAAC,CAAC,OAAO,CACZ,CAAC;QACJ,CAAC,CAAC;QAbA,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAA,uCAAkB,oBAChC,IAAI,EACP,CAAC;IACL,CAAC;IAQD;;OAEG;IACH,IAAI,uBAAuB;QACzB,0DAA0D;QAC1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,wBAAwB,GAAG,IAAA,+BAAoB,EAAC;gBACnD,QAAQ,EAAE,IAAI,CAAC,cAAc;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,+BAA+B;QAC/B,OAAO,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IACD;;OAEG;IACH,gBAAgB,CACd,YAAuC;QAEvC,OAAO,IAAI,uBAAuB,iCAC7B,IAAI,KACP,YAAY,IACZ,CAAC;IACL,CAAC;CACF;AA3DD,0DA2DC"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EvaluatorBase } from "../core/EvaluatorBase";
|
|
2
|
+
import { CreateLLMEvaluatorArgs } from "../types";
|
|
2
3
|
/**
|
|
3
4
|
* Base class for llm evaluation metrics / scores
|
|
4
5
|
*/
|
|
5
|
-
export declare abstract class LLMEvaluator<RecordType extends Record<string, unknown>>
|
|
6
|
-
|
|
7
|
-
readonly kind: "LLM";
|
|
8
|
-
readonly optimizationDirection?: OptimizationDirection;
|
|
9
|
-
constructor({ name, optimizationDirection }: CreateEvaluatorArgs);
|
|
10
|
-
abstract evaluate(_example: RecordType): Promise<EvaluationResult>;
|
|
6
|
+
export declare abstract class LLMEvaluator<RecordType extends Record<string, unknown>> extends EvaluatorBase<RecordType> {
|
|
7
|
+
constructor({ ...args }: CreateLLMEvaluatorArgs<RecordType>);
|
|
11
8
|
}
|
|
12
9
|
//# sourceMappingURL=LLMEvaluator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LLMEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/LLMEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"LLMEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/LLMEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,8BAAsB,YAAY,CAChC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC1C,SAAQ,aAAa,CAAC,UAAU,CAAC;gBACrB,EAAE,GAAG,IAAI,EAAE,EAAE,sBAAsB,CAAC,UAAU,CAAC;CAG5D"}
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.LLMEvaluator = void 0;
|
|
15
|
+
const EvaluatorBase_1 = require("../core/EvaluatorBase");
|
|
4
16
|
/**
|
|
5
17
|
* Base class for llm evaluation metrics / scores
|
|
6
18
|
*/
|
|
7
|
-
class LLMEvaluator {
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.optimizationDirection = optimizationDirection;
|
|
19
|
+
class LLMEvaluator extends EvaluatorBase_1.EvaluatorBase {
|
|
20
|
+
constructor(_a) {
|
|
21
|
+
var args = __rest(_a, []);
|
|
22
|
+
super(Object.assign({ kind: "LLM" }, args));
|
|
12
23
|
}
|
|
13
24
|
}
|
|
14
25
|
exports.LLMEvaluator = LLMEvaluator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LLMEvaluator.js","sourceRoot":"","sources":["../../../src/llm/LLMEvaluator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LLMEvaluator.js","sourceRoot":"","sources":["../../../src/llm/LLMEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,yDAAsD;AAGtD;;GAEG;AACH,MAAsB,YAEpB,SAAQ,6BAAyB;IACjC,YAAY,EAA+C;YAA1C,IAAI,cAAT,EAAW,CAAF;QACnB,KAAK,iBAAG,IAAI,EAAE,KAAK,IAAK,IAAI,EAAG,CAAC;IAClC,CAAC;CACF;AAND,oCAMC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CreateClassificationEvaluatorArgs } from "../types/evals";
|
|
2
2
|
import { ClassificationEvaluator } from "./ClassificationEvaluator";
|
|
3
|
-
export declare function createClassificationEvaluator<RecordType extends Record<string, unknown>>(args: CreateClassificationEvaluatorArgs): ClassificationEvaluator<RecordType>;
|
|
3
|
+
export declare function createClassificationEvaluator<RecordType extends Record<string, unknown>>(args: CreateClassificationEvaluatorArgs<RecordType>): ClassificationEvaluator<RecordType>;
|
|
4
4
|
//# sourceMappingURL=createClassificationEvaluator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClassificationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,wBAAgB,6BAA6B,CAC3C,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAE1C,IAAI,EAAE,iCAAiC,
|
|
1
|
+
{"version":3,"file":"createClassificationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,wBAAgB,6BAA6B,CAC3C,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAE1C,IAAI,EAAE,iCAAiC,CAAC,UAAU,CAAC,GAClD,uBAAuB,CAAC,UAAU,CAAC,CAErC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":";;AAIA,sEAMC;AARD,uEAAoE;AAEpE,SAAgB,6BAA6B,CAG3C,
|
|
1
|
+
{"version":3,"file":"createClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":";;AAIA,sEAMC;AARD,uEAAoE;AAEpE,SAAgB,6BAA6B,CAG3C,IAAmD;IAEnD,OAAO,IAAI,iDAAuB,CAAa,IAAI,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { CreateClassificationEvaluatorArgs
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { CreateClassificationEvaluatorArgs } from "../types/evals";
|
|
2
|
+
import { ClassificationEvaluator } from "./ClassificationEvaluator";
|
|
3
|
+
export interface DocumentRelevancyEvaluatorArgs<RecordType extends Record<string, unknown> = DocumentRelevancyEvaluationRecord> extends Omit<CreateClassificationEvaluatorArgs<RecordType>, "promptTemplate" | "choices" | "optimizationDirection" | "name"> {
|
|
4
|
+
optimizationDirection?: CreateClassificationEvaluatorArgs<RecordType>["optimizationDirection"];
|
|
5
|
+
name?: CreateClassificationEvaluatorArgs<RecordType>["name"];
|
|
6
|
+
choices?: CreateClassificationEvaluatorArgs<RecordType>["choices"];
|
|
7
|
+
promptTemplate?: CreateClassificationEvaluatorArgs<RecordType>["promptTemplate"];
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* A record to be evaluated by the document relevancy evaluator.
|
|
@@ -39,5 +40,5 @@ export interface DocumentRelevancyEvaluationRecord {
|
|
|
39
40
|
* console.log(result.label); // "relevant" or "unrelated"
|
|
40
41
|
* ```
|
|
41
42
|
*/
|
|
42
|
-
export declare function createDocumentRelevancyEvaluator<RecordType extends Record<string, unknown> = DocumentRelevancyEvaluationRecord>(args: DocumentRelevancyEvaluatorArgs):
|
|
43
|
+
export declare function createDocumentRelevancyEvaluator<RecordType extends Record<string, unknown> = DocumentRelevancyEvaluationRecord>(args: DocumentRelevancyEvaluatorArgs<RecordType>): ClassificationEvaluator<RecordType>;
|
|
43
44
|
//# sourceMappingURL=createDocumentRelevancyEvaluator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDocumentRelevancyEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createDocumentRelevancyEvaluator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,
|
|
1
|
+
{"version":3,"file":"createDocumentRelevancyEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createDocumentRelevancyEvaluator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAGpE,MAAM,WAAW,8BAA8B,CAC7C,UAAU,SAAS,MAAM,CACvB,MAAM,EACN,OAAO,CACR,GAAG,iCAAiC,CACrC,SAAQ,IAAI,CACV,iCAAiC,CAAC,UAAU,CAAC,EAC7C,gBAAgB,GAAG,SAAS,GAAG,uBAAuB,GAAG,MAAM,CAChE;IACD,qBAAqB,CAAC,EAAE,iCAAiC,CAAC,UAAU,CAAC,CAAC,uBAAuB,CAAC,CAAC;IAC/F,IAAI,CAAC,EAAE,iCAAiC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7D,OAAO,CAAC,EAAE,iCAAiC,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC;IACnE,cAAc,CAAC,EAAE,iCAAiC,CAAC,UAAU,CAAC,CAAC,gBAAgB,CAAC,CAAC;CAClF;AAED;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gCAAgC,CAC9C,UAAU,SAAS,MAAM,CACvB,MAAM,EACN,OAAO,CACR,GAAG,iCAAiC,EAErC,IAAI,EAAE,8BAA8B,CAAC,UAAU,CAAC,GAC/C,uBAAuB,CAAC,UAAU,CAAC,CAerC"}
|
|
@@ -42,9 +42,9 @@ const createClassificationEvaluator_1 = require("./createClassificationEvaluator
|
|
|
42
42
|
*/
|
|
43
43
|
function createDocumentRelevancyEvaluator(args) {
|
|
44
44
|
const { choices = DOCUMENT_RELEVANCY_TEMPLATE_1.DOCUMENT_RELEVANCY_CHOICES, promptTemplate = DOCUMENT_RELEVANCY_TEMPLATE_1.DOCUMENT_RELEVANCY_TEMPLATE, optimizationDirection = "MAXIMIZE", name = "document_relevancy" } = args, rest = __rest(args, ["choices", "promptTemplate", "optimizationDirection", "name"]);
|
|
45
|
-
return (0, createClassificationEvaluator_1.createClassificationEvaluator)(Object.assign(Object.assign(
|
|
45
|
+
return (0, createClassificationEvaluator_1.createClassificationEvaluator)(Object.assign(Object.assign({}, rest), { promptTemplate,
|
|
46
46
|
choices,
|
|
47
47
|
optimizationDirection,
|
|
48
|
-
name })
|
|
48
|
+
name }));
|
|
49
49
|
}
|
|
50
50
|
//# sourceMappingURL=createDocumentRelevancyEvaluator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDocumentRelevancyEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createDocumentRelevancyEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"createDocumentRelevancyEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createDocumentRelevancyEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;AA2DA,4EAsBC;AAjFD,kGAG0D;AAI1D,mFAAgF;AA0BhF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,gCAAgC,CAM9C,IAAgD;IAEhD,MAAM,EACJ,OAAO,GAAG,wDAA0B,EACpC,cAAc,GAAG,yDAA2B,EAC5C,qBAAqB,GAAG,UAAU,EAClC,IAAI,GAAG,oBAAoB,KAEzB,IAAI,EADH,IAAI,UACL,IAAI,EANF,8DAML,CAAO,CAAC;IACT,OAAO,IAAA,6DAA6B,kCAC/B,IAAI,KACP,cAAc;QACd,OAAO;QACP,qBAAqB;QACrB,IAAI,IACJ,CAAC;AACL,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CreateClassificationEvaluatorArgs } from "../types/evals";
|
|
2
2
|
import { ClassificationEvaluator } from "./ClassificationEvaluator";
|
|
3
|
-
export interface HallucinationEvaluatorArgs extends Omit<CreateClassificationEvaluatorArgs
|
|
4
|
-
optimizationDirection?: CreateClassificationEvaluatorArgs["optimizationDirection"];
|
|
5
|
-
name?: CreateClassificationEvaluatorArgs["name"];
|
|
6
|
-
choices?: CreateClassificationEvaluatorArgs["choices"];
|
|
7
|
-
promptTemplate?: CreateClassificationEvaluatorArgs["promptTemplate"];
|
|
3
|
+
export interface HallucinationEvaluatorArgs<RecordType extends Record<string, unknown> = HallucinationEvaluationRecord> extends Omit<CreateClassificationEvaluatorArgs<RecordType>, "promptTemplate" | "choices" | "optimizationDirection" | "name"> {
|
|
4
|
+
optimizationDirection?: CreateClassificationEvaluatorArgs<RecordType>["optimizationDirection"];
|
|
5
|
+
name?: CreateClassificationEvaluatorArgs<RecordType>["name"];
|
|
6
|
+
choices?: CreateClassificationEvaluatorArgs<RecordType>["choices"];
|
|
7
|
+
promptTemplate?: CreateClassificationEvaluatorArgs<RecordType>["promptTemplate"];
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* A record to be evaluated by the hallucination evaluator.
|
|
@@ -21,5 +21,5 @@ export type HallucinationEvaluationRecord = {
|
|
|
21
21
|
* @param args - The arguments for creating the hallucination evaluator.
|
|
22
22
|
* @returns A function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
|
|
23
23
|
*/
|
|
24
|
-
export declare function createHallucinationEvaluator<RecordType extends Record<string, unknown> = HallucinationEvaluationRecord>(args: HallucinationEvaluatorArgs): ClassificationEvaluator<RecordType>;
|
|
24
|
+
export declare function createHallucinationEvaluator<RecordType extends Record<string, unknown> = HallucinationEvaluationRecord>(args: HallucinationEvaluatorArgs<RecordType>): ClassificationEvaluator<RecordType>;
|
|
25
25
|
//# sourceMappingURL=createHallucinationEvaluator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHallucinationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAGpE,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"createHallucinationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAGpE,MAAM,WAAW,0BAA0B,CACzC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,6BAA6B,CAC1E,SAAQ,IAAI,CACV,iCAAiC,CAAC,UAAU,CAAC,EAC7C,gBAAgB,GAAG,SAAS,GAAG,uBAAuB,GAAG,MAAM,CAChE;IACD,qBAAqB,CAAC,EAAE,iCAAiC,CAAC,UAAU,CAAC,CAAC,uBAAuB,CAAC,CAAC;IAC/F,IAAI,CAAC,EAAE,iCAAiC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7D,OAAO,CAAC,EAAE,iCAAiC,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC;IACnE,cAAc,CAAC,EAAE,iCAAiC,CAAC,UAAU,CAAC,CAAC,gBAAgB,CAAC,CAAC;CAClF;AAED;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AACF;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,6BAA6B,EAE1E,IAAI,EAAE,0BAA0B,CAAC,UAAU,CAAC,GAC3C,uBAAuB,CAAC,UAAU,CAAC,CAerC"}
|
|
@@ -22,9 +22,9 @@ const createClassificationEvaluator_1 = require("./createClassificationEvaluator
|
|
|
22
22
|
*/
|
|
23
23
|
function createHallucinationEvaluator(args) {
|
|
24
24
|
const { choices = HALLUCINATION_TEMPLATE_1.HALLUCINATION_CHOICES, promptTemplate = HALLUCINATION_TEMPLATE_1.HALLUCINATION_TEMPLATE, optimizationDirection = "MINIMIZE", name = "hallucination" } = args, rest = __rest(args, ["choices", "promptTemplate", "optimizationDirection", "name"]);
|
|
25
|
-
return (0, createClassificationEvaluator_1.createClassificationEvaluator)(Object.assign(Object.assign(
|
|
25
|
+
return (0, createClassificationEvaluator_1.createClassificationEvaluator)(Object.assign(Object.assign({}, rest), { promptTemplate,
|
|
26
26
|
choices,
|
|
27
27
|
optimizationDirection,
|
|
28
|
-
name })
|
|
28
|
+
name }));
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=createHallucinationEvaluator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHallucinationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"createHallucinationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAoCA,oEAmBC;AAvDD,wFAGqD;AAIrD,mFAAgF;AAuBhF;;;;;GAKG;AACH,SAAgB,4BAA4B,CAG1C,IAA4C;IAE5C,MAAM,EACJ,OAAO,GAAG,8CAAqB,EAC/B,cAAc,GAAG,+CAAsB,EACvC,qBAAqB,GAAG,UAAU,EAClC,IAAI,GAAG,eAAe,KAEpB,IAAI,EADH,IAAI,UACL,IAAI,EANF,8DAML,CAAO,CAAC;IACT,OAAO,IAAA,6DAA6B,kCAC/B,IAAI,KACP,cAAc;QACd,OAAO;QACP,qBAAqB;QACrB,IAAI,IACJ,CAAC;AACL,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PromptTemplate, RenderedPrompt } from "../types/templating";
|
|
2
2
|
/**
|
|
3
3
|
* A function that applies a set of variables to a template (e.g. a prompt)
|
|
4
4
|
* Uses the Mustache library to apply the variables to the template
|
|
5
5
|
*/
|
|
6
6
|
export declare function formatTemplate(args: {
|
|
7
|
-
template:
|
|
7
|
+
template: PromptTemplate;
|
|
8
8
|
variables: Record<string, unknown>;
|
|
9
|
-
}):
|
|
9
|
+
}): RenderedPrompt;
|
|
10
10
|
//# sourceMappingURL=applyTemplate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTemplate.d.ts","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"applyTemplate.d.ts","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMrE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,QAAQ,EAAE,cAAc,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,cAAc,CAejB"}
|
|
@@ -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;gBACtC,CAAC;gBAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;oBAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBACnC,CAAC;gBAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAExC,sEAAsE;gBACtE,iFAAiF;gBACjF,IACE,KAAK,KAAK,IAAI;oBACd,OAAO,KAAK,KAAK,QAAQ;oBACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACrB,CAAC;oBACD,OAAO,4BAA4B,CAAC,KAAK,CAAC,CAAC;gBAC7C,CAAC;gBAED,OAAO,KAAK,CAAC;YACf,CAAC;YACD,kGAAkG;YAClG,8EAA8E;YAC9E,GAAG,CAAC,MAAM,EAAE,IAAI;gBACd,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9C,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;YACD,OAAO,CAAC,MAAM;gBACZ,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACjC,CAAC;YACD,wBAAwB,CAAC,MAAM,EAAE,IAAI;gBACnC,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;oBACxB,OAAO;wBACL,UAAU,EAAE,KAAK;wBACjB,YAAY,EAAE,IAAI;wBAClB,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;qBACpC,CAAC;gBACJ,CAAC;gBACD,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACxD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value extractor that can retrieve data from an object using various methods.
|
|
3
|
+
*
|
|
4
|
+
* This type supports multiple ways to extract values from your data structure:
|
|
5
|
+
* - **String paths**: Simple property names, dot notation, or JSONPath expressions
|
|
6
|
+
* - **Function extractors**: Custom transformation functions
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* **Simple property access:**
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const getter: ValueGetter<{ name: string }> = "name";
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* **Dot notation for nested properties:**
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const getter: ValueGetter<{ user: { profile: { name: string } } }> = "user.profile.name";
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* **Array element access:**
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const getter: ValueGetter<{ items: string[] }> = "items[0]";
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* **JSONPath expression:**
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const getter: ValueGetter<{ items: Array<{ id: number }> }> = "$.items[*].id";
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* **Function-based extraction:**
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const getter: ValueGetter<{ firstName: string; lastName: string }> =
|
|
36
|
+
* (data) => `${data.firstName} ${data.lastName}`;
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* **Complex transformation:**
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const getter: ValueGetter<{ scores: number[] }> =
|
|
43
|
+
* (data) => data.scores.reduce((a, b) => a + b, 0) / data.scores.length;
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @typeParam DataType - The type of the data object to extract values from
|
|
47
|
+
*/
|
|
48
|
+
export type ValueGetter<DataType extends Record<string, unknown>> = string | ((data: DataType) => any);
|
|
49
|
+
/**
|
|
50
|
+
* A mapping configuration that transforms data from one structure to another.
|
|
51
|
+
*
|
|
52
|
+
* This type defines how to map fields from your data structure to the fields
|
|
53
|
+
* expected by an evaluator or other component. The mapping is flexible and
|
|
54
|
+
* supports multiple extraction methods.
|
|
55
|
+
*
|
|
56
|
+
* **Key Features:**
|
|
57
|
+
* - Preserves original data fields
|
|
58
|
+
* - Adds/overrides fields with mapped values
|
|
59
|
+
* - Supports nested property access
|
|
60
|
+
* - Supports array element access
|
|
61
|
+
* - Supports JSONPath expressions for complex queries
|
|
62
|
+
* - Supports function-based transformations
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* **Basic field mapping:**
|
|
66
|
+
* ```typescript
|
|
67
|
+
* type MyData = {
|
|
68
|
+
* userQuery: string;
|
|
69
|
+
* context: string;
|
|
70
|
+
* response: string;
|
|
71
|
+
* };
|
|
72
|
+
*
|
|
73
|
+
* const mapping: ObjectMapping<MyData> = {
|
|
74
|
+
* input: "userQuery", // Map "input" to "userQuery"
|
|
75
|
+
* reference: "context", // Map "reference" to "context"
|
|
76
|
+
* output: "response", // Map "output" to "response"
|
|
77
|
+
* };
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* **Nested property mapping:**
|
|
82
|
+
* ```typescript
|
|
83
|
+
* type ApiData = {
|
|
84
|
+
* request: {
|
|
85
|
+
* body: {
|
|
86
|
+
* query: string;
|
|
87
|
+
* context: string;
|
|
88
|
+
* };
|
|
89
|
+
* };
|
|
90
|
+
* response: {
|
|
91
|
+
* data: {
|
|
92
|
+
* text: string;
|
|
93
|
+
* };
|
|
94
|
+
* };
|
|
95
|
+
* };
|
|
96
|
+
*
|
|
97
|
+
* const mapping: ObjectMapping<ApiData> = {
|
|
98
|
+
* input: "request.body.query",
|
|
99
|
+
* reference: "request.body.context",
|
|
100
|
+
* output: "response.data.text",
|
|
101
|
+
* };
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* **Array element access:**
|
|
106
|
+
* ```typescript
|
|
107
|
+
* type DataWithArrays = {
|
|
108
|
+
* messages: Array<{ role: string; content: string }>;
|
|
109
|
+
* sources: string[];
|
|
110
|
+
* };
|
|
111
|
+
*
|
|
112
|
+
* const mapping: ObjectMapping<DataWithArrays> = {
|
|
113
|
+
* firstMessage: "messages[0].content",
|
|
114
|
+
* lastSource: "sources[-1]", // Last element
|
|
115
|
+
* allRoles: "$.messages[*].role", // JSONPath for all roles
|
|
116
|
+
* };
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* **Function-based transformations:**
|
|
121
|
+
* ```typescript
|
|
122
|
+
* type RawData = {
|
|
123
|
+
* firstName: string;
|
|
124
|
+
* lastName: string;
|
|
125
|
+
* contexts: string[];
|
|
126
|
+
* scores: number[];
|
|
127
|
+
* };
|
|
128
|
+
*
|
|
129
|
+
* const mapping: ObjectMapping<RawData> = {
|
|
130
|
+
* // Combine fields
|
|
131
|
+
* fullName: (data) => `${data.firstName} ${data.lastName}`,
|
|
132
|
+
* // Transform array to string
|
|
133
|
+
* contextText: (data) => data.contexts.join("\n\n"),
|
|
134
|
+
* // Calculate derived value
|
|
135
|
+
* averageScore: (data) =>
|
|
136
|
+
* data.scores.reduce((a, b) => a + b, 0) / data.scores.length,
|
|
137
|
+
* // Conditional logic
|
|
138
|
+
* status: (data) => data.scores.length > 0 ? "active" : "inactive",
|
|
139
|
+
* };
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* **Mixed mapping types:**
|
|
144
|
+
* ```typescript
|
|
145
|
+
* type ComplexData = {
|
|
146
|
+
* user: {
|
|
147
|
+
* name: string;
|
|
148
|
+
* email: string;
|
|
149
|
+
* };
|
|
150
|
+
* items: Array<{ id: number; name: string }>;
|
|
151
|
+
* metadata: {
|
|
152
|
+
* tags: string[];
|
|
153
|
+
* };
|
|
154
|
+
* };
|
|
155
|
+
*
|
|
156
|
+
* const mapping: ObjectMapping<ComplexData> = {
|
|
157
|
+
* // Simple dot notation
|
|
158
|
+
* userName: "user.name",
|
|
159
|
+
* // Array access
|
|
160
|
+
* firstItemId: "items[0].id",
|
|
161
|
+
* // JSONPath for complex query
|
|
162
|
+
* allItemNames: "$.items[*].name",
|
|
163
|
+
* // Function for transformation
|
|
164
|
+
* formattedTags: (data) => data.metadata.tags.map(t => `#${t}`).join(" "),
|
|
165
|
+
* };
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* **Real-world evaluator binding:**
|
|
170
|
+
* ```typescript
|
|
171
|
+
* import { bindEvaluator, createHallucinationEvaluator } from "@arizeai/phoenix-evals";
|
|
172
|
+
*
|
|
173
|
+
* type QAData = {
|
|
174
|
+
* question: string;
|
|
175
|
+
* context: string;
|
|
176
|
+
* answer: string;
|
|
177
|
+
* };
|
|
178
|
+
*
|
|
179
|
+
* const mapping: ObjectMapping<QAData> = {
|
|
180
|
+
* input: "question", // Evaluator expects "input"
|
|
181
|
+
* reference: "context", // Evaluator expects "reference"
|
|
182
|
+
* output: "answer", // Evaluator expects "output"
|
|
183
|
+
* };
|
|
184
|
+
*
|
|
185
|
+
* const evaluator = bindEvaluator(
|
|
186
|
+
* createHallucinationEvaluator({ model: openai("gpt-4") }),
|
|
187
|
+
* { inputMapping: mapping }
|
|
188
|
+
* );
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @typeParam DataType - The type of the data object being mapped
|
|
192
|
+
*/
|
|
193
|
+
export type ObjectMapping<DataType extends Record<string, unknown>> = Record<string, ValueGetter<DataType>>;
|
|
194
|
+
//# sourceMappingURL=data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/types/data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC5D,MAAM,GAEN,CAAC,CAAC,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+IG;AACH,MAAM,MAAM,aAAa,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,MAAM,CAC1E,MAAM,EACN,WAAW,CAAC,QAAQ,CAAC,CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../../src/types/data.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ObjectMapping } from "./data";
|
|
1
2
|
import { WithTelemetry } from "./otel";
|
|
2
|
-
import {
|
|
3
|
+
import { PromptTemplate } from "./templating";
|
|
3
4
|
import { LanguageModel } from "ai";
|
|
4
5
|
/**
|
|
5
6
|
* A specific AI example that is under evaluation
|
|
@@ -66,21 +67,34 @@ export interface CreateClassifierArgs extends WithTelemetry {
|
|
|
66
67
|
/**
|
|
67
68
|
* The prompt template to use for classification
|
|
68
69
|
*/
|
|
69
|
-
promptTemplate:
|
|
70
|
+
promptTemplate: PromptTemplate;
|
|
70
71
|
}
|
|
71
|
-
export interface CreateEvaluatorArgs {
|
|
72
|
+
export interface CreateEvaluatorArgs<ExampleType extends Record<string, unknown> = Record<string, unknown>> extends WithTelemetry {
|
|
72
73
|
/**
|
|
73
74
|
* The name of the metric that the evaluator produces
|
|
74
75
|
* E.x. "correctness"
|
|
75
76
|
*/
|
|
76
77
|
name: string;
|
|
78
|
+
/**
|
|
79
|
+
* The kind of the evaluation. Also known as the "kind" of evaluator.
|
|
80
|
+
*/
|
|
81
|
+
kind: EvaluationKind;
|
|
77
82
|
/**
|
|
78
83
|
* If present, represents the direction in which you want the metric to be optimized
|
|
79
84
|
* E.x. "MAXIMIZE" means you want the number to be higher.
|
|
80
85
|
*/
|
|
81
86
|
optimizationDirection?: OptimizationDirection;
|
|
87
|
+
/**
|
|
88
|
+
* The mapping of the input to evaluate to the shape that the evaluator expects
|
|
89
|
+
*/
|
|
90
|
+
inputMapping?: ObjectMapping<ExampleType>;
|
|
82
91
|
}
|
|
83
|
-
export
|
|
92
|
+
export type CreateLLMEvaluatorArgs<RecordType extends Record<string, unknown>> = Omit<CreateEvaluatorArgs<RecordType>, "kind">;
|
|
93
|
+
export interface CreateClassificationEvaluatorArgs<RecordType extends Record<string, unknown>> extends CreateClassifierArgs, CreateLLMEvaluatorArgs<RecordType> {
|
|
94
|
+
/**
|
|
95
|
+
* The prompt template to use for classification
|
|
96
|
+
*/
|
|
97
|
+
promptTemplate: PromptTemplate;
|
|
84
98
|
}
|
|
85
99
|
export type EvaluatorFn<ExampleType extends Record<string, unknown>> = (args: ExampleType) => Promise<EvaluationResult>;
|
|
86
100
|
/**
|
|
@@ -114,7 +128,7 @@ interface EvaluatorDescription {
|
|
|
114
128
|
* The Base Evaluator interface
|
|
115
129
|
* This is the interface that all evaluators must implement
|
|
116
130
|
*/
|
|
117
|
-
export interface
|
|
131
|
+
export interface EvaluatorInterface<ExampleType extends Record<string, unknown>> extends EvaluatorDescription {
|
|
118
132
|
/**
|
|
119
133
|
* The function that evaluates the example
|
|
120
134
|
*/
|