@arizeai/phoenix-evals 2.6.0 → 2.7.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 (79) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/esm/decision/decideClassification.d.ts +20 -0
  3. package/dist/esm/decision/decideClassification.d.ts.map +1 -0
  4. package/dist/esm/decision/decideClassification.js +72 -0
  5. package/dist/esm/decision/decideClassification.js.map +1 -0
  6. package/dist/esm/decision/decisionPrompt.d.ts +8 -0
  7. package/dist/esm/decision/decisionPrompt.d.ts.map +1 -0
  8. package/dist/esm/decision/decisionPrompt.js +66 -0
  9. package/dist/esm/decision/decisionPrompt.js.map +1 -0
  10. package/dist/esm/llm/ClassificationEvaluator.d.ts +2 -2
  11. package/dist/esm/llm/ClassificationEvaluator.d.ts.map +1 -1
  12. package/dist/esm/llm/ClassificationEvaluator.js.map +1 -1
  13. package/dist/esm/llm/generateClassification.d.ts +5 -5
  14. package/dist/esm/llm/generateClassification.d.ts.map +1 -1
  15. package/dist/esm/llm/generateClassification.js +20 -71
  16. package/dist/esm/llm/generateClassification.js.map +1 -1
  17. package/dist/esm/telemetry/index.d.ts +14 -0
  18. package/dist/esm/telemetry/index.d.ts.map +1 -1
  19. package/dist/esm/telemetry/index.js +15 -0
  20. package/dist/esm/telemetry/index.js.map +1 -1
  21. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  22. package/dist/esm/types/evals.d.ts +8 -6
  23. package/dist/esm/types/evals.d.ts.map +1 -1
  24. package/dist/esm/utils/index.d.ts +1 -0
  25. package/dist/esm/utils/index.d.ts.map +1 -1
  26. package/dist/esm/utils/index.js +1 -0
  27. package/dist/esm/utils/index.js.map +1 -1
  28. package/dist/esm/utils/isDecisionModel.d.ts +18 -0
  29. package/dist/esm/utils/isDecisionModel.d.ts.map +1 -0
  30. package/dist/esm/utils/isDecisionModel.js +13 -0
  31. package/dist/esm/utils/isDecisionModel.js.map +1 -0
  32. package/dist/src/decision/decideClassification.d.ts +20 -0
  33. package/dist/src/decision/decideClassification.d.ts.map +1 -0
  34. package/dist/src/decision/decideClassification.js +71 -0
  35. package/dist/src/decision/decideClassification.js.map +1 -0
  36. package/dist/src/decision/decisionPrompt.d.ts +8 -0
  37. package/dist/src/decision/decisionPrompt.d.ts.map +1 -0
  38. package/dist/src/decision/decisionPrompt.js +69 -0
  39. package/dist/src/decision/decisionPrompt.js.map +1 -0
  40. package/dist/src/llm/ClassificationEvaluator.d.ts +2 -2
  41. package/dist/src/llm/ClassificationEvaluator.d.ts.map +1 -1
  42. package/dist/src/llm/generateClassification.d.ts +5 -5
  43. package/dist/src/llm/generateClassification.d.ts.map +1 -1
  44. package/dist/src/llm/generateClassification.js +18 -70
  45. package/dist/src/llm/generateClassification.js.map +1 -1
  46. package/dist/src/telemetry/index.d.ts +14 -0
  47. package/dist/src/telemetry/index.d.ts.map +1 -1
  48. package/dist/src/telemetry/index.js +17 -0
  49. package/dist/src/telemetry/index.js.map +1 -1
  50. package/dist/src/types/evals.d.ts +8 -6
  51. package/dist/src/types/evals.d.ts.map +1 -1
  52. package/dist/src/utils/index.d.ts +1 -0
  53. package/dist/src/utils/index.d.ts.map +1 -1
  54. package/dist/src/utils/index.js +1 -0
  55. package/dist/src/utils/index.js.map +1 -1
  56. package/dist/src/utils/isDecisionModel.d.ts +18 -0
  57. package/dist/src/utils/isDecisionModel.d.ts.map +1 -0
  58. package/dist/src/utils/isDecisionModel.js +16 -0
  59. package/dist/src/utils/isDecisionModel.js.map +1 -0
  60. package/dist/tsconfig.tsbuildinfo +1 -1
  61. package/docs/classification.mdx +43 -1
  62. package/package.json +13 -13
  63. package/src/decision/decideClassification.ts +85 -0
  64. package/src/decision/decisionPrompt.ts +70 -0
  65. package/src/llm/ClassificationEvaluator.ts +2 -2
  66. package/src/llm/generateClassification.ts +20 -82
  67. package/src/telemetry/index.ts +21 -0
  68. package/src/types/evals.ts +8 -6
  69. package/src/utils/index.ts +1 -0
  70. package/src/utils/isDecisionModel.ts +29 -0
  71. package/dist/esm/utils/isEvaluationModel.d.ts +0 -13
  72. package/dist/esm/utils/isEvaluationModel.d.ts.map +0 -1
  73. package/dist/esm/utils/isEvaluationModel.js +0 -11
  74. package/dist/esm/utils/isEvaluationModel.js.map +0 -1
  75. package/dist/src/utils/isEvaluationModel.d.ts +0 -13
  76. package/dist/src/utils/isEvaluationModel.d.ts.map +0 -1
  77. package/dist/src/utils/isEvaluationModel.js +0 -14
  78. package/dist/src/utils/isEvaluationModel.js.map +0 -1
  79. package/src/utils/isEvaluationModel.ts +0 -23
@@ -1,5 +1,5 @@
1
1
  import type { LanguageModel } from "ai";
2
- import type { EvaluationModel } from "../utils/isEvaluationModel.js";
2
+ import type { DecisionModel } from "../utils/isDecisionModel.js";
3
3
  import type { ObjectMapping } from "./data.js";
4
4
  import type { WithTelemetry } from "./otel.js";
5
5
  import type { PromptTemplate } from "./templating.js";
@@ -15,10 +15,12 @@ export interface ExampleRecord<OutputType, InputType> {
15
15
  export interface WithLLM {
16
16
  /**
17
17
  * Either a regular AI SDK {@link LanguageModel}, or an AI SDK
18
- * {@link EvaluationModel} (e.g. TypeSafe's Jev) which classifies without
19
- * generating text and therefore cannot produce an explanation.
18
+ * {@link DecisionModel} (e.g. `openai.decisionModel("gpt-6-luna")`) which
19
+ * classifies without generating text and therefore cannot produce an
20
+ * explanation. With a decision model, label probabilities are returned in
21
+ * the result's `metadata.probabilities`.
20
22
  */
21
- model: LanguageModel | EvaluationModel;
23
+ model: LanguageModel | DecisionModel;
22
24
  }
23
25
  export interface LLMEvaluationArgs extends WithLLM {
24
26
  }
@@ -43,7 +45,7 @@ export interface EvaluationResult {
43
45
  explanation?: string;
44
46
  /**
45
47
  * Additional information about how the result was produced, e.g. the
46
- * label probabilities reported by an evaluation model.
48
+ * label probabilities reported by a decision model.
47
49
  */
48
50
  metadata?: Record<string, unknown>;
49
51
  }
@@ -70,7 +72,7 @@ export type ClassificationChoicesMap = Record<string, number>;
70
72
  * The arguments for creating a classification-based evaluator
71
73
  */
72
74
  export interface CreateClassifierArgs extends WithTelemetry {
73
- model: LanguageModel | EvaluationModel;
75
+ model: LanguageModel | DecisionModel;
74
76
  /**
75
77
  * The choices to classify the example into.
76
78
  * e.g. { "correct": 1, "incorrect": 0 }
@@ -1 +1 @@
1
- {"version":3,"file":"evals.d.ts","sourceRoot":"","sources":["../../../src/types/evals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,UAAU,EAAE,SAAS;IAClD,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;;;;OAIG;IACH,KAAK,EAAE,aAAa,GAAG,eAAe,CAAC;CACxC;AAGD,MAAM,WAAW,iBAAkB,SAAQ,OAAO;CAAG;AAErD;;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;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAA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,WAAW,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,sBAAsB,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC3E,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;AAEhD,MAAM,WAAW,iCAAiC,CAChD,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE1C,SAAQ,oBAAoB,EAAE,sBAAsB,CAAC,UAAU,CAAC;IAChE;;OAEG;IACH,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,MAAM,MAAM,WAAW,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CACrE,IAAI,EAAE,WAAW,KACd,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;AAExE;;GAEG;AACH,UAAU,oBAAoB;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,cAAc,CAAC;IACrB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CACjC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3C,SAAQ,oBAAoB;IAC5B;;OAEG;IACH,QAAQ,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;CACpC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./bindEvaluator.js";
2
+ export * from "./isDecisionModel.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./bindEvaluator.js";
2
+ export * from "./isDecisionModel.js";
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Experimental_DecisionModel, LanguageModel } from "ai";
2
+ /**
3
+ * An AI SDK decision model instance, e.g. `openai.decisionModel("gpt-6-luna")`
4
+ * or TypeSafe's Jev. Unlike a {@link LanguageModel}, a decision model only
5
+ * answers typed questions (here, which label applies) and cannot generate
6
+ * free-form text, so classifications made with it have no explanation.
7
+ *
8
+ * Gateway string IDs are excluded: a plain string is treated as a language
9
+ * model. Wrap the ID with the provider's `decisionModel()` instead.
10
+ */
11
+ export type DecisionModel = Exclude<Experimental_DecisionModel, string>;
12
+ /**
13
+ * Type guard that distinguishes an AI SDK decision model from a language model.
14
+ * Decision models expose `doDecide` (or `doEvaluate` for providers written
15
+ * against the older evaluation model spec) instead of `doGenerate`.
16
+ */
17
+ export declare function isDecisionModel(model: LanguageModel | DecisionModel): model is DecisionModel;
18
+ //# sourceMappingURL=isDecisionModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isDecisionModel.d.ts","sourceRoot":"","sources":["../../../src/utils/isDecisionModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAEpE;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,aAAa,GAAG,aAAa,GACnC,KAAK,IAAI,aAAa,CAQxB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Type guard that distinguishes an AI SDK decision model from a language model.
3
+ * Decision models expose `doDecide` (or `doEvaluate` for providers written
4
+ * against the older evaluation model spec) instead of `doGenerate`.
5
+ */
6
+ export function isDecisionModel(model) {
7
+ if (typeof model !== "object" || model === null) {
8
+ return false;
9
+ }
10
+ return (("doDecide" in model && typeof model.doDecide === "function") ||
11
+ ("doEvaluate" in model && typeof model.doEvaluate === "function"));
12
+ }
13
+ //# sourceMappingURL=isDecisionModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isDecisionModel.js","sourceRoot":"","sources":["../../../src/utils/isDecisionModel.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAoC;IAEpC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CACL,CAAC,UAAU,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,CAAC;QAC7D,CAAC,YAAY,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAClE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { ClassificationResult } from "../types/evals";
2
+ import type { TelemetryConfig } from "../types/otel";
3
+ import type { WithPrompt } from "../types/prompts";
4
+ import type { DecisionModel } from "../utils/isDecisionModel";
5
+ /**
6
+ * Classify with an AI SDK decision model by asking one choice question whose
7
+ * options are the labels. Decision models don't generate text, so the
8
+ * result has no explanation. Label probabilities, the provider's confidence
9
+ * (when it reports one) and the resolved model ID go in the metadata.
10
+ *
11
+ * Choice limits and refusals are left to the AI SDK and the provider: a
12
+ * refusal throws the AI SDK's `Experimental_DecisionRefusalError`.
13
+ */
14
+ export declare function decideClassification(args: {
15
+ model: DecisionModel;
16
+ labels: readonly string[];
17
+ prompt: WithPrompt;
18
+ telemetry?: TelemetryConfig;
19
+ }): Promise<ClassificationResult>;
20
+ //# sourceMappingURL=decideClassification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decideClassification.d.ts","sourceRoot":"","sources":["../../../src/decision/decideClassification.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAe9D;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA2BhC"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decideClassification = decideClassification;
4
+ /**
5
+ * The only place phoenix-evals calls the AI SDK's experimental decision API.
6
+ * `experimental_decide` and the decision model spec may change in AI SDK
7
+ * patch releases, so keep everything that depends on their shape in here.
8
+ */
9
+ const ai_1 = require("ai");
10
+ const telemetry_1 = require("../telemetry");
11
+ const decisionPrompt_1 = require("./decisionPrompt");
12
+ /**
13
+ * The ID of the single choice question asked per classification.
14
+ */
15
+ const QUESTION_ID = "label";
16
+ /**
17
+ * The question's instructions. The rendered prompt, rubric included, is sent
18
+ * as the state.
19
+ */
20
+ const INSTRUCTIONS = "Read the prompt in the state and answer it by selecting exactly one of the choices.";
21
+ /**
22
+ * Classify with an AI SDK decision model by asking one choice question whose
23
+ * options are the labels. Decision models don't generate text, so the
24
+ * result has no explanation. Label probabilities, the provider's confidence
25
+ * (when it reports one) and the resolved model ID go in the metadata.
26
+ *
27
+ * Choice limits and refusals are left to the AI SDK and the provider: a
28
+ * refusal throws the AI SDK's `Experimental_DecisionRefusalError`.
29
+ */
30
+ async function decideClassification(args) {
31
+ const { model, labels, prompt, telemetry } = args;
32
+ const result = await (0, ai_1.experimental_decide)({
33
+ model,
34
+ state: (0, decisionPrompt_1.promptToDecisionState)(prompt),
35
+ questions: {
36
+ [QUESTION_ID]: {
37
+ type: "choice",
38
+ instructions: INSTRUCTIONS,
39
+ criteria: Object.fromEntries(labels.map((label) => [label, null])),
40
+ },
41
+ },
42
+ telemetry: (0, telemetry_1.getTelemetryOptions)({
43
+ functionId: "decideClassification",
44
+ telemetry,
45
+ }),
46
+ });
47
+ const answer = result.answers[QUESTION_ID];
48
+ const confidence = getConfidence(result.providerMetadata);
49
+ return {
50
+ label: answer.choice,
51
+ metadata: Object.assign(Object.assign({ probabilities: answer.probabilities }, (confidence !== undefined ? { confidence } : {})), { modelId: result.response.modelId }),
52
+ };
53
+ }
54
+ /**
55
+ * The decision model spec has no confidence field, but providers that
56
+ * report one (OpenAI, TypeSafe) put it in their provider metadata as
57
+ * `confidence[questionId]`.
58
+ */
59
+ function getConfidence(providerMetadata) {
60
+ var _a;
61
+ if (typeof providerMetadata !== "object" || providerMetadata === null) {
62
+ return undefined;
63
+ }
64
+ for (const metadata of Object.values(providerMetadata)) {
65
+ const confidence = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.confidence) === null || _a === void 0 ? void 0 : _a[QUESTION_ID];
66
+ if (typeof confidence === "number")
67
+ return confidence;
68
+ }
69
+ return undefined;
70
+ }
71
+ //# sourceMappingURL=decideClassification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decideClassification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IG;AACH,SAAS,aAAa,CAAC,gBAAyB;;IAC9C,IAAI,OAAO,gBAAgB,KAAK,QAAQ,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACtE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACvD,MAAM,UAAU,GAAG,MAAC,QAAqD,aAArD,QAAQ,uBAAR,QAAQ,CACxB,UAAU,0CAAG,WAAW,CAAC,CAAC;QAC9B,IAAI,OAAO,UAAU,KAAK,QAAQ;YAAE,OAAO,UAAU,CAAC;IACxD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { WithPrompt } from "../types/prompts";
2
+ /**
3
+ * Join a rendered AI SDK prompt into the plain-text state a decision model
4
+ * judges. Decision models have no roles, so system text, instructions and
5
+ * messages are joined in order.
6
+ */
7
+ export declare function promptToDecisionState(prompt: WithPrompt): string;
8
+ //# sourceMappingURL=decisionPrompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decisionPrompt.d.ts","sourceRoot":"","sources":["../../../src/decision/decisionPrompt.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAahE"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promptToDecisionState = promptToDecisionState;
4
+ /**
5
+ * Join a rendered AI SDK prompt into the plain-text state a decision model
6
+ * judges. Decision models have no roles, so system text, instructions and
7
+ * messages are joined in order.
8
+ */
9
+ function promptToDecisionState(prompt) {
10
+ const parts = [];
11
+ const { instructions, system, messages, prompt: promptContent } = prompt;
12
+ for (const value of [instructions, system]) {
13
+ if (value !== undefined)
14
+ parts.push(instructionsToText(value));
15
+ }
16
+ if (typeof promptContent === "string") {
17
+ parts.push(promptContent);
18
+ }
19
+ else if (Array.isArray(promptContent)) {
20
+ parts.push(messagesToText(promptContent));
21
+ }
22
+ if (messages !== undefined)
23
+ parts.push(messagesToText(messages));
24
+ return parts.filter((part) => part.length > 0).join("\n\n");
25
+ }
26
+ function messagesToText(messages) {
27
+ return messages
28
+ .map((message) => contentToText(message.content))
29
+ .filter((text) => text.length > 0)
30
+ .join("\n\n");
31
+ }
32
+ function instructionsToText(value) {
33
+ if (typeof value === "string")
34
+ return value;
35
+ if (Array.isArray(value)) {
36
+ return value
37
+ .map((item) => typeof item === "object" && item !== null && "content" in item
38
+ ? contentToText(item.content)
39
+ : "")
40
+ .filter((text) => text.length > 0)
41
+ .join("\n\n");
42
+ }
43
+ if (typeof value === "object" && value !== null && "content" in value) {
44
+ return contentToText(value.content);
45
+ }
46
+ return "";
47
+ }
48
+ /**
49
+ * Keep only the text of a message. Decision models judge text here; image
50
+ * and file parts are not forwarded.
51
+ */
52
+ function contentToText(content) {
53
+ if (typeof content === "string")
54
+ return content;
55
+ if (!Array.isArray(content))
56
+ return "";
57
+ return content
58
+ .map((part) => typeof part === "object" &&
59
+ part !== null &&
60
+ "type" in part &&
61
+ part.type === "text" &&
62
+ "text" in part &&
63
+ typeof part.text === "string"
64
+ ? part.text
65
+ : "")
66
+ .filter((text) => text.length > 0)
67
+ .join("\n");
68
+ }
69
+ //# sourceMappingURL=decisionPrompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decisionPrompt.js","sourceRoot":"","sources":["../../../src/decision/decisionPrompt.ts"],"names":[],"mappings":";;;AAIA;;;;GAIG;AACH,+BAAsC,MAAkB;IACtD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IACzE,KAAK,MAAM,KAAK,IAAI,CAAC,YA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,CAAC,IAAI,CAAC,OAAO,CAAC;YAC7B,CAAC,CAAC,EAAE,CACP;aACA,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;aACjC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QACtE,OAAO,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,SAAS,aAAa,CAAC,OAAgB;IACrC,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,MAAM,IAAI,IAAI;QACd,IAAI,CAAC,IAAI,KAAK,MAAM;QACpB,MAAM,IAAI,IAAI;QACd,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAC3B,CAAC,CAAC,IAAI,CAAC,IAAI;QACX,CAAC,CAAC,EAAE,CACP;SACA,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;SACjC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import type { LanguageModel } from "ai";
2
2
  import type { ClassificationChoicesMap, CreateClassificationEvaluatorArgs, EvaluatorFn, PromptTemplate, WithPromptTemplate } from "../types";
3
3
  import type { ObjectMapping } from "../types/data";
4
- import type { EvaluationModel } from "../utils/isEvaluationModel";
4
+ import type { DecisionModel } from "../utils/isDecisionModel";
5
5
  import { LLMEvaluator } from "./LLMEvaluator";
6
6
  /**
7
7
  * An LLM evaluator that performs evaluation via classification
@@ -16,7 +16,7 @@ export declare class ClassificationEvaluator<RecordType extends Record<string, u
16
16
  /**
17
17
  * The model to use for classification
18
18
  */
19
- readonly model: LanguageModel | EvaluationModel;
19
+ readonly model: LanguageModel | DecisionModel;
20
20
  /**
21
21
  * The choices to classify the example into
22
22
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ClassificationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAGxC,OAAO,KAAK,EACV,wBAAwB,EACxB,iCAAiC,EACjC,WAAW,EACX,cAAc,EACd,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,qBAAa,uBAAuB,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC7E,SAAQ,YAAY,CAAC,UAAU,CAC/B,YAAW,kBAAkB;IAE7B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAC9C,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC;;OAEG;IACH,OAAO,CAAC,wBAAwB,CAAuB;IACvD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,eAAe,CAAC;IAChD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAE3C,YAAY,IAAI,EAAE,iCAAiC,CAAC,UAAU,CAAC,EAQ9D;IACD,QAAQ,YAAa,UAAU,kDAM7B;IACF;;OAEG;IACH,IAAI,uB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rC;CACF"}
@@ -18,11 +18,11 @@ export type ClassifyArgs = WithLLM & WithTelemetry & WithPrompt & {
18
18
  /**
19
19
  * A function that leverages an llm to perform a classification
20
20
  *
21
- * When given an AI SDK evaluation model (e.g. TypeSafe's Jev) the
22
- * classification is routed through `experimental_evaluate` as a single
23
- * choice question. Evaluation models cannot generate text, so no explanation
24
- * is returned in that case. `telemetry`, `schemaName` and `schemaDescription`
25
- * are ignored on that path: `experimental_evaluate` does not emit spans yet.
21
+ * When given an AI SDK decision model (e.g. `openai.decisionModel("gpt-6-luna")`)
22
+ * the classification is routed through `experimental_decide` as a single
23
+ * choice question, with the prompt sent as plain text. Decision models cannot
24
+ * generate text, so no explanation is returned in that case, and
25
+ * `schemaName` / `schemaDescription` are ignored.
26
26
  */
27
27
  export declare function generateClassification(args: ClassifyArgs): Promise<ClassificationResult>;
28
28
  //# sourceMappingURL=generateClassification.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateClassification.d.ts","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD,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;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAgC/B"}
1
+ {"version":3,"file":"generateClassification.d.ts","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnD,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;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAkC/B"}
@@ -14,34 +14,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.generateClassification = generateClassification;
15
15
  const ai_1 = require("ai");
16
16
  const zod_1 = require("zod");
17
+ const decideClassification_1 = require("../decision/decideClassification");
17
18
  const telemetry_1 = require("../telemetry");
18
- const isEvaluationModel_1 = require("../utils/isEvaluationModel");
19
+ const isDecisionModel_1 = require("../utils/isDecisionModel");
19
20
  /**
20
21
  * A function that leverages an llm to perform a classification
21
22
  *
22
- * When given an AI SDK evaluation model (e.g. TypeSafe's Jev) the
23
- * classification is routed through `experimental_evaluate` as a single
24
- * choice question. Evaluation models cannot generate text, so no explanation
25
- * is returned in that case. `telemetry`, `schemaName` and `schemaDescription`
26
- * are ignored on that path: `experimental_evaluate` does not emit spans yet.
23
+ * When given an AI SDK decision model (e.g. `openai.decisionModel("gpt-6-luna")`)
24
+ * the classification is routed through `experimental_decide` as a single
25
+ * choice question, with the prompt sent as plain text. Decision models cannot
26
+ * generate text, so no explanation is returned in that case, and
27
+ * `schemaName` / `schemaDescription` are ignored.
27
28
  */
28
29
  async function generateClassification(args) {
29
- var _a, _b;
30
30
  const { labels, model, schemaName, schemaDescription, telemetry } = args, prompt = __rest(args, ["labels", "model", "schemaName", "schemaDescription", "telemetry"]);
31
- if ((0, isEvaluationModel_1.isEvaluationModel)(model)) {
32
- return evaluateClassification({ model, labels, prompt });
31
+ if ((0, isDecisionModel_1.isDecisionModel)(model)) {
32
+ return (0, decideClassification_1.decideClassification)({
33
+ model,
34
+ labels,
35
+ prompt,
36
+ telemetry,
37
+ });
33
38
  }
34
- const telemetryOptions = {
35
- isEnabled: (_a = telemetry === null || telemetry === void 0 ? void 0 : telemetry.isEnabled) !== null && _a !== void 0 ? _a : true,
36
- functionId: "generateClassification",
37
- integrations: (0, telemetry_1.getTelemetryIntegrations)((_b = telemetry === null || telemetry === void 0 ? void 0 : telemetry.tracer) !== null && _b !== void 0 ? _b : telemetry_1.tracer),
38
- };
39
39
  const result = await (0, ai_1.generateObject)(Object.assign({ model,
40
40
  schemaName,
41
41
  schemaDescription, schema: zod_1.z.object({
42
42
  explanation: zod_1.z.string(), // We place the explanation in hopes it uses reasoning to explain the label.
43
43
  label: zod_1.z.enum(labels),
44
- }), telemetry: telemetryOptions,
44
+ }), telemetry: (0, telemetry_1.getTelemetryOptions)({
45
+ functionId: "generateClassification",
46
+ telemetry,
47
+ }),
45
48
  // AI SDK 7 rejects system messages inside `messages` by default; keep
46
49
  // accepting them since prompt templates may include system messages.
47
50
  allowSystemInMessages: true }, prompt));
@@ -50,59 +53,4 @@ async function generateClassification(args) {
50
53
  explanation: result.object.explanation,
51
54
  };
52
55
  }
53
- /**
54
- * Classify using an AI SDK evaluation model. The rendered prompt becomes the
55
- * shared evaluation state and the labels become the options of one choice
56
- * question. The model's label probabilities and resolved model id are
57
- * returned as metadata.
58
- */
59
- async function evaluateClassification(args) {
60
- const { model, labels, prompt } = args;
61
- const result = await (0, ai_1.experimental_evaluate)({
62
- model,
63
- state: toEvaluationState(prompt),
64
- questions: {
65
- label: {
66
- type: "choice",
67
- instructions: "Read the prompt in the state and answer it by selecting exactly one of the choices.",
68
- criteria: Object.fromEntries(labels.map((label) => [label, null])),
69
- },
70
- },
71
- });
72
- const answer = result.answers.label;
73
- return {
74
- label: answer.choice,
75
- metadata: {
76
- probabilities: answer.probabilities,
77
- modelId: result.response.modelId,
78
- },
79
- };
80
- }
81
- /**
82
- * Convert an AI SDK prompt into JSON-compatible evaluation state.
83
- * A bare text prompt is passed through as a string; anything else
84
- * (instructions, system messages, message arrays) is serialized to JSON.
85
- */
86
- function toEvaluationState(prompt) {
87
- const { instructions, system, messages, prompt: promptContent } = prompt;
88
- if (typeof promptContent === "string" &&
89
- instructions === undefined &&
90
- system === undefined &&
91
- messages === undefined) {
92
- return promptContent;
93
- }
94
- const state = {};
95
- if (instructions !== undefined)
96
- state.instructions = instructions;
97
- if (system !== undefined)
98
- state.system = system;
99
- if (promptContent !== undefined)
100
- state.prompt = promptContent;
101
- if (messages !== undefined)
102
- state.messages = messages;
103
- // Round-trip through JSON so the state only contains JSON values
104
- // (strips `undefined`, turns Date/URL into strings). Binary file parts
105
- // are not supported by evaluation models and are not stripped here.
106
- return JSON.parse(JSON.stringify(state));
107
- }
108
56
  //# sourceMappingURL=generateClassification.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2BAA2D;AAC3D,6BAAwB;AAExB,4CAAgE;AAIhE,kEAGoC;AAkBpC;;;;;;;;GAQG;AACI,KAAK,iCACV,IAAkB;;IAElB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,KAC7D,IAAI,EAD8D,MAAM,UACxE,IAAI,EADA,mEAAsE,CACtE,CAAC;IAEP,IAAI,IAAA,qCAAiB,EAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,sBAAsB,CAAC,E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CAAC,CAAC;aACnE;SACF;KACF,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;IACpC,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM;QACpB,QAAQ,EAAE;YACR,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO;SACjC;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,iBAAiB,CAAC,MAAkB;IAC3C,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IACzE,IACE,OAAO,aAAa,KAAK,QAAQ;QACjC,YAAY,KAAK,SAAS;QAC1B,MAAM,KAAK,SAAS;QACpB,QAAQ,KAAK,SAAS,EACtB,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,IAAI,YAAY,KAAK,SAAS;QAAE,KAAK,CAAC,YAAY,GAAG,YAAY,CAAC;IAClE,IAAI,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IAChD,IAAI,aAAa,KAAK,SAAS;QAAE,KAAK,CAAC,MAAM,GAAG,aAAa,CAAC;IAC9D,IAAI,QAAQ,KAAK,SAAS;QAAE,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACtD,iEAAiE;IACjE,uEAAuE;IACvE,oEAAoE;IACpE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAoB,CAAC;AAC9D,CAAC"}
1
+ {"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2BAAoC;AACpC,6BAAwB;AAExB,2EAAwE;AACxE,4CAAmD;AAInD,8DAA2D;AAkB3D;;;;;;;;GAQG;AACI,KAAK,iCACV,IAAkB;IAElB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,KAC7D,IAAI,EAD8D,MAAM,UACxE,IAAI,EADA,mEAAsE,CACtE,CAAC;IAEP,IAAI,IAAA,iCAAe,EAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAA,2CAAoB,EAAC;YAC1B,KAAK;YACL,MAAM;YACN,MAAM;YACN,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAc,kBACjC,KAAK;QACL,UAAU;QACV,iBAAiB,EACjB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;YACf,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,4EAA4E;YACrG,KAAK,EAAE,OAAC,CAAC,IAAI,CAAC,MAAM,CAAC;SACtB,CAAC,EACF,SAAS,EAAE,IAAA,+BAAmB,EAAC;YAC7B,UAAU,EAAE,wBAAwB;YACpC,SAAS;SACV,CAAC;QACF,sEAAsE;QACtE,qEAAqE;QACrE,qBAAqB,EAAE,IAAI,IACxB,MAAM,EACT,CAAC;IACH,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;QAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW;KACvC,CAAC;AACJ,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { type Tracer } from "@opentelemetry/api";
2
2
  import type { Telemetry } from "ai";
3
+ import type { TelemetryConfig } from "../types/otel";
3
4
  /**
4
5
  * Returns a lazy tracer that resolves from `trace.getTracer()` on every call,
5
6
  * so evaluator spans follow whichever provider is currently mounted as global.
@@ -18,4 +19,17 @@ export declare const tracer: Tracer;
18
19
  * used as-is so the call is not traced twice.
19
20
  */
20
21
  export declare function getTelemetryIntegrations(integrationTracer: Tracer): Telemetry[];
22
+ /**
23
+ * Builds the AI SDK `telemetry` call option for an evaluator call. Telemetry
24
+ * is on unless explicitly disabled, and spans go to the configured tracer or
25
+ * the default Phoenix tracer.
26
+ */
27
+ export declare function getTelemetryOptions(args: {
28
+ functionId: string;
29
+ telemetry?: TelemetryConfig;
30
+ }): {
31
+ isEnabled: boolean;
32
+ functionId: string;
33
+ integrations: Telemetry[];
34
+ };
21
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/telemetry/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAIpC;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAA4B,GAAG,MAAM,CAUpE;AAED,eAAO,MAAM,MAAM,QAAc,CAAC;AAElC;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,iBAAiB,EAAE,MAAM,GACxB,SAAS,EAAE,CAsBb"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/telemetry/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIrD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAA4B,GAAG,MAAM,CAUpE;AAED,eAAO,MAAM,MAAM,QAAc,CAAC;AAElC;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,iBAAiB,EAAE,MAAM,GACxB,SAAS,EAAE,CAwBb;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;;;;EAOA"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tracer = void 0;
4
4
  exports.getTracer = getTracer;
5
5
  exports.getTelemetryIntegrations = getTelemetryIntegrations;
6
+ exports.getTelemetryOptions = getTelemetryOptions;
6
7
  const otel_1 = require("@ai-sdk/otel");
7
8
  const api_1 = require("@opentelemetry/api");
8
9
  const DEFAULT_TRACER_NAME = "phoenix-evals";
@@ -52,7 +53,23 @@ function getTelemetryIntegrations(integrationTracer) {
52
53
  usage: true,
53
54
  providerMetadata: true,
54
55
  schema: true,
56
+ // Record the state, questions and answers of decision model calls.
57
+ experimental_decision: true,
55
58
  }),
56
59
  ];
57
60
  }
61
+ /**
62
+ * Builds the AI SDK `telemetry` call option for an evaluator call. Telemetry
63
+ * is on unless explicitly disabled, and spans go to the configured tracer or
64
+ * the default Phoenix tracer.
65
+ */
66
+ function getTelemetryOptions(args) {
67
+ var _a, _b;
68
+ const { functionId, telemetry } = args;
69
+ return {
70
+ isEnabled: (_a = telemetry === null || telemetry === void 0 ? void 0 : telemetry.isEnabled) !== null && _a !== void 0 ? _a : true,
71
+ functionId,
72
+ integrations: getTelemetryIntegrations((_b = telemetry === null || telemetry === void 0 ? void 0 : telemetry.tracer) !== null && _b !== void 0 ? _b : exports.tracer),
73
+ };
74
+ }
58
75
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/telemetry/index.ts"],"names":[],"mappings":";;;;;AAAA,uCAA6C;AAC7C,4CAAwD;AAGxD,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAE5C;;;;;;GAMG;AACH,mBAA0B,IAAI,GAAW,mBAAmB;IAC1D,OAAO;QACL,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO;YAClC,OAAO,WAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACrE,CAA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
+ import type { DecisionModel } from "../utils/isDecisionModel";
3
3
  import type { ObjectMapping } from "./data";
4
4
  import type { WithTelemetry } from "./otel";
5
5
  import type { PromptTemplate } from "./templating";
@@ -15,10 +15,12 @@ export interface ExampleRecord<OutputType, InputType> {
15
15
  export interface WithLLM {
16
16
  /**
17
17
  * Either a regular AI SDK {@link LanguageModel}, or an AI SDK
18
- * {@link EvaluationModel} (e.g. TypeSafe's Jev) which classifies without
19
- * generating text and therefore cannot produce an explanation.
18
+ * {@link DecisionModel} (e.g. `openai.decisionModel("gpt-6-luna")`) which
19
+ * classifies without generating text and therefore cannot produce an
20
+ * explanation. With a decision model, label probabilities are returned in
21
+ * the result's `metadata.probabilities`.
20
22
  */
21
- model: LanguageModel | EvaluationModel;
23
+ model: LanguageModel | DecisionModel;
22
24
  }
23
25
  export interface LLMEvaluationArgs extends WithLLM {
24
26
  }
@@ -43,7 +45,7 @@ export interface EvaluationResult {
43
45
  explanation?: string;
44
46
  /**
45
47
  * Additional information about how the result was produced, e.g. the
46
- * label probabilities reported by an evaluation model.
48
+ * label probabilities reported by a decision model.
47
49
  */
48
50
  metadata?: Record<string, unknown>;
49
51
  }
@@ -70,7 +72,7 @@ export type ClassificationChoicesMap = Record<string, number>;
70
72
  * The arguments for creating a classification-based evaluator
71
73
  */
72
74
  export interface CreateClassifierArgs extends WithTelemetry {
73
- model: LanguageModel | EvaluationModel;
75
+ model: LanguageModel | DecisionModel;
74
76
  /**
75
77
  * The choices to classify the example into.
76
78
  * e.g. { "correct": 1, "incorrect": 0 }
@@ -1 +1 @@
1
- {"version":3,"file":"evals.d.ts","sourceRoot":"","sources":["../../../src/types/evals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,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AW,KACd,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;AAExE;;GAEG;AACH,UAAU,oBAAoB;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,cAAc,CAAC;IACrB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CACjC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3C,SAAQ,oBAAoB;IAC5B;;OAEG;IACH,QAAQ,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;CACpC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./bindEvaluator";
2
+ export * from "./isDecisionModel";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}