@arizeai/phoenix-evals 2.5.0 → 2.6.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.
- package/CHANGELOG.md +6 -0
- package/dist/esm/llm/ClassificationEvaluator.d.ts +2 -1
- package/dist/esm/llm/ClassificationEvaluator.d.ts.map +1 -1
- package/dist/esm/llm/ClassificationEvaluator.js.map +1 -1
- package/dist/esm/llm/generateClassification.d.ts +6 -0
- package/dist/esm/llm/generateClassification.d.ts.map +1 -1
- package/dist/esm/llm/generateClassification.js +66 -1
- package/dist/esm/llm/generateClassification.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/evals.d.ts +14 -2
- package/dist/esm/types/evals.d.ts.map +1 -1
- package/dist/esm/utils/isEvaluationModel.d.ts +13 -0
- package/dist/esm/utils/isEvaluationModel.d.ts.map +1 -0
- package/dist/esm/utils/isEvaluationModel.js +11 -0
- package/dist/esm/utils/isEvaluationModel.js.map +1 -0
- package/dist/src/llm/ClassificationEvaluator.d.ts +2 -1
- package/dist/src/llm/ClassificationEvaluator.d.ts.map +1 -1
- package/dist/src/llm/ClassificationEvaluator.js.map +1 -1
- package/dist/src/llm/generateClassification.d.ts +6 -0
- package/dist/src/llm/generateClassification.d.ts.map +1 -1
- package/dist/src/llm/generateClassification.js +65 -0
- package/dist/src/llm/generateClassification.js.map +1 -1
- package/dist/src/types/evals.d.ts +14 -2
- package/dist/src/types/evals.d.ts.map +1 -1
- package/dist/src/utils/isEvaluationModel.d.ts +13 -0
- package/dist/src/utils/isEvaluationModel.d.ts.map +1 -0
- package/dist/src/utils/isEvaluationModel.js +14 -0
- package/dist/src/utils/isEvaluationModel.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -10
- package/src/llm/ClassificationEvaluator.ts +2 -1
- package/src/llm/generateClassification.ts +78 -1
- package/src/types/evals.ts +15 -3
- package/src/utils/isEvaluationModel.ts +23 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @arizeai/phoenix-evals
|
|
2
2
|
|
|
3
|
+
## 2.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b7b7dfb: Classification evaluators now accept AI SDK evaluation models such as TypeSafe's Jev. When an evaluation model is passed as `model`, the classification is routed through `experimental_evaluate` as a single choice question instead of `generateObject`. Results carry a `label` and `score` but no `explanation`, since evaluation models do not generate text.
|
|
8
|
+
|
|
3
9
|
## 2.5.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LanguageModel } from "ai";
|
|
2
2
|
import type { ClassificationChoicesMap, CreateClassificationEvaluatorArgs, EvaluatorFn, PromptTemplate, WithPromptTemplate } from "../types/index.js";
|
|
3
3
|
import type { ObjectMapping } from "../types/data.js";
|
|
4
|
+
import type { EvaluationModel } from "../utils/isEvaluationModel.js";
|
|
4
5
|
import { LLMEvaluator } from "./LLMEvaluator.js";
|
|
5
6
|
/**
|
|
6
7
|
* An LLM evaluator that performs evaluation via classification
|
|
@@ -15,7 +16,7 @@ export declare class ClassificationEvaluator<RecordType extends Record<string, u
|
|
|
15
16
|
/**
|
|
16
17
|
* The model to use for classification
|
|
17
18
|
*/
|
|
18
|
-
readonly model: LanguageModel;
|
|
19
|
+
readonly model: LanguageModel | EvaluationModel;
|
|
19
20
|
/**
|
|
20
21
|
* The choices to classify the example into
|
|
21
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;
|
|
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,4CAM7B;IACF;;OAEG;IACH,IAAI,uBAAuB,IAAI,MAAM,EAAE,CAStC;IACD;;OAEG;IACH,gBAAgB,CACd,YAAY,EAAE,aAAa,CAAC,UAAU,CAAC,GACtC,uBAAuB,CAAC,UAAU,CAAC,CAKrC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAUnD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,uBACX,SAAQ,YAAwB;IAGvB,WAAW,CAA0B;IACrC,cAAc,CAAiB;IACxC;;OAEG;IACK,wBAAwB,CAAuB;IACvD;;OAEG;IACM,KAAK,CAAkC;IAChD;;OAEG;IACM,OAAO,CAA2B;IAE3C,YAAY,IAAmD;QAC7D,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,kBAAkB,CAAa;YAChD,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC;IACD,QAAQ,GAAG,CAAC,OAAmB,EAAE,EAAE;QACjC,OAAO,IAAI,CAAC,WAAW,CACrB,IAAI,CAAC,YAAY;YACf,CAAC,CAAC,WAAW,CAAa,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC;YACrD,CAAC,CAAC,OAAO,CACZ,CAAC;IACJ,CAAC,CAAC;IACF;;OAEG;IACH,IAAI,uBAAuB;QACzB,0DAA0D;QAC1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,wBAAwB,GAAG,oBAAoB,CAAC;gBACnD,QAAQ,EAAE,IAAI,CAAC,cAAc;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,+BAA+B;QAC/B,OAAO,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IACD;;OAEG;IACH,gBAAgB,CACd,YAAuC;QAEvC,OAAO,IAAI,uBAAuB,CAAC;YACjC,GAAG,IAAI;YACP,YAAY;SACb,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -17,6 +17,12 @@ export type ClassifyArgs = WithLLM & WithTelemetry & WithPrompt & {
|
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* A function that leverages an llm to perform a classification
|
|
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.
|
|
20
26
|
*/
|
|
21
27
|
export declare function generateClassification(args: ClassifyArgs): Promise<ClassificationResult>;
|
|
22
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;
|
|
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,11 +1,21 @@
|
|
|
1
|
-
import { generateObject } from "ai";
|
|
1
|
+
import { experimental_evaluate, generateObject } from "ai";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { getTelemetryIntegrations, tracer } from "../telemetry/index.js";
|
|
4
|
+
import { isEvaluationModel, } from "../utils/isEvaluationModel.js";
|
|
4
5
|
/**
|
|
5
6
|
* A function that leverages an llm to perform a classification
|
|
7
|
+
*
|
|
8
|
+
* When given an AI SDK evaluation model (e.g. TypeSafe's Jev) the
|
|
9
|
+
* classification is routed through `experimental_evaluate` as a single
|
|
10
|
+
* choice question. Evaluation models cannot generate text, so no explanation
|
|
11
|
+
* is returned in that case. `telemetry`, `schemaName` and `schemaDescription`
|
|
12
|
+
* are ignored on that path: `experimental_evaluate` does not emit spans yet.
|
|
6
13
|
*/
|
|
7
14
|
export async function generateClassification(args) {
|
|
8
15
|
const { labels, model, schemaName, schemaDescription, telemetry, ...prompt } = args;
|
|
16
|
+
if (isEvaluationModel(model)) {
|
|
17
|
+
return evaluateClassification({ model, labels, prompt });
|
|
18
|
+
}
|
|
9
19
|
const telemetryOptions = {
|
|
10
20
|
isEnabled: telemetry?.isEnabled ?? true,
|
|
11
21
|
functionId: "generateClassification",
|
|
@@ -30,4 +40,59 @@ export async function generateClassification(args) {
|
|
|
30
40
|
explanation: result.object.explanation,
|
|
31
41
|
};
|
|
32
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Classify using an AI SDK evaluation model. The rendered prompt becomes the
|
|
45
|
+
* shared evaluation state and the labels become the options of one choice
|
|
46
|
+
* question. The model's label probabilities and resolved model id are
|
|
47
|
+
* returned as metadata.
|
|
48
|
+
*/
|
|
49
|
+
async function evaluateClassification(args) {
|
|
50
|
+
const { model, labels, prompt } = args;
|
|
51
|
+
const result = await experimental_evaluate({
|
|
52
|
+
model,
|
|
53
|
+
state: toEvaluationState(prompt),
|
|
54
|
+
questions: {
|
|
55
|
+
label: {
|
|
56
|
+
type: "choice",
|
|
57
|
+
instructions: "Read the prompt in the state and answer it by selecting exactly one of the choices.",
|
|
58
|
+
criteria: Object.fromEntries(labels.map((label) => [label, null])),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const answer = result.answers.label;
|
|
63
|
+
return {
|
|
64
|
+
label: answer.choice,
|
|
65
|
+
metadata: {
|
|
66
|
+
probabilities: answer.probabilities,
|
|
67
|
+
modelId: result.response.modelId,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert an AI SDK prompt into JSON-compatible evaluation state.
|
|
73
|
+
* A bare text prompt is passed through as a string; anything else
|
|
74
|
+
* (instructions, system messages, message arrays) is serialized to JSON.
|
|
75
|
+
*/
|
|
76
|
+
function toEvaluationState(prompt) {
|
|
77
|
+
const { instructions, system, messages, prompt: promptContent } = prompt;
|
|
78
|
+
if (typeof promptContent === "string" &&
|
|
79
|
+
instructions === undefined &&
|
|
80
|
+
system === undefined &&
|
|
81
|
+
messages === undefined) {
|
|
82
|
+
return promptContent;
|
|
83
|
+
}
|
|
84
|
+
const state = {};
|
|
85
|
+
if (instructions !== undefined)
|
|
86
|
+
state.instructions = instructions;
|
|
87
|
+
if (system !== undefined)
|
|
88
|
+
state.system = system;
|
|
89
|
+
if (promptContent !== undefined)
|
|
90
|
+
state.prompt = promptContent;
|
|
91
|
+
if (messages !== undefined)
|
|
92
|
+
state.messages = messages;
|
|
93
|
+
// Round-trip through JSON so the state only contains JSON values
|
|
94
|
+
// (strips `undefined`, turns Date/URL into strings). Binary file parts
|
|
95
|
+
// are not supported by evaluation models and are not stripped here.
|
|
96
|
+
return JSON.parse(JSON.stringify(state));
|
|
97
|
+
}
|
|
33
98
|
//# sourceMappingURL=generateClassification.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AAC3D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAIhE,OAAO,EAEL,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAkBpC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAAkB;IAElB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAC1E,IAAI,CAAC;IAEP,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,sBAAsB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,gBA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