@arizeai/phoenix-evals 0.7.0 → 0.9.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 (107) hide show
  1. package/dist/esm/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.d.ts +3 -0
  2. package/dist/esm/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.d.ts.map +1 -0
  3. package/dist/esm/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.js +33 -0
  4. package/dist/esm/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.js.map +1 -0
  5. package/dist/esm/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts +3 -0
  6. package/dist/esm/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts.map +1 -0
  7. package/dist/esm/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.js +30 -0
  8. package/dist/esm/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.js.map +1 -0
  9. package/dist/esm/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.d.ts +3 -0
  10. package/dist/esm/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.d.ts.map +1 -0
  11. package/dist/esm/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.js +86 -0
  12. package/dist/esm/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.js.map +1 -0
  13. package/dist/esm/__generated__/default_templates/index.d.ts +3 -0
  14. package/dist/esm/__generated__/default_templates/index.d.ts.map +1 -1
  15. package/dist/esm/__generated__/default_templates/index.js +3 -0
  16. package/dist/esm/__generated__/default_templates/index.js.map +1 -1
  17. package/dist/esm/core/EvaluatorBase.d.ts.map +1 -1
  18. package/dist/esm/llm/createCorrectnessEvaluator.d.ts.map +1 -1
  19. package/dist/esm/llm/createDocumentRelevanceEvaluator.d.ts.map +1 -1
  20. package/dist/esm/llm/createDocumentRelevanceEvaluator.js.map +1 -1
  21. package/dist/esm/llm/createFaithfulnessEvaluator.d.ts +24 -0
  22. package/dist/esm/llm/createFaithfulnessEvaluator.d.ts.map +1 -0
  23. package/dist/esm/llm/createFaithfulnessEvaluator.js +19 -0
  24. package/dist/esm/llm/createFaithfulnessEvaluator.js.map +1 -0
  25. package/dist/esm/llm/createHallucinationEvaluator.d.ts +12 -0
  26. package/dist/esm/llm/createHallucinationEvaluator.d.ts.map +1 -1
  27. package/dist/esm/llm/createHallucinationEvaluator.js +17 -0
  28. package/dist/esm/llm/createHallucinationEvaluator.js.map +1 -1
  29. package/dist/esm/llm/createToolInvocationEvaluator.d.ts +74 -0
  30. package/dist/esm/llm/createToolInvocationEvaluator.d.ts.map +1 -0
  31. package/dist/esm/llm/createToolInvocationEvaluator.js +60 -0
  32. package/dist/esm/llm/createToolInvocationEvaluator.js.map +1 -0
  33. package/dist/esm/llm/createToolResponseHandlingEvaluator.d.ts +78 -0
  34. package/dist/esm/llm/createToolResponseHandlingEvaluator.d.ts.map +1 -0
  35. package/dist/esm/llm/createToolResponseHandlingEvaluator.js +59 -0
  36. package/dist/esm/llm/createToolResponseHandlingEvaluator.js.map +1 -0
  37. package/dist/esm/llm/createToolSelectionEvaluator.d.ts +64 -0
  38. package/dist/esm/llm/createToolSelectionEvaluator.d.ts.map +1 -0
  39. package/dist/esm/llm/createToolSelectionEvaluator.js +50 -0
  40. package/dist/esm/llm/createToolSelectionEvaluator.js.map +1 -0
  41. package/dist/esm/llm/index.d.ts +9 -5
  42. package/dist/esm/llm/index.d.ts.map +1 -1
  43. package/dist/esm/llm/index.js +9 -5
  44. package/dist/esm/llm/index.js.map +1 -1
  45. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  46. package/dist/esm/types/evals.d.ts.map +1 -1
  47. package/dist/src/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.d.ts +3 -0
  48. package/dist/src/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.d.ts.map +1 -0
  49. package/dist/src/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.js +36 -0
  50. package/dist/src/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.js.map +1 -0
  51. package/dist/src/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts +3 -0
  52. package/dist/src/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts.map +1 -0
  53. package/dist/src/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.js +33 -0
  54. package/dist/src/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.js.map +1 -0
  55. package/dist/src/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.d.ts +3 -0
  56. package/dist/src/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.d.ts.map +1 -0
  57. package/dist/src/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.js +89 -0
  58. package/dist/src/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.js.map +1 -0
  59. package/dist/src/__generated__/default_templates/index.d.ts +3 -0
  60. package/dist/src/__generated__/default_templates/index.d.ts.map +1 -1
  61. package/dist/src/__generated__/default_templates/index.js +7 -1
  62. package/dist/src/__generated__/default_templates/index.js.map +1 -1
  63. package/dist/src/core/EvaluatorBase.d.ts.map +1 -1
  64. package/dist/src/llm/createCorrectnessEvaluator.d.ts.map +1 -1
  65. package/dist/src/llm/createDocumentRelevanceEvaluator.d.ts.map +1 -1
  66. package/dist/src/llm/createDocumentRelevanceEvaluator.js.map +1 -1
  67. package/dist/src/llm/createFaithfulnessEvaluator.d.ts +24 -0
  68. package/dist/src/llm/createFaithfulnessEvaluator.d.ts.map +1 -0
  69. package/dist/src/llm/createFaithfulnessEvaluator.js +30 -0
  70. package/dist/src/llm/createFaithfulnessEvaluator.js.map +1 -0
  71. package/dist/src/llm/createHallucinationEvaluator.d.ts +12 -0
  72. package/dist/src/llm/createHallucinationEvaluator.d.ts.map +1 -1
  73. package/dist/src/llm/createHallucinationEvaluator.js +17 -0
  74. package/dist/src/llm/createHallucinationEvaluator.js.map +1 -1
  75. package/dist/src/llm/createToolInvocationEvaluator.d.ts +74 -0
  76. package/dist/src/llm/createToolInvocationEvaluator.d.ts.map +1 -0
  77. package/dist/src/llm/createToolInvocationEvaluator.js +71 -0
  78. package/dist/src/llm/createToolInvocationEvaluator.js.map +1 -0
  79. package/dist/src/llm/createToolResponseHandlingEvaluator.d.ts +78 -0
  80. package/dist/src/llm/createToolResponseHandlingEvaluator.d.ts.map +1 -0
  81. package/dist/src/llm/createToolResponseHandlingEvaluator.js +70 -0
  82. package/dist/src/llm/createToolResponseHandlingEvaluator.js.map +1 -0
  83. package/dist/src/llm/createToolSelectionEvaluator.d.ts +64 -0
  84. package/dist/src/llm/createToolSelectionEvaluator.d.ts.map +1 -0
  85. package/dist/src/llm/createToolSelectionEvaluator.js +61 -0
  86. package/dist/src/llm/createToolSelectionEvaluator.js.map +1 -0
  87. package/dist/src/llm/index.d.ts +9 -5
  88. package/dist/src/llm/index.d.ts.map +1 -1
  89. package/dist/src/llm/index.js +9 -5
  90. package/dist/src/llm/index.js.map +1 -1
  91. package/dist/src/types/evals.d.ts.map +1 -1
  92. package/dist/tsconfig.tsbuildinfo +1 -1
  93. package/package.json +1 -1
  94. package/src/__generated__/default_templates/FAITHFULNESS_CLASSIFICATION_EVALUATOR_CONFIG.ts +35 -0
  95. package/src/__generated__/default_templates/TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.ts +32 -0
  96. package/src/__generated__/default_templates/TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.ts +88 -0
  97. package/src/__generated__/default_templates/index.ts +3 -0
  98. package/src/core/EvaluatorBase.ts +3 -3
  99. package/src/llm/createCorrectnessEvaluator.ts +3 -3
  100. package/src/llm/createDocumentRelevanceEvaluator.ts +7 -11
  101. package/src/llm/createFaithfulnessEvaluator.ts +52 -0
  102. package/src/llm/createHallucinationEvaluator.ts +25 -3
  103. package/src/llm/createToolInvocationEvaluator.ts +103 -0
  104. package/src/llm/createToolResponseHandlingEvaluator.ts +109 -0
  105. package/src/llm/createToolSelectionEvaluator.ts +93 -0
  106. package/src/llm/index.ts +9 -5
  107. package/src/types/evals.ts +5 -4
@@ -0,0 +1,78 @@
1
+ import { CreateClassificationEvaluatorArgs } from "../types/evals";
2
+ import { ClassificationEvaluator } from "./ClassificationEvaluator";
3
+ export interface ToolResponseHandlingEvaluatorArgs<RecordType extends Record<string, unknown> = ToolResponseHandlingEvaluationRecord> 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
+ }
9
+ /**
10
+ * A record to be evaluated by the tool response handling evaluator.
11
+ */
12
+ export type ToolResponseHandlingEvaluationRecord = {
13
+ /**
14
+ * The user query or conversation context.
15
+ */
16
+ input: string;
17
+ /**
18
+ * The tool invocation(s) made by the agent, including arguments.
19
+ */
20
+ toolCall: string;
21
+ /**
22
+ * The tool's response (data, errors, or partial results).
23
+ */
24
+ toolResult: string;
25
+ /**
26
+ * The agent's handling after receiving the tool result
27
+ * (may include retries, follow-ups, or final response).
28
+ */
29
+ output: string;
30
+ };
31
+ /**
32
+ * Creates a tool response handling evaluator function.
33
+ *
34
+ * This function returns an evaluator that determines whether an AI agent properly
35
+ * handled a tool's response, including error handling, data extraction,
36
+ * transformation, and safe information disclosure.
37
+ *
38
+ * @param args - The arguments for creating the tool response handling evaluator.
39
+ * @param args.model - The model to use for classification.
40
+ * @param args.choices - The possible classification choices (defaults to correct/incorrect).
41
+ * @param args.promptTemplate - The prompt template to use.
42
+ * @param args.telemetry - The telemetry to use for the evaluator.
43
+ *
44
+ * @returns An evaluator function that takes a {@link ToolResponseHandlingEvaluationRecord}
45
+ * and returns a classification result indicating whether the tool response handling
46
+ * is correct or incorrect.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const evaluator = createToolResponseHandlingEvaluator({ model: openai("gpt-4o-mini") });
51
+ *
52
+ * // Example: Correct extraction from tool result
53
+ * const result = await evaluator.evaluate({
54
+ * input: "What's the weather in Seattle?",
55
+ * toolCall: 'get_weather(location="Seattle")',
56
+ * toolResult: JSON.stringify({
57
+ * temperature: 58,
58
+ * unit: "fahrenheit",
59
+ * conditions: "partly cloudy"
60
+ * }),
61
+ * output: "The weather in Seattle is 58°F and partly cloudy."
62
+ * });
63
+ * console.log(result.label); // "correct"
64
+ *
65
+ * // Example: Hallucinated data (incorrect)
66
+ * const resultHallucinated = await evaluator.evaluate({
67
+ * input: "What restaurants are nearby?",
68
+ * toolCall: 'search_restaurants(location="downtown")',
69
+ * toolResult: JSON.stringify({
70
+ * results: [{ name: "Cafe Luna", rating: 4.2 }]
71
+ * }),
72
+ * output: "I found Cafe Luna (4.2 stars) and Mario's Italian (4.8 stars) nearby."
73
+ * });
74
+ * console.log(resultHallucinated.label); // "incorrect" - Mario's was hallucinated
75
+ * ```
76
+ */
77
+ export declare function createToolResponseHandlingEvaluator<RecordType extends Record<string, unknown> = ToolResponseHandlingEvaluationRecord>(args: ToolResponseHandlingEvaluatorArgs<RecordType>): ClassificationEvaluator<RecordType>;
78
+ //# sourceMappingURL=createToolResponseHandlingEvaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createToolResponseHandlingEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createToolResponseHandlingEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAGpE,MAAM,WAAW,iCAAiC,CAChD,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,oCAAoC,CACtC,SAAQ,IAAI,CACZ,iCAAiC,CAAC,UAAU,CAAC,EAC7C,gBAAgB,GAAG,SAAS,GAAG,uBAAuB,GAAG,MAAM,CAChE;IACC,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,oCAAoC,GAAG;IACjD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,mCAAmC,CACjD,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,oCAAoC,EAEtC,IAAI,EAAE,iCAAiC,CAAC,UAAU,CAAC,GAClD,uBAAuB,CAAC,UAAU,CAAC,CAerC"}
@@ -0,0 +1,70 @@
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
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.createToolResponseHandlingEvaluator = createToolResponseHandlingEvaluator;
15
+ const default_templates_1 = require("../__generated__/default_templates");
16
+ const createClassificationEvaluator_1 = require("./createClassificationEvaluator");
17
+ /**
18
+ * Creates a tool response handling evaluator function.
19
+ *
20
+ * This function returns an evaluator that determines whether an AI agent properly
21
+ * handled a tool's response, including error handling, data extraction,
22
+ * transformation, and safe information disclosure.
23
+ *
24
+ * @param args - The arguments for creating the tool response handling evaluator.
25
+ * @param args.model - The model to use for classification.
26
+ * @param args.choices - The possible classification choices (defaults to correct/incorrect).
27
+ * @param args.promptTemplate - The prompt template to use.
28
+ * @param args.telemetry - The telemetry to use for the evaluator.
29
+ *
30
+ * @returns An evaluator function that takes a {@link ToolResponseHandlingEvaluationRecord}
31
+ * and returns a classification result indicating whether the tool response handling
32
+ * is correct or incorrect.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const evaluator = createToolResponseHandlingEvaluator({ model: openai("gpt-4o-mini") });
37
+ *
38
+ * // Example: Correct extraction from tool result
39
+ * const result = await evaluator.evaluate({
40
+ * input: "What's the weather in Seattle?",
41
+ * toolCall: 'get_weather(location="Seattle")',
42
+ * toolResult: JSON.stringify({
43
+ * temperature: 58,
44
+ * unit: "fahrenheit",
45
+ * conditions: "partly cloudy"
46
+ * }),
47
+ * output: "The weather in Seattle is 58°F and partly cloudy."
48
+ * });
49
+ * console.log(result.label); // "correct"
50
+ *
51
+ * // Example: Hallucinated data (incorrect)
52
+ * const resultHallucinated = await evaluator.evaluate({
53
+ * input: "What restaurants are nearby?",
54
+ * toolCall: 'search_restaurants(location="downtown")',
55
+ * toolResult: JSON.stringify({
56
+ * results: [{ name: "Cafe Luna", rating: 4.2 }]
57
+ * }),
58
+ * output: "I found Cafe Luna (4.2 stars) and Mario's Italian (4.8 stars) nearby."
59
+ * });
60
+ * console.log(resultHallucinated.label); // "incorrect" - Mario's was hallucinated
61
+ * ```
62
+ */
63
+ function createToolResponseHandlingEvaluator(args) {
64
+ const { choices = default_templates_1.TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.choices, promptTemplate = default_templates_1.TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.template, optimizationDirection = default_templates_1.TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.optimizationDirection, name = default_templates_1.TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.name } = args, rest = __rest(args, ["choices", "promptTemplate", "optimizationDirection", "name"]);
65
+ return (0, createClassificationEvaluator_1.createClassificationEvaluator)(Object.assign(Object.assign({}, rest), { promptTemplate,
66
+ choices,
67
+ optimizationDirection,
68
+ name }));
69
+ }
70
+ //# sourceMappingURL=createToolResponseHandlingEvaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createToolResponseHandlingEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createToolResponseHandlingEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAwFA,kFAoBC;AA5GD,0EAA4G;AAI5G,mFAAgF;AAsChF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,SAAgB,mCAAmC,CAIjD,IAAmD;IAEnD,MAAM,EACJ,OAAO,GAAG,0EAAsD,CAAC,OAAO,EACxE,cAAc,GAAG,0EAAsD,CAAC,QAAQ,EAChF,qBAAqB,GAAG,0EAAsD,CAAC,qBAAqB,EACpG,IAAI,GAAG,0EAAsD,CAAC,IAAI,KAEhE,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"}
@@ -0,0 +1,64 @@
1
+ import { CreateClassificationEvaluatorArgs } from "../types/evals";
2
+ import { ClassificationEvaluator } from "./ClassificationEvaluator";
3
+ export interface ToolSelectionEvaluatorArgs<RecordType extends Record<string, unknown> = ToolSelectionEvaluationRecord> 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
+ }
9
+ /**
10
+ * A record to be evaluated by the tool selection evaluator.
11
+ */
12
+ export type ToolSelectionEvaluationRecord = {
13
+ /**
14
+ * The input query or conversation context.
15
+ */
16
+ input: string;
17
+ /**
18
+ * The available tools that the LLM could use.
19
+ */
20
+ availableTools: string;
21
+ /**
22
+ * The tool or tools selected by the LLM.
23
+ */
24
+ toolSelection: string;
25
+ };
26
+ /**
27
+ * Creates a tool selection evaluator function.
28
+ *
29
+ * This function returns an evaluator that determines whether the correct tool
30
+ * was selected for a given context. Unlike the tool invocation evaluator which
31
+ * checks if the tool was called correctly with proper arguments, this evaluator
32
+ * focuses on whether the right tool was chosen in the first place.
33
+ *
34
+ * The evaluator checks for:
35
+ * - Whether the LLM chose the best available tool for the user query
36
+ * - Whether the tool name exists in the available tools list
37
+ * - Whether the correct number of tools were selected for the task
38
+ * - Whether the tool selection is safe and appropriate
39
+ *
40
+ * @param args - The arguments for creating the tool selection evaluator.
41
+ * @param args.model - The model to use for classification.
42
+ * @param args.choices - The possible classification choices (defaults to correct/incorrect).
43
+ * @param args.promptTemplate - The prompt template to use (defaults to TOOL_SELECTION_TEMPLATE).
44
+ * @param args.telemetry - The telemetry to use for the evaluator.
45
+ *
46
+ * @returns An evaluator function that takes a {@link ToolSelectionEvaluationRecord} and returns
47
+ * a classification result indicating whether the tool selection is correct or incorrect.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const evaluator = createToolSelectionEvaluator({ model: openai("gpt-4o-mini") });
52
+ *
53
+ * const result = await evaluator.evaluate({
54
+ * input: "User: What is the weather in San Francisco?",
55
+ * availableTools: `WeatherTool: Get the current weather for a location.
56
+ * NewsTool: Stay connected to global events with our up-to-date news around the world.
57
+ * MusicTool: Create playlists, search for music, and check the latest music trends.`,
58
+ * toolSelection: "WeatherTool"
59
+ * });
60
+ * console.log(result.label); // "correct" or "incorrect"
61
+ * ```
62
+ */
63
+ export declare function createToolSelectionEvaluator<RecordType extends Record<string, unknown> = ToolSelectionEvaluationRecord>(args: ToolSelectionEvaluatorArgs<RecordType>): ClassificationEvaluator<RecordType>;
64
+ //# sourceMappingURL=createToolSelectionEvaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createToolSelectionEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createToolSelectionEvaluator.ts"],"names":[],"mappings":"AACA,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,CACZ,iCAAiC,CAAC,UAAU,CAAC,EAC7C,gBAAgB,GAAG,SAAS,GAAG,uBAAuB,GAAG,MAAM,CAChE;IACC,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;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;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"}
@@ -0,0 +1,61 @@
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
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.createToolSelectionEvaluator = createToolSelectionEvaluator;
15
+ const default_templates_1 = require("../__generated__/default_templates");
16
+ const createClassificationEvaluator_1 = require("./createClassificationEvaluator");
17
+ /**
18
+ * Creates a tool selection evaluator function.
19
+ *
20
+ * This function returns an evaluator that determines whether the correct tool
21
+ * was selected for a given context. Unlike the tool invocation evaluator which
22
+ * checks if the tool was called correctly with proper arguments, this evaluator
23
+ * focuses on whether the right tool was chosen in the first place.
24
+ *
25
+ * The evaluator checks for:
26
+ * - Whether the LLM chose the best available tool for the user query
27
+ * - Whether the tool name exists in the available tools list
28
+ * - Whether the correct number of tools were selected for the task
29
+ * - Whether the tool selection is safe and appropriate
30
+ *
31
+ * @param args - The arguments for creating the tool selection evaluator.
32
+ * @param args.model - The model to use for classification.
33
+ * @param args.choices - The possible classification choices (defaults to correct/incorrect).
34
+ * @param args.promptTemplate - The prompt template to use (defaults to TOOL_SELECTION_TEMPLATE).
35
+ * @param args.telemetry - The telemetry to use for the evaluator.
36
+ *
37
+ * @returns An evaluator function that takes a {@link ToolSelectionEvaluationRecord} and returns
38
+ * a classification result indicating whether the tool selection is correct or incorrect.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const evaluator = createToolSelectionEvaluator({ model: openai("gpt-4o-mini") });
43
+ *
44
+ * const result = await evaluator.evaluate({
45
+ * input: "User: What is the weather in San Francisco?",
46
+ * availableTools: `WeatherTool: Get the current weather for a location.
47
+ * NewsTool: Stay connected to global events with our up-to-date news around the world.
48
+ * MusicTool: Create playlists, search for music, and check the latest music trends.`,
49
+ * toolSelection: "WeatherTool"
50
+ * });
51
+ * console.log(result.label); // "correct" or "incorrect"
52
+ * ```
53
+ */
54
+ function createToolSelectionEvaluator(args) {
55
+ const { choices = default_templates_1.TOOL_SELECTION_CLASSIFICATION_EVALUATOR_CONFIG.choices, promptTemplate = default_templates_1.TOOL_SELECTION_CLASSIFICATION_EVALUATOR_CONFIG.template, optimizationDirection = default_templates_1.TOOL_SELECTION_CLASSIFICATION_EVALUATOR_CONFIG.optimizationDirection, name = default_templates_1.TOOL_SELECTION_CLASSIFICATION_EVALUATOR_CONFIG.name } = args, rest = __rest(args, ["choices", "promptTemplate", "optimizationDirection", "name"]);
56
+ return (0, createClassificationEvaluator_1.createClassificationEvaluator)(Object.assign(Object.assign({}, rest), { promptTemplate,
57
+ choices,
58
+ optimizationDirection,
59
+ name }));
60
+ }
61
+ //# sourceMappingURL=createToolSelectionEvaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createToolSelectionEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createToolSelectionEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAyEA,oEAmBC;AA5FD,0EAAoG;AAIpG,mFAAgF;AAgChF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,SAAgB,4BAA4B,CAG1C,IAA4C;IAE5C,MAAM,EACJ,OAAO,GAAG,kEAA8C,CAAC,OAAO,EAChE,cAAc,GAAG,kEAA8C,CAAC,QAAQ,EACxE,qBAAqB,GAAG,kEAA8C,CAAC,qBAAqB,EAC5F,IAAI,GAAG,kEAA8C,CAAC,IAAI,KAExD,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,9 +1,13 @@
1
- export * from "./generateClassification";
2
- export * from "./createClassifierFn";
1
+ export * from "./ClassificationEvaluator";
3
2
  export * from "./createClassificationEvaluator";
4
- export * from "./createHallucinationEvaluator";
5
- export * from "./createDocumentRelevanceEvaluator";
3
+ export * from "./createClassifierFn";
6
4
  export * from "./createCorrectnessEvaluator";
7
- export * from "./ClassificationEvaluator";
5
+ export * from "./createDocumentRelevanceEvaluator";
6
+ export * from "./createFaithfulnessEvaluator";
7
+ export * from "./createHallucinationEvaluator";
8
+ export * from "./createToolInvocationEvaluator";
9
+ export * from "./createToolResponseHandlingEvaluator";
10
+ export * from "./createToolSelectionEvaluator";
11
+ export * from "./generateClassification";
8
12
  export * from "./LLMEvaluator";
9
13
  //# 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,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/llm/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC"}
@@ -14,12 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./generateClassification"), exports);
18
- __exportStar(require("./createClassifierFn"), exports);
17
+ __exportStar(require("./ClassificationEvaluator"), exports);
19
18
  __exportStar(require("./createClassificationEvaluator"), exports);
20
- __exportStar(require("./createHallucinationEvaluator"), exports);
21
- __exportStar(require("./createDocumentRelevanceEvaluator"), exports);
19
+ __exportStar(require("./createClassifierFn"), exports);
22
20
  __exportStar(require("./createCorrectnessEvaluator"), exports);
23
- __exportStar(require("./ClassificationEvaluator"), exports);
21
+ __exportStar(require("./createDocumentRelevanceEvaluator"), exports);
22
+ __exportStar(require("./createFaithfulnessEvaluator"), exports);
23
+ __exportStar(require("./createHallucinationEvaluator"), exports); // Deprecated: use createFaithfulnessEvaluator
24
+ __exportStar(require("./createToolInvocationEvaluator"), exports);
25
+ __exportStar(require("./createToolResponseHandlingEvaluator"), exports);
26
+ __exportStar(require("./createToolSelectionEvaluator"), exports);
27
+ __exportStar(require("./generateClassification"), exports);
24
28
  __exportStar(require("./LLMEvaluator"), exports);
25
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/llm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,uDAAqC;AACrC,kEAAgD;AAChD,iEAA+C;AAC/C,qEAAmD;AACnD,+DAA6C;AAC7C,4DAA0C;AAC1C,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/llm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,kEAAgD;AAChD,uDAAqC;AACrC,+DAA6C;AAC7C,qEAAmD;AACnD,gEAA8C;AAC9C,iEAA+C,CAAC,8CAA8C;AAC9F,kEAAgD;AAChD,wEAAsD;AACtD,iEAA+C;AAC/C,2DAAyC;AACzC,iDAA+B"}
@@ -1 +1 @@
1
- {"version":3,"file":"evals.d.ts","sourceRoot":"","sources":["../../../src/types/evals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,aAAa,C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