@arizeai/phoenix-evals 0.2.0 → 0.2.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/README.md +20 -1
- package/dist/esm/llm/ClassificationEvaluator.d.ts +17 -0
- package/dist/esm/llm/ClassificationEvaluator.d.ts.map +1 -0
- package/dist/esm/llm/ClassificationEvaluator.js +33 -0
- package/dist/esm/llm/ClassificationEvaluator.js.map +1 -0
- package/dist/esm/llm/LLMEvaluator.d.ts +12 -0
- package/dist/esm/llm/LLMEvaluator.d.ts.map +1 -0
- package/dist/esm/llm/LLMEvaluator.js +13 -0
- package/dist/esm/llm/LLMEvaluator.js.map +1 -0
- package/dist/esm/llm/createClassificationEvaluator.d.ts +3 -2
- package/dist/esm/llm/createClassificationEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/createClassificationEvaluator.js +2 -7
- package/dist/esm/llm/createClassificationEvaluator.js.map +1 -1
- package/dist/esm/llm/createClassifierFn.d.ts +1 -1
- package/dist/esm/llm/createClassifierFn.d.ts.map +1 -1
- package/dist/esm/llm/createClassifierFn.js.map +1 -1
- package/dist/esm/llm/createDocumentRelevancyEvaluator.d.ts +5 -4
- package/dist/esm/llm/createDocumentRelevancyEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/createDocumentRelevancyEvaluator.js.map +1 -1
- package/dist/esm/llm/createHallucinationEvaluator.d.ts +5 -4
- package/dist/esm/llm/createHallucinationEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/createHallucinationEvaluator.js.map +1 -1
- package/dist/esm/llm/generateClassification.d.ts +2 -2
- package/dist/esm/llm/generateClassification.d.ts.map +1 -1
- package/dist/esm/llm/generateClassification.js.map +1 -1
- package/dist/esm/template/getTemplateVariables.d.ts +12 -0
- package/dist/esm/template/getTemplateVariables.d.ts.map +1 -0
- package/dist/esm/template/getTemplateVariables.js +18 -0
- package/dist/esm/template/getTemplateVariables.js.map +1 -0
- package/dist/esm/template/index.d.ts +1 -0
- package/dist/esm/template/index.d.ts.map +1 -1
- package/dist/esm/template/index.js +1 -0
- package/dist/esm/template/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/evals.d.ts +13 -6
- package/dist/esm/types/evals.d.ts.map +1 -1
- package/dist/esm/types/otel.d.ts +2 -2
- package/dist/esm/types/otel.d.ts.map +1 -1
- package/dist/esm/types/prompts.d.ts +2 -16
- package/dist/esm/types/prompts.d.ts.map +1 -1
- package/dist/src/llm/ClassificationEvaluator.d.ts +17 -0
- package/dist/src/llm/ClassificationEvaluator.d.ts.map +1 -0
- package/dist/src/llm/ClassificationEvaluator.js +34 -0
- package/dist/src/llm/ClassificationEvaluator.js.map +1 -0
- package/dist/src/llm/LLMEvaluator.d.ts +12 -0
- package/dist/src/llm/LLMEvaluator.d.ts.map +1 -0
- package/dist/src/llm/LLMEvaluator.js +15 -0
- package/dist/src/llm/LLMEvaluator.js.map +1 -0
- package/dist/src/llm/createClassificationEvaluator.d.ts +3 -2
- package/dist/src/llm/createClassificationEvaluator.d.ts.map +1 -1
- package/dist/src/llm/createClassificationEvaluator.js +2 -7
- package/dist/src/llm/createClassificationEvaluator.js.map +1 -1
- package/dist/src/llm/createClassifierFn.d.ts +1 -1
- package/dist/src/llm/createClassifierFn.d.ts.map +1 -1
- package/dist/src/llm/createClassifierFn.js.map +1 -1
- package/dist/src/llm/createDocumentRelevancyEvaluator.d.ts +5 -4
- package/dist/src/llm/createDocumentRelevancyEvaluator.d.ts.map +1 -1
- package/dist/src/llm/createDocumentRelevancyEvaluator.js.map +1 -1
- package/dist/src/llm/createHallucinationEvaluator.d.ts +5 -4
- package/dist/src/llm/createHallucinationEvaluator.d.ts.map +1 -1
- package/dist/src/llm/createHallucinationEvaluator.js.map +1 -1
- package/dist/src/llm/generateClassification.d.ts +2 -2
- package/dist/src/llm/generateClassification.d.ts.map +1 -1
- package/dist/src/llm/generateClassification.js.map +1 -1
- package/dist/src/template/getTemplateVariables.d.ts +12 -0
- package/dist/src/template/getTemplateVariables.d.ts.map +1 -0
- package/dist/src/template/getTemplateVariables.js +24 -0
- package/dist/src/template/getTemplateVariables.js.map +1 -0
- package/dist/src/template/index.d.ts +1 -0
- package/dist/src/template/index.d.ts.map +1 -1
- package/dist/src/template/index.js +1 -0
- package/dist/src/template/index.js.map +1 -1
- package/dist/src/types/evals.d.ts +13 -6
- package/dist/src/types/evals.d.ts.map +1 -1
- package/dist/src/types/otel.d.ts +2 -2
- package/dist/src/types/otel.d.ts.map +1 -1
- package/dist/src/types/prompts.d.ts +2 -16
- package/dist/src/types/prompts.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/llm/ClassificationEvaluator.ts +40 -0
- package/src/llm/LLMEvaluator.ts +22 -0
- package/src/llm/createClassificationEvaluator.ts +7 -10
- package/src/llm/createClassifierFn.ts +4 -4
- package/src/llm/createDocumentRelevancyEvaluator.ts +11 -7
- package/src/llm/createHallucinationEvaluator.ts +8 -7
- package/src/llm/generateClassification.ts +16 -14
- package/src/template/getTemplateVariables.ts +22 -0
- package/src/template/index.ts +1 -0
- package/src/types/evals.ts +18 -7
- package/src/types/otel.ts +2 -2
- package/src/types/prompts.ts +2 -17
package/README.md
CHANGED
|
@@ -12,7 +12,14 @@
|
|
|
12
12
|
</div>
|
|
13
13
|
</h1>
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://www.npmjs.com/package/@arizeai/phoenix-evals">
|
|
17
|
+
<img src="https://img.shields.io/npm/v/%40arizeai%2Fphoenix-evals" alt="NPM Version">
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://arize-ai.github.io/phoenix/">
|
|
20
|
+
<img src="https://img.shields.io/badge/docs-blue?logo=typescript&logoColor=white" alt="Documentation">
|
|
21
|
+
</a>
|
|
22
|
+
</p>
|
|
16
23
|
|
|
17
24
|
This package provides a TypeScript evaluation library. It is vendor agnostic and can be used in isolation of any framework or platform. This package is still under active development and is subject to change.
|
|
18
25
|
|
|
@@ -176,3 +183,15 @@ runExperiment({
|
|
|
176
183
|
evaluators: [hallucinationCheck],
|
|
177
184
|
});
|
|
178
185
|
```
|
|
186
|
+
|
|
187
|
+
## Community
|
|
188
|
+
|
|
189
|
+
Join our community to connect with thousands of AI builders:
|
|
190
|
+
|
|
191
|
+
- 🌍 Join our [Slack community](https://arize-ai.slack.com/join/shared_invite/zt-11t1vbu4x-xkBIHmOREQnYnYDH1GDfCg).
|
|
192
|
+
- 📚 Read the [Phoenix documentation](https://arize.com/docs/phoenix).
|
|
193
|
+
- 💡 Ask questions and provide feedback in the _#phoenix-support_ channel.
|
|
194
|
+
- 🌟 Leave a star on our [GitHub](https://github.com/Arize-ai/phoenix).
|
|
195
|
+
- 🐞 Report bugs with [GitHub Issues](https://github.com/Arize-ai/phoenix/issues).
|
|
196
|
+
- 𝕏 Follow us on [𝕏](https://twitter.com/ArizePhoenix).
|
|
197
|
+
- 🗺️ Check out our [roadmap](https://github.com/orgs/Arize-ai/projects/45) to see where we're heading next.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CreateClassificationEvaluatorArgs, EvaluatorFn, Template } from "../types/index.js";
|
|
2
|
+
import { LLMEvaluator } from "./LLMEvaluator.js";
|
|
3
|
+
/**
|
|
4
|
+
* An LLM evaluator that performs evaluation via classification
|
|
5
|
+
*/
|
|
6
|
+
export declare class ClassificationEvaluator<RecordType extends Record<string, unknown>> extends LLMEvaluator<RecordType> {
|
|
7
|
+
readonly evaluatorFn: EvaluatorFn<RecordType>;
|
|
8
|
+
readonly promptTemplate: Template;
|
|
9
|
+
private _promptTemplateVariables;
|
|
10
|
+
constructor(args: CreateClassificationEvaluatorArgs);
|
|
11
|
+
evaluate: (example: RecordType) => Promise<import("../types/index.js").EvaluationResult>;
|
|
12
|
+
/**
|
|
13
|
+
* List out the prompt template variables needed to perform evaluation
|
|
14
|
+
*/
|
|
15
|
+
get promptTemplateVariables(): string[];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ClassificationEvaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassificationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,WAAW,EACX,QAAQ,EACT,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;GAEG;AACH,qBAAa,uBAAuB,CAClC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC1C,SAAQ,YAAY,CAAC,UAAU,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAC9C,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC;IAClC,OAAO,CAAC,wBAAwB,CAAuB;gBAC3C,IAAI,EAAE,iCAAiC;IAKnD,QAAQ,GAAI,SAAS,UAAU,kDAE7B;IACF;;OAEG;IACH,IAAI,uBAAuB,IAAI,MAAM,EAAE,CAStC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createClassifierFn } from "./createClassifierFn.js";
|
|
2
|
+
import { LLMEvaluator } from "./LLMEvaluator.js";
|
|
3
|
+
import { getTemplateVariables } from "../template/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* An LLM evaluator that performs evaluation via classification
|
|
6
|
+
*/
|
|
7
|
+
export class ClassificationEvaluator extends LLMEvaluator {
|
|
8
|
+
evaluatorFn;
|
|
9
|
+
promptTemplate;
|
|
10
|
+
_promptTemplateVariables;
|
|
11
|
+
constructor(args) {
|
|
12
|
+
super(args);
|
|
13
|
+
this.promptTemplate = args.promptTemplate;
|
|
14
|
+
this.evaluatorFn = createClassifierFn(args);
|
|
15
|
+
}
|
|
16
|
+
evaluate = (example) => {
|
|
17
|
+
return this.evaluatorFn(example);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* List out the prompt template variables needed to perform evaluation
|
|
21
|
+
*/
|
|
22
|
+
get promptTemplateVariables() {
|
|
23
|
+
// Use dynamic programming to see if it's computed already
|
|
24
|
+
if (!Array.isArray(this._promptTemplateVariables)) {
|
|
25
|
+
this._promptTemplateVariables = getTemplateVariables({
|
|
26
|
+
template: this.promptTemplate,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Give a copy of the variables
|
|
30
|
+
return [...this._promptTemplateVariables];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ClassificationEvaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,uBAEX,SAAQ,YAAwB;IACvB,WAAW,CAA0B;IACrC,cAAc,CAAW;IAC1B,wBAAwB,CAAuB;IACvD,YAAY,IAAuC;QACjD,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,kBAAkB,CAAa,IAAI,CAAC,CAAC;IAC1D,CAAC;IACD,QAAQ,GAAG,CAAC,OAAmB,EAAE,EAAE;QACjC,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC,CAAC;IACF;;OAEG;IACH,IAAI,uBAAuB;QACzB,0DAA0D;QAC1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,wBAAwB,GAAG,oBAAoB,CAAC;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;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EvaluationResult, Evaluator, OptimizationDirection, CreateEvaluatorArgs } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for llm evaluation metrics / scores
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class LLMEvaluator<RecordType extends Record<string, unknown>> implements Evaluator<RecordType> {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly source: "LLM";
|
|
8
|
+
readonly optimizationDirection?: OptimizationDirection;
|
|
9
|
+
constructor({ name, optimizationDirection }: CreateEvaluatorArgs);
|
|
10
|
+
abstract evaluate(_example: RecordType): Promise<EvaluationResult>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=LLMEvaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LLMEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/LLMEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,8BAAsB,YAAY,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3E,YAAW,SAAS,CAAC,UAAU,CAAC;IAEhC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAG,KAAK,CAAU;IACjC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;gBAC3C,EAAE,IAAI,EAAE,qBAAqB,EAAE,EAAE,mBAAmB;IAIhE,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;CACnE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for llm evaluation metrics / scores
|
|
3
|
+
*/
|
|
4
|
+
export class LLMEvaluator {
|
|
5
|
+
name;
|
|
6
|
+
source = "LLM";
|
|
7
|
+
optimizationDirection;
|
|
8
|
+
constructor({ name, optimizationDirection }) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.optimizationDirection = optimizationDirection;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=LLMEvaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LLMEvaluator.js","sourceRoot":"","sources":["../../../src/llm/LLMEvaluator.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAgB,YAAY;IAGvB,IAAI,CAAS;IACb,MAAM,GAAG,KAAc,CAAC;IACxB,qBAAqB,CAAyB;IACvD,YAAY,EAAE,IAAI,EAAE,qBAAqB,EAAuB;QAC9D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACrD,CAAC;CAEF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { CreateClassificationEvaluatorArgs
|
|
2
|
-
|
|
1
|
+
import { CreateClassificationEvaluatorArgs } from "../types/evals.js";
|
|
2
|
+
import { ClassificationEvaluator } from "./ClassificationEvaluator.js";
|
|
3
|
+
export declare function createClassificationEvaluator<RecordType extends Record<string, unknown>>(args: CreateClassificationEvaluatorArgs): ClassificationEvaluator<RecordType>;
|
|
3
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,
|
|
1
|
+
{"version":3,"file":"createClassificationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,wBAAgB,6BAA6B,CAC3C,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAE1C,IAAI,EAAE,iCAAiC,GACtC,uBAAuB,CAAC,UAAU,CAAC,CAErC"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClassificationEvaluator } from "./ClassificationEvaluator.js";
|
|
2
2
|
export function createClassificationEvaluator(args) {
|
|
3
|
-
return
|
|
4
|
-
name: args.name,
|
|
5
|
-
source: "LLM",
|
|
6
|
-
optimizationDirection: args.optimizationDirection,
|
|
7
|
-
evaluate: createClassifierFn(args),
|
|
8
|
-
};
|
|
3
|
+
return new ClassificationEvaluator(args);
|
|
9
4
|
}
|
|
10
5
|
//# sourceMappingURL=createClassificationEvaluator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"createClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,UAAU,6BAA6B,CAG3C,IAAuC;IAEvC,OAAO,IAAI,uBAAuB,CAAa,IAAI,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -2,5 +2,5 @@ import { CreateClassifierArgs, EvaluatorFn } from "../types/evals.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* A function that serves as a factory that will output a classification evaluator function
|
|
4
4
|
*/
|
|
5
|
-
export declare function createClassifierFn<
|
|
5
|
+
export declare function createClassifierFn<RecordToEvaluate extends Record<string, unknown>>(args: CreateClassifierArgs): EvaluatorFn<RecordToEvaluate>;
|
|
6
6
|
//# sourceMappingURL=createClassifierFn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClassifierFn.d.ts","sourceRoot":"","sources":["../../../src/llm/createClassifierFn.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,oBAAoB,EACpB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAkBxB;;GAEG;AACH,wBAAgB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"createClassifierFn.d.ts","sourceRoot":"","sources":["../../../src/llm/createClassifierFn.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,oBAAoB,EACpB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAkBxB;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,gBAAgB,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChD,IAAI,EAAE,oBAAoB,GAAG,WAAW,CAAC,gBAAgB,CAAC,CA4B3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClassifierFn.js","sourceRoot":"","sources":["../../../src/llm/createClassifierFn.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;GAGG;AACH,SAAS,eAAe,CACtB,OAAiC;IAEjC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,MAA+B,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,
|
|
1
|
+
{"version":3,"file":"createClassifierFn.js","sourceRoot":"","sources":["../../../src/llm/createClassifierFn.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;GAGG;AACH,SAAS,eAAe,CACtB,OAAiC;IAEjC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,MAA+B,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAEhC,IAA0B;IAC1B,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAEzD,OAAO,KAAK,EAAE,IAAsB,EAA6B,EAAE;QACjE,MAAM,iBAAiB,GAAG;YACxB,GAAG,IAAI;SACR,CAAC;QAEF,MAAM,MAAM,GAAG,cAAc,CAAC;YAC5B,QAAQ,EAAE,cAAc;YACxB,SAAS,EAAE,iBAAiB;SAC7B,CAAC,CAAC;QAEH,MAAM,cAAc,GAAG,MAAM,sBAAsB,CAAC;YAClD,KAAK;YACL,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC;YAChC,MAAM;YACN,GAAG,IAAI;SACR,CAAC,CAAC;QAEH,mEAAmE;QACnE,MAAM,KAAK,GAAG,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAE5C,OAAO;YACL,KAAK;YACL,GAAG,cAAc;SAClB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -6,12 +6,13 @@ export interface DocumentRelevancyEvaluatorArgs extends Omit<CreateClassificatio
|
|
|
6
6
|
promptTemplate?: CreateClassificationEvaluatorArgs["promptTemplate"];
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* A record to be evaluated by the document relevancy evaluator.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export interface DocumentRelevancyEvaluationRecord {
|
|
12
12
|
input: string;
|
|
13
13
|
documentText: string;
|
|
14
|
-
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
15
16
|
/**
|
|
16
17
|
* Creates a document relevancy evaluator function.
|
|
17
18
|
*
|
|
@@ -38,5 +39,5 @@ export type DocumentRelevancyExample = {
|
|
|
38
39
|
* console.log(result.label); // "relevant" or "unrelated"
|
|
39
40
|
* ```
|
|
40
41
|
*/
|
|
41
|
-
export declare function createDocumentRelevancyEvaluator(args: DocumentRelevancyEvaluatorArgs): Evaluator<
|
|
42
|
+
export declare function createDocumentRelevancyEvaluator<RecordType extends Record<string, unknown> = DocumentRelevancyEvaluationRecord>(args: DocumentRelevancyEvaluatorArgs): Evaluator<RecordType>;
|
|
42
43
|
//# sourceMappingURL=createDocumentRelevancyEvaluator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDocumentRelevancyEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createDocumentRelevancyEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAO9E,MAAM,WAAW,8BACf,SAAQ,IAAI,CACV,iCAAiC,EACjC,gBAAgB,GAAG,SAAS,GAAG,uBAAuB,GAAG,MAAM,CAChE;IACD,qBAAqB,CAAC,EAAE,iCAAiC,CAAC,uBAAuB,CAAC,CAAC;IACnF,IAAI,CAAC,EAAE,iCAAiC,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,EAAE,iCAAiC,CAAC,SAAS,CAAC,CAAC;IACvD,cAAc,CAAC,EAAE,iCAAiC,CAAC,gBAAgB,CAAC,CAAC;CACtE;AAED;;GAEG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"createDocumentRelevancyEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createDocumentRelevancyEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAO9E,MAAM,WAAW,8BACf,SAAQ,IAAI,CACV,iCAAiC,EACjC,gBAAgB,GAAG,SAAS,GAAG,uBAAuB,GAAG,MAAM,CAChE;IACD,qBAAqB,CAAC,EAAE,iCAAiC,CAAC,uBAAuB,CAAC,CAAC;IACnF,IAAI,CAAC,EAAE,iCAAiC,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,EAAE,iCAAiC,CAAC,SAAS,CAAC,CAAC;IACvD,cAAc,CAAC,EAAE,iCAAiC,CAAC,gBAAgB,CAAC,CAAC;CACtE;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,EACrC,IAAI,EAAE,8BAA8B,GAAG,SAAS,CAAC,UAAU,CAAC,CAiB7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDocumentRelevancyEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createDocumentRelevancyEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,GAC3B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"createDocumentRelevancyEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createDocumentRelevancyEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,GAC3B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAsBhF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,gCAAgC,CAK9C,IAAoC;IACpC,MAAM,EACJ,OAAO,GAAG,0BAA0B,EACpC,cAAc,GAAG,2BAA2B,EAC5C,qBAAqB,GAAG,UAAU,EAClC,IAAI,GAAG,oBAAoB,EAC3B,GAAG,IAAI,EACR,GAAG,IAAI,CAAC;IAET,OAAO,6BAA6B,CAAa;QAC/C,GAAG,IAAI;QACP,cAAc;QACd,OAAO;QACP,qBAAqB;QACrB,IAAI;QACJ,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CreateClassificationEvaluatorArgs
|
|
1
|
+
import { CreateClassificationEvaluatorArgs } from "../types/evals.js";
|
|
2
|
+
import { ClassificationEvaluator } from "./ClassificationEvaluator.js";
|
|
2
3
|
export interface HallucinationEvaluatorArgs extends Omit<CreateClassificationEvaluatorArgs, "promptTemplate" | "choices" | "optimizationDirection" | "name"> {
|
|
3
4
|
optimizationDirection?: CreateClassificationEvaluatorArgs["optimizationDirection"];
|
|
4
5
|
name?: CreateClassificationEvaluatorArgs["name"];
|
|
@@ -6,9 +7,9 @@ export interface HallucinationEvaluatorArgs extends Omit<CreateClassificationEva
|
|
|
6
7
|
promptTemplate?: CreateClassificationEvaluatorArgs["promptTemplate"];
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* A record to be evaluated by the hallucination evaluator.
|
|
10
11
|
*/
|
|
11
|
-
export type
|
|
12
|
+
export type HallucinationEvaluationRecord = {
|
|
12
13
|
input: string;
|
|
13
14
|
output: string;
|
|
14
15
|
reference?: string;
|
|
@@ -20,5 +21,5 @@ export type HallucinationExample = {
|
|
|
20
21
|
* @param args - The arguments for creating the hallucination evaluator.
|
|
21
22
|
* @returns A function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
|
|
22
23
|
*/
|
|
23
|
-
export declare function createHallucinationEvaluator(args: HallucinationEvaluatorArgs):
|
|
24
|
+
export declare function createHallucinationEvaluator<RecordType extends Record<string, unknown> = HallucinationEvaluationRecord>(args: HallucinationEvaluatorArgs): ClassificationEvaluator<RecordType>;
|
|
24
25
|
//# sourceMappingURL=createHallucinationEvaluator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHallucinationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,
|
|
1
|
+
{"version":3,"file":"createHallucinationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAMnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,WAAW,0BACf,SAAQ,IAAI,CACV,iCAAiC,EACjC,gBAAgB,GAAG,SAAS,GAAG,uBAAuB,GAAG,MAAM,CAChE;IACD,qBAAqB,CAAC,EAAE,iCAAiC,CAAC,uBAAuB,CAAC,CAAC;IACnF,IAAI,CAAC,EAAE,iCAAiC,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,EAAE,iCAAiC,CAAC,SAAS,CAAC,CAAC;IACvD,cAAc,CAAC,EAAE,iCAAiC,CAAC,gBAAgB,CAAC,CAAC;CACtE;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,EAC1E,IAAI,EAAE,0BAA0B,GAAG,uBAAuB,CAAC,UAAU,CAAC,CAgBvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHallucinationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"createHallucinationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAuBhF;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAE1C,IAAgC;IAChC,MAAM,EACJ,OAAO,GAAG,qBAAqB,EAC/B,cAAc,GAAG,sBAAsB,EACvC,qBAAqB,GAAG,UAAU,EAClC,IAAI,GAAG,eAAe,EACtB,GAAG,IAAI,EACR,GAAG,IAAI,CAAC;IACT,OAAO,6BAA6B,CAAa;QAC/C,GAAG,IAAI;QACP,cAAc;QACd,OAAO;QACP,qBAAqB;QACrB,IAAI;QACJ,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClassificationResult, WithLLM } from "../types/evals.js";
|
|
2
2
|
import { WithTelemetry } from "../types/otel.js";
|
|
3
3
|
import type { WithPrompt } from "../types/prompts.js";
|
|
4
|
-
export
|
|
4
|
+
export type ClassifyArgs = WithLLM & WithTelemetry & WithPrompt & {
|
|
5
5
|
/**
|
|
6
6
|
* The labels to classify the example into. E.x. ["correct", "incorrect"]
|
|
7
7
|
*/
|
|
@@ -14,7 +14,7 @@ export interface ClassifyArgs extends WithLLM, WithPrompt, WithTelemetry {
|
|
|
14
14
|
* The description of the schema for generating the label and explanation.
|
|
15
15
|
*/
|
|
16
16
|
schemaDescription?: string;
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
18
|
/**
|
|
19
19
|
* A function that leverages an llm to perform a classification
|
|
20
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClassification.d.ts","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,MAAM,
|
|
1
|
+
{"version":3,"file":"generateClassification.d.ts","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,MAAM,MAAM,YAAY,GAAG,OAAO,GAChC,aAAa,GACb,UAAU,GAAG;IACX;;OAEG;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IAC9B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AACJ;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAyB/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAAkB;IAElB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAC1E,IAAI,CAAC;IAEP,MAAM,sBAAsB,GAAG;QAC7B,SAAS,EAAE,SAAS,EAAE,SAAS,IAAI,IAAI;QACvC,UAAU,EAAE,wBAAwB;QACpC,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,MAAM;KACpC,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC;QAClC,KAAK;QACL,UAAU;QACV,iBAAiB;QACjB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,4EAA4E;YACrG,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;SACtB,CAAC;QACF,sBAAsB;QACtB,GAAG,MAAM;KACV,CAAC,CAAC;IACH,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;QAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW;KACvC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Template } from "../types/templating.js";
|
|
2
|
+
type GetTemplateVariableArgs = {
|
|
3
|
+
template: Template;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Parse out the template variables of a prompt
|
|
7
|
+
* @param {GetTemplateVariableArgs} args
|
|
8
|
+
* @returns {string[]} a list of prompt template variables
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTemplateVariables(args: GetTemplateVariableArgs): string[];
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=getTemplateVariables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTemplateVariables.d.ts","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AACF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,EAAE,CAU5E"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Mustache from "mustache";
|
|
2
|
+
/**
|
|
3
|
+
* Parse out the template variables of a prompt
|
|
4
|
+
* @param {GetTemplateVariableArgs} args
|
|
5
|
+
* @returns {string[]} a list of prompt template variables
|
|
6
|
+
*/
|
|
7
|
+
export function getTemplateVariables(args) {
|
|
8
|
+
const { template } = args;
|
|
9
|
+
const templateSpans = Mustache.parse(template);
|
|
10
|
+
return templateSpans.reduce((acc, templateSpan) => {
|
|
11
|
+
const [spanType, value] = templateSpan;
|
|
12
|
+
if (spanType === "name" && typeof value === "string") {
|
|
13
|
+
acc = [...acc, value];
|
|
14
|
+
}
|
|
15
|
+
return acc;
|
|
16
|
+
}, []);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=getTemplateVariables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTemplateVariables.js","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAKhC;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAA6B;IAChE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC1B,MAAM,aAAa,GAAG,QAAQ,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/template/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/template/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/template/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/template/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC"}
|