@arizeai/phoenix-evals 0.0.7 → 0.1.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.
Files changed (89) hide show
  1. package/dist/esm/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.d.ts +6 -0
  2. package/dist/esm/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.d.ts.map +1 -0
  3. package/dist/esm/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.js +25 -0
  4. package/dist/esm/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.js.map +1 -0
  5. package/dist/esm/default_templates/HALLUCINATION_TEMPLATE.d.ts +1 -1
  6. package/dist/esm/default_templates/HALLUCINATION_TEMPLATE.js +2 -2
  7. package/dist/esm/default_templates/HALLUCINATION_TEMPLATE.js.map +1 -1
  8. package/dist/esm/default_templates/index.d.ts +1 -0
  9. package/dist/esm/default_templates/index.d.ts.map +1 -1
  10. package/dist/esm/default_templates/index.js +1 -0
  11. package/dist/esm/default_templates/index.js.map +1 -1
  12. package/dist/esm/llm/createClassificationEvaluator.d.ts +3 -0
  13. package/dist/esm/llm/createClassificationEvaluator.d.ts.map +1 -0
  14. package/dist/esm/llm/createClassificationEvaluator.js +10 -0
  15. package/dist/esm/llm/createClassificationEvaluator.js.map +1 -0
  16. package/dist/esm/llm/createClassifierFn.d.ts +6 -0
  17. package/dist/esm/llm/createClassifierFn.d.ts.map +1 -0
  18. package/dist/esm/llm/{createClassifier.js → createClassifierFn.js} +3 -3
  19. package/dist/esm/llm/createClassifierFn.js.map +1 -0
  20. package/dist/esm/llm/createDocumentRelevancyEvaluator.d.ts +42 -0
  21. package/dist/esm/llm/createDocumentRelevancyEvaluator.d.ts.map +1 -0
  22. package/dist/esm/llm/createDocumentRelevancyEvaluator.js +40 -0
  23. package/dist/esm/llm/createDocumentRelevancyEvaluator.js.map +1 -0
  24. package/dist/esm/llm/createHallucinationEvaluator.d.ts +16 -5
  25. package/dist/esm/llm/createHallucinationEvaluator.d.ts.map +1 -1
  26. package/dist/esm/llm/createHallucinationEvaluator.js +5 -4
  27. package/dist/esm/llm/createHallucinationEvaluator.js.map +1 -1
  28. package/dist/esm/llm/index.d.ts +3 -1
  29. package/dist/esm/llm/index.d.ts.map +1 -1
  30. package/dist/esm/llm/index.js +3 -1
  31. package/dist/esm/llm/index.js.map +1 -1
  32. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  33. package/dist/esm/types/evals.d.ts +49 -4
  34. package/dist/esm/types/evals.d.ts.map +1 -1
  35. package/dist/esm/types/prompts.d.ts +7 -6
  36. package/dist/esm/types/prompts.d.ts.map +1 -1
  37. package/dist/src/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.d.ts +6 -0
  38. package/dist/src/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.d.ts.map +1 -0
  39. package/dist/src/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.js +28 -0
  40. package/dist/src/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.js.map +1 -0
  41. package/dist/src/default_templates/HALLUCINATION_TEMPLATE.d.ts +1 -1
  42. package/dist/src/default_templates/HALLUCINATION_TEMPLATE.js +2 -2
  43. package/dist/src/default_templates/HALLUCINATION_TEMPLATE.js.map +1 -1
  44. package/dist/src/default_templates/index.d.ts +1 -0
  45. package/dist/src/default_templates/index.d.ts.map +1 -1
  46. package/dist/src/default_templates/index.js +1 -0
  47. package/dist/src/default_templates/index.js.map +1 -1
  48. package/dist/src/llm/createClassificationEvaluator.d.ts +3 -0
  49. package/dist/src/llm/createClassificationEvaluator.d.ts.map +1 -0
  50. package/dist/src/llm/createClassificationEvaluator.js +13 -0
  51. package/dist/src/llm/createClassificationEvaluator.js.map +1 -0
  52. package/dist/src/llm/createClassifierFn.d.ts +6 -0
  53. package/dist/src/llm/createClassifierFn.d.ts.map +1 -0
  54. package/dist/src/llm/{createClassifier.js → createClassifierFn.js} +4 -4
  55. package/dist/src/llm/createClassifierFn.js.map +1 -0
  56. package/dist/src/llm/createDocumentRelevancyEvaluator.d.ts +42 -0
  57. package/dist/src/llm/createDocumentRelevancyEvaluator.d.ts.map +1 -0
  58. package/dist/src/llm/createDocumentRelevancyEvaluator.js +50 -0
  59. package/dist/src/llm/createDocumentRelevancyEvaluator.js.map +1 -0
  60. package/dist/src/llm/createHallucinationEvaluator.d.ts +16 -5
  61. package/dist/src/llm/createHallucinationEvaluator.d.ts.map +1 -1
  62. package/dist/src/llm/createHallucinationEvaluator.js +6 -5
  63. package/dist/src/llm/createHallucinationEvaluator.js.map +1 -1
  64. package/dist/src/llm/index.d.ts +3 -1
  65. package/dist/src/llm/index.d.ts.map +1 -1
  66. package/dist/src/llm/index.js +3 -1
  67. package/dist/src/llm/index.js.map +1 -1
  68. package/dist/src/types/evals.d.ts +49 -4
  69. package/dist/src/types/evals.d.ts.map +1 -1
  70. package/dist/src/types/prompts.d.ts +7 -6
  71. package/dist/src/types/prompts.d.ts.map +1 -1
  72. package/dist/tsconfig.tsbuildinfo +1 -1
  73. package/package.json +5 -5
  74. package/src/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.ts +25 -0
  75. package/src/default_templates/HALLUCINATION_TEMPLATE.ts +2 -2
  76. package/src/default_templates/index.ts +1 -0
  77. package/src/llm/createClassificationEvaluator.ts +13 -0
  78. package/src/llm/{createClassifier.ts → createClassifierFn.ts} +4 -7
  79. package/src/llm/createDocumentRelevancyEvaluator.ts +72 -0
  80. package/src/llm/createHallucinationEvaluator.ts +26 -8
  81. package/src/llm/index.ts +3 -1
  82. package/src/types/evals.ts +54 -7
  83. package/src/types/prompts.ts +7 -6
  84. package/dist/esm/llm/createClassifier.d.ts +0 -6
  85. package/dist/esm/llm/createClassifier.d.ts.map +0 -1
  86. package/dist/esm/llm/createClassifier.js.map +0 -1
  87. package/dist/src/llm/createClassifier.d.ts +0 -6
  88. package/dist/src/llm/createClassifier.d.ts.map +0 -1
  89. package/dist/src/llm/createClassifier.js.map +0 -1
@@ -0,0 +1,6 @@
1
+ export declare const DOCUMENT_RELEVANCY_TEMPLATE = "\nYou are comparing a document to a question and trying to determine if the document text\ncontains information relevant to answering the question. Here is the data:\n\n [BEGIN DATA]\n ************\n [Question]: {{input}}\n ************\n [Document text]: {{documentText}}\n ************\n [END DATA]\n\nCompare the Question above to the Document text. You must determine whether the Document text\ncontains information that can answer the Question. Please focus on whether the very specific\nquestion can be answered by the information in the Document text.\nYour response must be single word, either \"relevant\" or \"unrelated\",\nand should not contain any text or characters aside from that word.\n\"unrelated\" means that the document text does not contain an answer to the Question.\n\"relevant\" means the document text contains an answer to the Question.\n";
2
+ export declare const DOCUMENT_RELEVANCY_CHOICES: {
3
+ relevant: number;
4
+ unrelated: number;
5
+ };
6
+ //# sourceMappingURL=DOCUMENT_RELEVANCY_TEMPLATE.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DOCUMENT_RELEVANCY_TEMPLATE.d.ts","sourceRoot":"","sources":["../../../src/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,23BAmBvC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;CAGtC,CAAC"}
@@ -0,0 +1,25 @@
1
+ export const DOCUMENT_RELEVANCY_TEMPLATE = `
2
+ You are comparing a document to a question and trying to determine if the document text
3
+ contains information relevant to answering the question. Here is the data:
4
+
5
+ [BEGIN DATA]
6
+ ************
7
+ [Question]: {{input}}
8
+ ************
9
+ [Document text]: {{documentText}}
10
+ ************
11
+ [END DATA]
12
+
13
+ Compare the Question above to the Document text. You must determine whether the Document text
14
+ contains information that can answer the Question. Please focus on whether the very specific
15
+ question can be answered by the information in the Document text.
16
+ Your response must be single word, either "relevant" or "unrelated",
17
+ and should not contain any text or characters aside from that word.
18
+ "unrelated" means that the document text does not contain an answer to the Question.
19
+ "relevant" means the document text contains an answer to the Question.
20
+ `;
21
+ export const DOCUMENT_RELEVANCY_CHOICES = {
22
+ relevant: 1,
23
+ unrelated: 0,
24
+ };
25
+ //# sourceMappingURL=DOCUMENT_RELEVANCY_TEMPLATE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DOCUMENT_RELEVANCY_TEMPLATE.js","sourceRoot":"","sources":["../../../src/default_templates/DOCUMENT_RELEVANCY_TEMPLATE.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;CAmB1C,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,QAAQ,EAAE,CAAC;IACX,SAAS,EAAE,CAAC;CACb,CAAC"}
@@ -1,6 +1,6 @@
1
1
  export declare const HALLUCINATION_TEMPLATE = "\nIn this task, you will be presented with a query, a reference text and an answer. The answer is\ngenerated to the question based on the reference text. The answer may contain false information. You\nmust use the reference text to determine if the answer to the question contains false information,\nif the answer is a hallucination of facts. Your objective is to determine whether the answer text\ncontains factual information and is not a hallucination. A 'hallucination' refers to\nan answer that is not based on the reference text or assumes information that is not available in\nthe reference text. Your response should be a single word: either \"factual\" or \"hallucinated\", and\nit should not include any other text or characters. \"hallucinated\" indicates that the answer\nprovides factually inaccurate information to the query based on the reference text. \"factual\"\nindicates that the answer to the question is correct relative to the reference text, and does not\ncontain made up information. Please read the query and reference text carefully before determining\nyour response.\n\n [BEGIN DATA]\n ************\n [Query]: {{input}}\n ************\n [Reference text]: {{reference}}\n ************\n [Answer]: {{output}}\n ************\n [END DATA]\n\nIs the answer above factual or hallucinated based on the query and reference text?\n";
2
2
  export declare const HALLUCINATION_CHOICES: {
3
- factual: number;
4
3
  hallucinated: number;
4
+ factual: number;
5
5
  };
6
6
  //# sourceMappingURL=HALLUCINATION_TEMPLATE.d.ts.map
@@ -25,7 +25,7 @@ your response.
25
25
  Is the answer above factual or hallucinated based on the query and reference text?
26
26
  `;
27
27
  export const HALLUCINATION_CHOICES = {
28
- factual: 1,
29
- hallucinated: 0,
28
+ hallucinated: 1,
29
+ factual: 0,
30
30
  };
31
31
  //# sourceMappingURL=HALLUCINATION_TEMPLATE.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HALLUCINATION_TEMPLATE.js","sourceRoot":"","sources":["../../../src/default_templates/HALLUCINATION_TEMPLATE.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyBrC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,OAAO,EAAE,CAAC;IACV,YAAY,EAAE,CAAC;CAChB,CAAC"}
1
+ {"version":3,"file":"HALLUCINATION_TEMPLATE.js","sourceRoot":"","sources":["../../../src/default_templates/HALLUCINATION_TEMPLATE.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyBrC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,YAAY,EAAE,CAAC;IACf,OAAO,EAAE,CAAC;CACX,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./HALLUCINATION_TEMPLATE.js";
2
+ export * from "./DOCUMENT_RELEVANCY_TEMPLATE.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/default_templates/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/default_templates/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./HALLUCINATION_TEMPLATE.js";
2
+ export * from "./DOCUMENT_RELEVANCY_TEMPLATE.js";
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/default_templates/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/default_templates/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { CreateClassificationEvaluatorArgs, Evaluator } from "../types/evals.js";
2
+ export declare function createClassificationEvaluator<ExampleType extends Record<string, unknown>>(args: CreateClassificationEvaluatorArgs): Evaluator<ExampleType>;
3
+ //# sourceMappingURL=createClassificationEvaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createClassificationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG9E,wBAAgB,6BAA6B,CAC3C,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3C,IAAI,EAAE,iCAAiC,GAAG,SAAS,CAAC,WAAW,CAAC,CAOjE"}
@@ -0,0 +1,10 @@
1
+ import { createClassifierFn } from "./createClassifierFn.js";
2
+ export function createClassificationEvaluator(args) {
3
+ return {
4
+ name: args.name,
5
+ source: "LLM",
6
+ optimizationDirection: args.optimizationDirection,
7
+ evaluate: createClassifierFn(args),
8
+ };
9
+ }
10
+ //# sourceMappingURL=createClassificationEvaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createClassificationEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,UAAU,6BAA6B,CAE3C,IAAuC;IACvC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM,EAAE,KAAK;QACb,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;QACjD,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC;KACnC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { CreateClassifierArgs, EvaluatorFn } from "../types/evals.js";
2
+ /**
3
+ * A function that serves as a factory that will output a classification evaluator function
4
+ */
5
+ export declare function createClassifierFn<ExampleType extends Record<string, unknown>>(args: CreateClassifierArgs): EvaluatorFn<ExampleType>;
6
+ //# sourceMappingURL=createClassifierFn.d.ts.map
@@ -0,0 +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,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5E,IAAI,EAAE,oBAAoB,GACzB,WAAW,CAAC,WAAW,CAAC,CA4B1B"}
@@ -12,9 +12,9 @@ function choicesToLabels(choices) {
12
12
  return labels;
13
13
  }
14
14
  /**
15
- * A function that serves as a factory that will output a classification evaluator
15
+ * A function that serves as a factory that will output a classification evaluator function
16
16
  */
17
- export function createClassifier(args) {
17
+ export function createClassifierFn(args) {
18
18
  const { model, choices, promptTemplate, ...rest } = args;
19
19
  return async (args) => {
20
20
  const templateVariables = {
@@ -38,4 +38,4 @@ export function createClassifier(args) {
38
38
  };
39
39
  };
40
40
  }
41
- //# sourceMappingURL=createClassifier.js.map
41
+ //# sourceMappingURL=createClassifierFn.js.map
@@ -0,0 +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,CAChC,IAA0B;IAE1B,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAEzD,OAAO,KAAK,EAAE,IAAiB,EAA6B,EAAE;QAC5D,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"}
@@ -0,0 +1,42 @@
1
+ import { CreateClassificationEvaluatorArgs, Evaluator } from "../types/evals.js";
2
+ export interface DocumentRelevancyEvaluatorArgs extends Omit<CreateClassificationEvaluatorArgs, "promptTemplate" | "choices" | "optimizationDirection" | "name"> {
3
+ optimizationDirection?: CreateClassificationEvaluatorArgs["optimizationDirection"];
4
+ name?: CreateClassificationEvaluatorArgs["name"];
5
+ choices?: CreateClassificationEvaluatorArgs["choices"];
6
+ promptTemplate?: CreateClassificationEvaluatorArgs["promptTemplate"];
7
+ }
8
+ /**
9
+ * An example to be evaluated by the document relevancy evaluator.
10
+ */
11
+ export type DocumentRelevancyExample = {
12
+ input: string;
13
+ documentText: string;
14
+ };
15
+ /**
16
+ * Creates a document relevancy evaluator function.
17
+ *
18
+ * This function returns an evaluator that determines whether a given document text
19
+ * is relevant to a provided input question. The evaluator uses a classification model
20
+ * and a prompt template to make its determination.
21
+ *
22
+ * @param args - The arguments for creating the document relevancy evaluator.
23
+ * @param args.model - The model to use for classification.
24
+ * @param args.choices - The possible classification choices (defaults to DOCUMENT_RELEVANCY_CHOICES).
25
+ * @param args.promptTemplate - The prompt template to use (defaults to DOCUMENT_RELEVANCY_TEMPLATE).
26
+ * @param args.telemetry - The telemetry to use for the evaluator.
27
+ *
28
+ * @returns An evaluator function that takes a {@link DocumentRelevancyExample} and returns a classification result
29
+ * indicating whether the document is relevant to the input question.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const evaluator = createDocumentRelevancyEvaluator({ model: openai("gpt-4o-mini") });
34
+ * const result = await evaluator.evaluate({
35
+ * input: "What is the capital of France?",
36
+ * documentText: "Paris is the capital and most populous city of France.",
37
+ * });
38
+ * console.log(result.label); // "relevant" or "unrelated"
39
+ * ```
40
+ */
41
+ export declare function createDocumentRelevancyEvaluator(args: DocumentRelevancyEvaluatorArgs): Evaluator<DocumentRelevancyExample>;
42
+ //# sourceMappingURL=createDocumentRelevancyEvaluator.d.ts.map
@@ -0,0 +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,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,8BAA8B,GACnC,SAAS,CAAC,wBAAwB,CAAC,CAiBrC"}
@@ -0,0 +1,40 @@
1
+ import { DOCUMENT_RELEVANCY_TEMPLATE, DOCUMENT_RELEVANCY_CHOICES, } from "../default_templates/DOCUMENT_RELEVANCY_TEMPLATE.js";
2
+ import { createClassificationEvaluator } from "./createClassificationEvaluator.js";
3
+ /**
4
+ * Creates a document relevancy evaluator function.
5
+ *
6
+ * This function returns an evaluator that determines whether a given document text
7
+ * is relevant to a provided input question. The evaluator uses a classification model
8
+ * and a prompt template to make its determination.
9
+ *
10
+ * @param args - The arguments for creating the document relevancy evaluator.
11
+ * @param args.model - The model to use for classification.
12
+ * @param args.choices - The possible classification choices (defaults to DOCUMENT_RELEVANCY_CHOICES).
13
+ * @param args.promptTemplate - The prompt template to use (defaults to DOCUMENT_RELEVANCY_TEMPLATE).
14
+ * @param args.telemetry - The telemetry to use for the evaluator.
15
+ *
16
+ * @returns An evaluator function that takes a {@link DocumentRelevancyExample} and returns a classification result
17
+ * indicating whether the document is relevant to the input question.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const evaluator = createDocumentRelevancyEvaluator({ model: openai("gpt-4o-mini") });
22
+ * const result = await evaluator.evaluate({
23
+ * input: "What is the capital of France?",
24
+ * documentText: "Paris is the capital and most populous city of France.",
25
+ * });
26
+ * console.log(result.label); // "relevant" or "unrelated"
27
+ * ```
28
+ */
29
+ export function createDocumentRelevancyEvaluator(args) {
30
+ const { choices = DOCUMENT_RELEVANCY_CHOICES, promptTemplate = DOCUMENT_RELEVANCY_TEMPLATE, optimizationDirection = "MAXIMIZE", name = "document_relevancy", ...rest } = args;
31
+ return createClassificationEvaluator({
32
+ ...args,
33
+ promptTemplate,
34
+ choices,
35
+ optimizationDirection,
36
+ name,
37
+ ...rest,
38
+ });
39
+ }
40
+ //# sourceMappingURL=createDocumentRelevancyEvaluator.js.map
@@ -0,0 +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;AAqBhF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,gCAAgC,CAC9C,IAAoC;IAEpC,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,CAA2B;QAC7D,GAAG,IAAI;QACP,cAAc;QACd,OAAO;QACP,qBAAqB;QACrB,IAAI;QACJ,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC"}
@@ -1,13 +1,24 @@
1
- import { CreateClassifierArgs, EvaluatorFn } from "../types/evals.js";
2
- export interface HallucinationEvaluatorArgs extends Omit<CreateClassifierArgs, "promptTemplate" | "choices"> {
3
- choices?: CreateClassifierArgs["choices"];
4
- promptTemplate?: CreateClassifierArgs["promptTemplate"];
1
+ import { CreateClassificationEvaluatorArgs, Evaluator } from "../types/evals.js";
2
+ export interface HallucinationEvaluatorArgs extends Omit<CreateClassificationEvaluatorArgs, "promptTemplate" | "choices" | "optimizationDirection" | "name"> {
3
+ optimizationDirection?: CreateClassificationEvaluatorArgs["optimizationDirection"];
4
+ name?: CreateClassificationEvaluatorArgs["name"];
5
+ choices?: CreateClassificationEvaluatorArgs["choices"];
6
+ promptTemplate?: CreateClassificationEvaluatorArgs["promptTemplate"];
5
7
  }
8
+ /**
9
+ * An example to be evaluated by the hallucination evaluator.
10
+ */
11
+ export type HallucinationExample = {
12
+ input: string;
13
+ output: string;
14
+ reference?: string;
15
+ context?: string;
16
+ };
6
17
  /**
7
18
  * Creates a function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
8
19
  *
9
20
  * @param args - The arguments for creating the hallucination evaluator.
10
21
  * @returns A function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
11
22
  */
12
- export declare function createHallucinationEvaluator(args: HallucinationEvaluatorArgs): EvaluatorFn<string, string>;
23
+ export declare function createHallucinationEvaluator(args: HallucinationEvaluatorArgs): Evaluator<HallucinationExample>;
13
24
  //# sourceMappingURL=createHallucinationEvaluator.d.ts.map
@@ -1 +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,MAAM,WAAW,0BACf,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,CAa7B"}
1
+ {"version":3,"file":"createHallucinationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAO9E,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,oBAAoB,GAAG;IACjC,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,IAAI,EAAE,0BAA0B,GAC/B,SAAS,CAAC,oBAAoB,CAAC,CAgBjC"}
@@ -1,5 +1,5 @@
1
- import { createClassifier } from "./createClassifier.js";
2
1
  import { HALLUCINATION_TEMPLATE, HALLUCINATION_CHOICES, } from "../default_templates/HALLUCINATION_TEMPLATE.js";
2
+ import { createClassificationEvaluator } from "./createClassificationEvaluator.js";
3
3
  /**
4
4
  * Creates a function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
5
5
  *
@@ -7,13 +7,14 @@ import { HALLUCINATION_TEMPLATE, HALLUCINATION_CHOICES, } from "../default_templ
7
7
  * @returns A function that evaluates whether an answer is factual or hallucinated based on a query and reference text.
8
8
  */
9
9
  export function createHallucinationEvaluator(args) {
10
- const { choices = HALLUCINATION_CHOICES, promptTemplate = HALLUCINATION_TEMPLATE, ...rest } = args;
11
- const hallucinationEvaluatorFn = createClassifier({
10
+ const { choices = HALLUCINATION_CHOICES, promptTemplate = HALLUCINATION_TEMPLATE, optimizationDirection = "MINIMIZE", name = "hallucination", ...rest } = args;
11
+ return createClassificationEvaluator({
12
12
  ...args,
13
13
  promptTemplate,
14
14
  choices,
15
+ optimizationDirection,
16
+ name,
15
17
  ...rest,
16
18
  });
17
- return hallucinationEvaluatorFn;
18
19
  }
19
20
  //# sourceMappingURL=createHallucinationEvaluator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createHallucinationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createHallucinationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,6CAA6C,CAAC;AAOrD;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,IAAgC;IAEhC,MAAM,EACJ,OAAO,GAAG,qBAAqB,EAC/B,cAAc,GAAG,sBAAsB,EACvC,GAAG,IAAI,EACR,GAAG,IAAI,CAAC;IACT,MAAM,wBAAwB,GAAG,gBAAgB,CAAiB;QAChE,GAAG,IAAI;QACP,cAAc;QACd,OAAO;QACP,GAAG,IAAI;KACR,CAAC,CAAC;IACH,OAAO,wBAAwB,CAAC;AAClC,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;AAsBhF;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,IAAgC;IAEhC,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,CAAuB;QACzD,GAAG,IAAI;QACP,cAAc;QACd,OAAO;QACP,qBAAqB;QACrB,IAAI;QACJ,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC"}
@@ -1,4 +1,6 @@
1
1
  export * from "./generateClassification.js";
2
- export * from "./createClassifier.js";
2
+ export * from "./createClassifierFn.js";
3
+ export * from "./createClassificationEvaluator.js";
3
4
  export * from "./createHallucinationEvaluator.js";
5
+ export * from "./createDocumentRelevancyEvaluator.js";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC"}
@@ -1,4 +1,6 @@
1
1
  export * from "./generateClassification.js";
2
- export * from "./createClassifier.js";
2
+ export * from "./createClassifierFn.js";
3
+ export * from "./createClassificationEvaluator.js";
3
4
  export * from "./createHallucinationEvaluator.js";
5
+ export * from "./createDocumentRelevancyEvaluator.js";
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC"}