@arizeai/phoenix-evals 0.0.1 → 0.0.3

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.
Files changed (121) hide show
  1. package/README.md +56 -0
  2. package/dist/esm/default_templates/HALLUCINATION_TEMPLATE.d.ts +6 -0
  3. package/dist/esm/default_templates/HALLUCINATION_TEMPLATE.d.ts.map +1 -0
  4. package/dist/esm/default_templates/HALLUCINATION_TEMPLATE.js +31 -0
  5. package/dist/esm/default_templates/HALLUCINATION_TEMPLATE.js.map +1 -0
  6. package/dist/esm/default_templates/index.d.ts +2 -0
  7. package/dist/esm/default_templates/index.d.ts.map +1 -0
  8. package/dist/esm/default_templates/index.js +2 -0
  9. package/dist/esm/default_templates/index.js.map +1 -0
  10. package/dist/esm/index.d.ts +1 -0
  11. package/dist/esm/index.d.ts.map +1 -1
  12. package/dist/esm/index.js +1 -1
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/llm/createClassifier.d.ts +6 -0
  15. package/dist/esm/llm/createClassifier.d.ts.map +1 -0
  16. package/dist/esm/llm/createClassifier.js +40 -0
  17. package/dist/esm/llm/createClassifier.js.map +1 -0
  18. package/dist/esm/llm/createHallucinationEvaluator.d.ts +14 -0
  19. package/dist/esm/llm/createHallucinationEvaluator.d.ts.map +1 -0
  20. package/dist/esm/llm/createHallucinationEvaluator.js +18 -0
  21. package/dist/esm/llm/createHallucinationEvaluator.js.map +1 -0
  22. package/dist/esm/llm/generateClassification.d.ts +22 -0
  23. package/dist/esm/llm/generateClassification.d.ts.map +1 -0
  24. package/dist/esm/llm/generateClassification.js +23 -0
  25. package/dist/esm/llm/generateClassification.js.map +1 -0
  26. package/dist/esm/llm/index.d.ts +4 -0
  27. package/dist/esm/llm/index.d.ts.map +1 -0
  28. package/dist/esm/llm/index.js +4 -0
  29. package/dist/esm/llm/index.js.map +1 -0
  30. package/dist/esm/template/applyTemplate.d.ts +10 -0
  31. package/dist/esm/template/applyTemplate.d.ts.map +1 -0
  32. package/dist/esm/template/applyTemplate.js +10 -0
  33. package/dist/esm/template/applyTemplate.js.map +1 -0
  34. package/dist/esm/template/index.d.ts +2 -0
  35. package/dist/esm/template/index.d.ts.map +1 -0
  36. package/dist/esm/template/index.js +2 -0
  37. package/dist/esm/template/index.js.map +1 -0
  38. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  39. package/dist/esm/types/evals.d.ts +73 -0
  40. package/dist/esm/types/evals.d.ts.map +1 -0
  41. package/dist/esm/types/evals.js +2 -0
  42. package/dist/esm/types/evals.js.map +1 -0
  43. package/dist/esm/types/index.d.ts +3 -0
  44. package/dist/esm/types/index.d.ts.map +1 -0
  45. package/dist/esm/types/index.js +3 -0
  46. package/dist/esm/types/index.js.map +1 -0
  47. package/dist/esm/types/prompts.d.ts +21 -0
  48. package/dist/esm/types/prompts.d.ts.map +1 -0
  49. package/dist/esm/types/prompts.js +2 -0
  50. package/dist/esm/types/prompts.js.map +1 -0
  51. package/dist/esm/types/templating.d.ts +3 -0
  52. package/dist/esm/types/templating.d.ts.map +1 -0
  53. package/dist/esm/types/templating.js +2 -0
  54. package/dist/esm/types/templating.js.map +1 -0
  55. package/dist/src/default_templates/HALLUCINATION_TEMPLATE.d.ts +6 -0
  56. package/dist/src/default_templates/HALLUCINATION_TEMPLATE.d.ts.map +1 -0
  57. package/dist/src/default_templates/HALLUCINATION_TEMPLATE.js +34 -0
  58. package/dist/src/default_templates/HALLUCINATION_TEMPLATE.js.map +1 -0
  59. package/dist/src/default_templates/index.d.ts +2 -0
  60. package/dist/src/default_templates/index.d.ts.map +1 -0
  61. package/dist/src/default_templates/index.js +18 -0
  62. package/dist/src/default_templates/index.js.map +1 -0
  63. package/dist/src/index.d.ts +1 -0
  64. package/dist/src/index.d.ts.map +1 -1
  65. package/dist/src/index.js +16 -0
  66. package/dist/src/index.js.map +1 -1
  67. package/dist/src/llm/createClassifier.d.ts +6 -0
  68. package/dist/src/llm/createClassifier.d.ts.map +1 -0
  69. package/dist/src/llm/createClassifier.js +47 -0
  70. package/dist/src/llm/createClassifier.js.map +1 -0
  71. package/dist/src/llm/createHallucinationEvaluator.d.ts +14 -0
  72. package/dist/src/llm/createHallucinationEvaluator.d.ts.map +1 -0
  73. package/dist/src/llm/createHallucinationEvaluator.js +18 -0
  74. package/dist/src/llm/createHallucinationEvaluator.js.map +1 -0
  75. package/dist/src/llm/generateClassification.d.ts +22 -0
  76. package/dist/src/llm/generateClassification.d.ts.map +1 -0
  77. package/dist/src/llm/generateClassification.js +44 -0
  78. package/dist/src/llm/generateClassification.js.map +1 -0
  79. package/dist/src/llm/index.d.ts +4 -0
  80. package/dist/src/llm/index.d.ts.map +1 -0
  81. package/dist/src/llm/index.js +20 -0
  82. package/dist/src/llm/index.js.map +1 -0
  83. package/dist/src/template/applyTemplate.d.ts +10 -0
  84. package/dist/src/template/applyTemplate.d.ts.map +1 -0
  85. package/dist/src/template/applyTemplate.js +16 -0
  86. package/dist/src/template/applyTemplate.js.map +1 -0
  87. package/dist/src/template/index.d.ts +2 -0
  88. package/dist/src/template/index.d.ts.map +1 -0
  89. package/dist/src/template/index.js +18 -0
  90. package/dist/src/template/index.js.map +1 -0
  91. package/dist/src/types/evals.d.ts +73 -0
  92. package/dist/src/types/evals.d.ts.map +1 -0
  93. package/dist/src/types/evals.js +3 -0
  94. package/dist/src/types/evals.js.map +1 -0
  95. package/dist/src/types/index.d.ts +3 -0
  96. package/dist/src/types/index.d.ts.map +1 -0
  97. package/dist/src/types/index.js +19 -0
  98. package/dist/src/types/index.js.map +1 -0
  99. package/dist/src/types/prompts.d.ts +21 -0
  100. package/dist/src/types/prompts.d.ts.map +1 -0
  101. package/dist/src/types/prompts.js +3 -0
  102. package/dist/src/types/prompts.js.map +1 -0
  103. package/dist/src/types/templating.d.ts +3 -0
  104. package/dist/src/types/templating.d.ts.map +1 -0
  105. package/dist/src/types/templating.js +3 -0
  106. package/dist/src/types/templating.js.map +1 -0
  107. package/dist/tsconfig.tsbuildinfo +1 -1
  108. package/package.json +42 -5
  109. package/src/default_templates/HALLUCINATION_TEMPLATE.ts +31 -0
  110. package/src/default_templates/index.ts +1 -0
  111. package/src/index.ts +1 -0
  112. package/src/llm/createClassifier.ts +59 -0
  113. package/src/llm/createHallucinationEvaluator.ts +32 -0
  114. package/src/llm/generateClassification.ts +42 -0
  115. package/src/llm/index.ts +3 -0
  116. package/src/template/applyTemplate.ts +14 -0
  117. package/src/template/index.ts +1 -0
  118. package/src/types/evals.ts +84 -0
  119. package/src/types/index.ts +2 -0
  120. package/src/types/prompts.ts +21 -0
  121. package/src/types/templating.ts +2 -0
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createClassifier = createClassifier;
13
+ const generateClassification_1 = require("./generateClassification");
14
+ const template_1 = require("../template");
15
+ /**
16
+ * Convert a mapping of choices to labels
17
+ * Asserts that the choices are valid
18
+ */
19
+ function choicesToLabels(choices) {
20
+ const labels = Object.keys(choices);
21
+ if (labels.length < 1) {
22
+ throw new Error("No choices provided");
23
+ }
24
+ return labels;
25
+ }
26
+ /**
27
+ * A function that serves as a factory that will output a classification evaluator
28
+ */
29
+ function createClassifier(args) {
30
+ const { model, choices, promptTemplate } = args;
31
+ return (args) => __awaiter(this, void 0, void 0, function* () {
32
+ const templateVariables = Object.assign({}, args);
33
+ const prompt = (0, template_1.formatTemplate)({
34
+ template: promptTemplate,
35
+ variables: templateVariables,
36
+ });
37
+ const classification = yield (0, generateClassification_1.generateClassification)({
38
+ model,
39
+ labels: choicesToLabels(choices),
40
+ prompt,
41
+ });
42
+ // Post-process the classification result and map it to the choices
43
+ const score = choices[classification.label];
44
+ return Object.assign({ score }, classification);
45
+ });
46
+ }
47
+ //# sourceMappingURL=createClassifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createClassifier.js","sourceRoot":"","sources":["../../../src/llm/createClassifier.ts"],"names":[],"mappings":";;;;;;;;;;;AA2BA,4CA+BC;AAnDD,qEAAkE;AAClE,0CAA6C;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,SAAgB,gBAAgB,CAC9B,IAA0B;IAE1B,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IAEhD,OAAO,CACL,IAA2C,EAChB,EAAE;QAC7B,MAAM,iBAAiB,qBAClB,IAAI,CACR,CAAC;QAEF,MAAM,MAAM,GAAG,IAAA,yBAAc,EAAC;YAC5B,QAAQ,EAAE,cAAc;YACxB,SAAS,EAAE,iBAAiB;SAC7B,CAAC,CAAC;QAEH,MAAM,cAAc,GAAG,MAAM,IAAA,+CAAsB,EAAC;YAClD,KAAK;YACL,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC;YAChC,MAAM;SACP,CAAC,CAAC;QAEH,mEAAmE;QACnE,MAAM,KAAK,GAAG,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAE5C,uBACE,KAAK,IACF,cAAc,EACjB;IACJ,CAAC,CAAA,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { CreateClassifierArgs, EvaluatorFn } from "../types/evals";
2
+ interface HallucinationEvaluatorArgs extends Omit<CreateClassifierArgs, "promptTemplate" | "choices"> {
3
+ choices?: CreateClassifierArgs["choices"];
4
+ promptTemplate?: CreateClassifierArgs["promptTemplate"];
5
+ }
6
+ /**
7
+ * Creates a function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
8
+ *
9
+ * @param args - The arguments for creating the hallucination evaluator.
10
+ * @returns A function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
11
+ */
12
+ export declare function createHallucinationEvaluator(args: HallucinationEvaluatorArgs): EvaluatorFn<string, string>;
13
+ export {};
14
+ //# sourceMappingURL=createHallucinationEvaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHallucinationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMnE,UAAU,0BACR,SAAQ,IAAI,CAAC,oBAAoB,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAChE,OAAO,CAAC,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC1C,cAAc,CAAC,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;CACzD;AACD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,0BAA0B,GAC/B,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAW7B"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHallucinationEvaluator = createHallucinationEvaluator;
4
+ const createClassifier_1 = require("./createClassifier");
5
+ const HALLUCINATION_TEMPLATE_1 = require("../default_templates/HALLUCINATION_TEMPLATE");
6
+ /**
7
+ * Creates a function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
8
+ *
9
+ * @param args - The arguments for creating the hallucination evaluator.
10
+ * @returns A function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
11
+ */
12
+ function createHallucinationEvaluator(args) {
13
+ const { choices = HALLUCINATION_TEMPLATE_1.HALLUCINATION_CHOICES, promptTemplate = HALLUCINATION_TEMPLATE_1.HALLUCINATION_TEMPLATE, } = args;
14
+ const hallucinationEvaluatorFn = (0, createClassifier_1.createClassifier)(Object.assign(Object.assign({}, args), { promptTemplate,
15
+ choices }));
16
+ return hallucinationEvaluatorFn;
17
+ }
18
+ //# sourceMappingURL=createHallucinationEvaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHallucinationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":";;AAkBA,oEAaC;AA/BD,yDAAsD;AAEtD,wFAGqD;AAOrD;;;;;GAKG;AACH,SAAgB,4BAA4B,CAC1C,IAAgC;IAEhC,MAAM,EACJ,OAAO,GAAG,8CAAqB,EAC/B,cAAc,GAAG,+CAAsB,GACxC,GAAG,IAAI,CAAC;IACT,MAAM,wBAAwB,GAAG,IAAA,mCAAgB,kCAC5C,IAAI,KACP,cAAc;QACd,OAAO,IACP,CAAC;IACH,OAAO,wBAAwB,CAAC;AAClC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { ClassificationResult, WithLLM } from "../types/evals";
2
+ import type { WithPrompt } from "../types/prompts";
3
+ interface ClassifyArgs extends WithLLM, WithPrompt {
4
+ /**
5
+ * The labels to classify the example into. E.x. ["correct", "incorrect"]
6
+ */
7
+ labels: [string, ...string[]];
8
+ /**
9
+ * The name of the schema for generating the label and explanation.
10
+ */
11
+ schemaName?: string;
12
+ /**
13
+ * The description of the schema for generating the label and explanation.
14
+ */
15
+ schemaDescription?: string;
16
+ }
17
+ /**
18
+ * A function that leverages an llm to perform a classification
19
+ */
20
+ export declare function generateClassification(args: ClassifyArgs): Promise<ClassificationResult>;
21
+ export {};
22
+ //# sourceMappingURL=generateClassification.d.ts.map
@@ -0,0 +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,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,UAAU,YAAa,SAAQ,OAAO,EAAE,UAAU;IAChD;;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;AACD;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAiB/B"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.generateClassification = generateClassification;
24
+ const ai_1 = require("ai");
25
+ const zod_1 = require("zod");
26
+ /**
27
+ * A function that leverages an llm to perform a classification
28
+ */
29
+ function generateClassification(args) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const { labels, model, schemaName, schemaDescription } = args, prompt = __rest(args, ["labels", "model", "schemaName", "schemaDescription"]);
32
+ const result = yield (0, ai_1.generateObject)(Object.assign({ model,
33
+ schemaName,
34
+ schemaDescription, schema: zod_1.z.object({
35
+ explanation: zod_1.z.string(), // We place the explanation in hopes it uses reasoning to explain the label.
36
+ label: zod_1.z.enum(labels),
37
+ }) }, prompt));
38
+ return {
39
+ label: result.object.label,
40
+ explanation: result.object.explanation,
41
+ };
42
+ });
43
+ }
44
+ //# sourceMappingURL=generateClassification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,wDAmBC;AAvCD,2BAAoC;AACpC,6BAAwB;AAgBxB;;GAEG;AACH,SAAsB,sBAAsB,CAC1C,IAAkB;;QAElB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,KAAgB,IAAI,EAAf,MAAM,UAAK,IAAI,EAAlE,sDAA2D,CAAO,CAAC;QAEzE,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAc,kBACjC,KAAK;YACL,UAAU;YACV,iBAAiB,EACjB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;gBACf,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,4EAA4E;gBACrG,KAAK,EAAE,OAAC,CAAC,IAAI,CAAC,MAAM,CAAC;aACtB,CAAC,IACC,MAAM,EACT,CAAC;QACH,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;YAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW;SACvC,CAAC;IACJ,CAAC;CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from "./generateClassification";
2
+ export * from "./createClassifier";
3
+ export * from "./createHallucinationEvaluator";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./generateClassification"), exports);
18
+ __exportStar(require("./createClassifier"), exports);
19
+ __exportStar(require("./createHallucinationEvaluator"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/llm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,qDAAmC;AACnC,iEAA+C"}
@@ -0,0 +1,10 @@
1
+ import { Template } from "../types/templating";
2
+ /**
3
+ * A function that applies a set of variables to a template (e.g. a prompt)
4
+ * Uses the Mustache library to apply the variables to the template
5
+ */
6
+ export declare function formatTemplate(args: {
7
+ template: Template;
8
+ variables: Record<string, unknown>;
9
+ }): string;
10
+ //# sourceMappingURL=applyTemplate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyTemplate.d.ts","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,UAGA"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatTemplate = formatTemplate;
7
+ const mustache_1 = __importDefault(require("mustache"));
8
+ /**
9
+ * A function that applies a set of variables to a template (e.g. a prompt)
10
+ * Uses the Mustache library to apply the variables to the template
11
+ */
12
+ function formatTemplate(args) {
13
+ const { template, variables } = args;
14
+ return mustache_1.default.render(template, variables);
15
+ }
16
+ //# sourceMappingURL=applyTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyTemplate.js","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":";;;;;AAOA,wCAMC;AAZD,wDAAgC;AAEhC;;;GAGG;AACH,SAAgB,cAAc,CAAC,IAG9B;IACC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACrC,OAAO,kBAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./applyTemplate";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/template/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./applyTemplate"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/template/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC"}
@@ -0,0 +1,73 @@
1
+ import { LanguageModel } from "ai";
2
+ /**
3
+ * The arguments for an evaluation
4
+ */
5
+ export interface EvaluationArgs<OutputType, InputType> {
6
+ output: OutputType;
7
+ expected?: OutputType;
8
+ input?: InputType;
9
+ [key: string]: unknown;
10
+ }
11
+ export interface WithLLM {
12
+ model: LanguageModel;
13
+ }
14
+ export interface LLMEvaluationArgs<OutputType, InputType> extends EvaluationArgs<OutputType, InputType>, WithLLM {
15
+ }
16
+ /**
17
+ * The result of an evaluation
18
+ */
19
+ export interface EvaluationResult {
20
+ /**
21
+ * The score of the evaluation.
22
+ * @example 0.95
23
+ */
24
+ score?: number;
25
+ /**
26
+ * The label of the evaluation.
27
+ * @example "correct"
28
+ */
29
+ label?: string;
30
+ /**
31
+ * The explanation of the evaluation.
32
+ * @example "The model correctly identified the sentiment of the text."
33
+ */
34
+ explanation?: string;
35
+ }
36
+ /**
37
+ * The result of a classification
38
+ */
39
+ export interface ClassificationResult {
40
+ label: string;
41
+ explanation?: string;
42
+ }
43
+ /**
44
+ * The choice (e.g. the label and score mapping) of a classification based evaluation
45
+ */
46
+ export interface ClassificationChoice {
47
+ label: string;
48
+ score: number;
49
+ }
50
+ /**
51
+ * A mapping of labels to scores
52
+ */
53
+ export type ClassificationChoicesMap = Record<string, number>;
54
+ /**
55
+ * The arguments for creating a classification-based evaluator
56
+ */
57
+ export interface CreateClassifierArgs {
58
+ /**
59
+ * The LLM to use for classification / evaluation
60
+ */
61
+ model: LanguageModel;
62
+ /**
63
+ * The choices to classify the example into.
64
+ * e.g. { "correct": 1, "incorrect": 0 }
65
+ */
66
+ choices: ClassificationChoicesMap;
67
+ /**
68
+ * The prompt template to use for classification
69
+ */
70
+ promptTemplate: string;
71
+ }
72
+ export type EvaluatorFn<OutputType, InputType> = (args: EvaluationArgs<OutputType, InputType>) => Promise<EvaluationResult>;
73
+ //# sourceMappingURL=evals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evals.d.ts","sourceRoot":"","sources":["../../../src/types/evals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,UAAU,EAAE,SAAS;IACnD,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;AAED,MAAM,WAAW,iBAAiB,CAAC,UAAU,EAAE,SAAS,CACtD,SAAQ,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC,EAC3C,OAAO;CAAG;AAEd;;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,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB;;;OAGG;IACH,OAAO,EAAE,wBAAwB,CAAC;IAClC;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,WAAW,CAAC,UAAU,EAAE,SAAS,IAAI,CAC/C,IAAI,EAAE,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC,KACxC,OAAO,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=evals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evals.js","sourceRoot":"","sources":["../../../src/types/evals.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from "./evals";
2
+ export * from "./templating";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./evals"), exports);
18
+ __exportStar(require("./templating"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,+CAA6B"}
@@ -0,0 +1,21 @@
1
+ import { CoreMessage, Message } from "ai";
2
+ /**
3
+ * Prompt part of the AI function options.
4
+ * It contains a system message, a simple text prompt, or a list of messages.
5
+ * Note: this is pulled from the `ai` package and is used as a compatibility type.
6
+ */
7
+ export interface WithPrompt {
8
+ /**
9
+ * System message to include in the prompt. Can be used with `prompt` or `messages`.
10
+ */
11
+ system?: string;
12
+ /**
13
+ * A simple text prompt. You can either use `prompt` or `messages` but not both.
14
+ */
15
+ prompt?: string;
16
+ /**
17
+ * A list of messages. You can either use `prompt` or `messages` but not both.
18
+ */
19
+ messages?: Array<CoreMessage> | Array<Omit<Message, "id">>;
20
+ }
21
+ //# sourceMappingURL=prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/types/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE1C;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;CAC5D"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/types/prompts.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export type Template = string;
2
+ export type TemplateVariables = Record<string, unknown>;
3
+ //# sourceMappingURL=templating.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../../src/types/templating.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=templating.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templating.js","sourceRoot":"","sources":["../../../src/types/templating.ts"],"names":[],"mappings":""}