@arizeai/phoenix-evals 1.2.0 → 2.0.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/README.md +2 -0
- package/dist/esm/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts +3 -0
- package/dist/esm/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts.map +1 -0
- package/dist/esm/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js +61 -0
- package/dist/esm/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js.map +1 -0
- package/dist/esm/__generated__/default_templates/index.d.ts +1 -0
- package/dist/esm/__generated__/default_templates/index.d.ts.map +1 -1
- package/dist/esm/__generated__/default_templates/index.js +1 -0
- package/dist/esm/__generated__/default_templates/index.js.map +1 -1
- package/dist/esm/llm/createUserFrictionEvaluator.d.ts +48 -0
- package/dist/esm/llm/createUserFrictionEvaluator.d.ts.map +1 -0
- package/dist/esm/llm/createUserFrictionEvaluator.js +39 -0
- package/dist/esm/llm/createUserFrictionEvaluator.js.map +1 -0
- package/dist/esm/llm/generateClassification.d.ts.map +1 -1
- package/dist/esm/llm/generateClassification.js +7 -4
- package/dist/esm/llm/generateClassification.js.map +1 -1
- package/dist/esm/llm/index.d.ts +1 -0
- package/dist/esm/llm/index.d.ts.map +1 -1
- package/dist/esm/llm/index.js +1 -0
- package/dist/esm/llm/index.js.map +1 -1
- package/dist/esm/telemetry/index.d.ts +10 -0
- package/dist/esm/telemetry/index.d.ts.map +1 -1
- package/dist/esm/telemetry/index.js +30 -0
- package/dist/esm/telemetry/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/src/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts +3 -0
- package/dist/src/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts.map +1 -0
- package/dist/src/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js +64 -0
- package/dist/src/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js.map +1 -0
- package/dist/src/__generated__/default_templates/index.d.ts +1 -0
- package/dist/src/__generated__/default_templates/index.d.ts.map +1 -1
- package/dist/src/__generated__/default_templates/index.js +3 -1
- package/dist/src/__generated__/default_templates/index.js.map +1 -1
- package/dist/src/llm/createUserFrictionEvaluator.d.ts +48 -0
- package/dist/src/llm/createUserFrictionEvaluator.d.ts.map +1 -0
- package/dist/src/llm/createUserFrictionEvaluator.js +50 -0
- package/dist/src/llm/createUserFrictionEvaluator.js.map +1 -0
- package/dist/src/llm/generateClassification.d.ts.map +1 -1
- package/dist/src/llm/generateClassification.js +6 -3
- package/dist/src/llm/generateClassification.js.map +1 -1
- package/dist/src/llm/index.d.ts +1 -0
- package/dist/src/llm/index.d.ts.map +1 -1
- package/dist/src/llm/index.js +1 -0
- package/dist/src/llm/index.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +10 -0
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/index.js +32 -0
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/overview.mdx +2 -2
- package/package.json +7 -6
- package/src/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.ts +63 -0
- package/src/__generated__/default_templates/index.ts +1 -0
- package/src/llm/createUserFrictionEvaluator.ts +76 -0
- package/src/llm/generateClassification.ts +7 -4
- package/src/llm/index.ts +1 -0
- package/src/telemetry/index.ts +36 -0
package/README.md
CHANGED
|
@@ -31,6 +31,8 @@ This package provides a TypeScript evaluation library. It is vendor agnostic and
|
|
|
31
31
|
npm install @arizeai/phoenix-evals
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
This package is built on [AI SDK](https://ai-sdk.dev/) v7, which is ESM-only. Node.js 22.12 or newer is required (the CommonJS build relies on `require()` of ESM). Use AI SDK v7-compatible model provider packages (e.g. `@ai-sdk/openai` v4+).
|
|
35
|
+
|
|
34
36
|
## Usage
|
|
35
37
|
|
|
36
38
|
### Creating a Classifier
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.d.ts","sourceRoot":"","sources":["../../../../src/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AAE9D,eAAO,MAAM,6CAA6C,EAAE,6BA0D3D,CAAC"}
|
package/dist/esm/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// This file is generated. Do not edit by hand.
|
|
2
|
+
export const USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG = {
|
|
3
|
+
name: "user_friction",
|
|
4
|
+
description: "Assess whether a user message expresses friction with an assistant's preceding behavior.",
|
|
5
|
+
optimizationDirection: "MINIMIZE",
|
|
6
|
+
template: [
|
|
7
|
+
{
|
|
8
|
+
role: "user",
|
|
9
|
+
content: `
|
|
10
|
+
You are an expert evaluator labeling whether the latest user message expresses friction with an AI assistant's preceding behavior.
|
|
11
|
+
|
|
12
|
+
<rubric>
|
|
13
|
+
|
|
14
|
+
FRICTION - The latest user message contains one or more of these signals directed at the assistant's preceding behavior:
|
|
15
|
+
|
|
16
|
+
- Correction: redirects or contradicts the assistant, identifies that it misunderstood, or asks it to undo, stop, or revert an action it took on its own initiative. Stopping or cancelling work the user themselves requested is not friction unless dissatisfaction is also expressed. Repeating or re-asserting an instruction or constraint the user already gave, after the assistant failed to follow it, is a correction
|
|
17
|
+
- Retry: repeats or rephrases an earlier request because the assistant failed, errored, returned nothing useful, or did not complete it
|
|
18
|
+
- Frustration: expresses negative affect about the assistant's behavior, such as annoyance, impatience, or disappointment
|
|
19
|
+
- Challenge: questions an action the assistant took or announced that was unrequested, unexplained, or inappropriate. A neutral question about why the assistant gave a recommendation or answer is not a challenge by itself, but asking why the assistant did not take a specific alternative the user implies was better ("why didn't you use X instead?") is a challenge. Asking why the assistant presented a recommendation as the best, current, or only suitable option is also a challenge; merely asking for rationale or a comparison is not
|
|
20
|
+
|
|
21
|
+
NO_FRICTION - The latest user message does not express friction with the assistant. This includes:
|
|
22
|
+
|
|
23
|
+
- A direct answer to a question or request for information from the assistant, even if the answer is terse or negative, such as "no", "skip", or "the second one"
|
|
24
|
+
- A follow-up, refinement, or new constraint that builds on the preceding response without indicating it was wrong or unsatisfactory
|
|
25
|
+
- A topic switch or new task
|
|
26
|
+
- Acceptance or rejection of an optional proposal. Commands such as "don't do that" are no_friction when they directly answer whether the assistant should do it
|
|
27
|
+
- Gratitude, greetings, acknowledgements, or other ordinary conversation
|
|
28
|
+
- A changed preference that does not imply the assistant made an error
|
|
29
|
+
- Curiosity or verification about a delivered answer, recommendation, or reasoning rather than a challenge to an action the assistant took. Requests for evidence or skeptical questions about a claim remain no_friction unless the user explicitly says the answer is wrong, fabricated, or unacceptable
|
|
30
|
+
- A first user message with no preceding assistant behavior to react to
|
|
31
|
+
|
|
32
|
+
Judge only expressed friction. Do not infer dissatisfaction from silence, brevity, negative words alone, or the fact that the user asks for additional work. A genuine friction signal still counts when combined with praise or a new request.
|
|
33
|
+
|
|
34
|
+
Apply the no_friction cases before interpreting terse or negative wording as friction. A direct answer to an assistant question or optional proposal remains no_friction unless the user also explicitly indicates that the assistant misunderstood, failed, or acted improperly. A negative answer followed by a replacement instruction is friction only when it corrects a completed response to the same request; it remains no_friction when answering a question or declining a proposal.
|
|
35
|
+
|
|
36
|
+
When the evidence supports both labels or remains ambiguous, choose no_friction. Precision on the friction label is more important than recall.
|
|
37
|
+
|
|
38
|
+
</rubric>
|
|
39
|
+
|
|
40
|
+
<data>
|
|
41
|
+
|
|
42
|
+
<conversation_before_user_message>
|
|
43
|
+
{{conversation}}
|
|
44
|
+
</conversation_before_user_message>
|
|
45
|
+
|
|
46
|
+
<latest_user_message>
|
|
47
|
+
{{userMessage}}
|
|
48
|
+
</latest_user_message>
|
|
49
|
+
|
|
50
|
+
</data>
|
|
51
|
+
|
|
52
|
+
Reason through whether the latest user message reacts negatively to the assistant's preceding behavior. Then classify it as friction or no_friction.
|
|
53
|
+
`,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
choices: {
|
|
57
|
+
"friction": 1,
|
|
58
|
+
"no_friction": 0
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js","sourceRoot":"","sources":["../../../../src/__generated__/default_templates/USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAI/C,MAAM,CAAC,MAAM,6CAA6C,GAAkC;IAC1F,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,0FAA0F;IACvG,qBAAqB,EAAE,UAAU;IACjC,QAAQ,EAAE;QACR;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Cd;SACI;KACF;IACD,OAAO,EAAE;QACT,UAAU,EAAE,CAAC;QACb,aAAa,EAAE,CAAC;KACjB;CACA,CAAC"}
|
|
@@ -7,4 +7,5 @@ export { REFUSAL_CLASSIFICATION_EVALUATOR_CONFIG } from "./REFUSAL_CLASSIFICATIO
|
|
|
7
7
|
export { TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG } from "./TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.js";
|
|
8
8
|
export { TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG } from "./TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.js";
|
|
9
9
|
export { TOOL_SELECTION_CLASSIFICATION_EVALUATOR_CONFIG } from "./TOOL_SELECTION_CLASSIFICATION_EVALUATOR_CONFIG.js";
|
|
10
|
+
export { USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG } from "./USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js";
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/__generated__/default_templates/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2CAA2C,EAAE,MAAM,+CAA+C,CAAC;AAC5G,OAAO,EAAE,2CAA2C,EAAE,MAAM,+CAA+C,CAAC;AAC5G,OAAO,EAAE,kDAAkD,EAAE,MAAM,sDAAsD,CAAC;AAC1H,OAAO,EAAE,4CAA4C,EAAE,MAAM,gDAAgD,CAAC;AAC9G,OAAO,EAAE,6CAA6C,EAAE,MAAM,iDAAiD,CAAC;AAChH,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,+CAA+C,EAAE,MAAM,mDAAmD,CAAC;AACpH,OAAO,EAAE,sDAAsD,EAAE,MAAM,0DAA0D,CAAC;AAClI,OAAO,EAAE,8CAA8C,EAAE,MAAM,kDAAkD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/__generated__/default_templates/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2CAA2C,EAAE,MAAM,+CAA+C,CAAC;AAC5G,OAAO,EAAE,2CAA2C,EAAE,MAAM,+CAA+C,CAAC;AAC5G,OAAO,EAAE,kDAAkD,EAAE,MAAM,sDAAsD,CAAC;AAC1H,OAAO,EAAE,4CAA4C,EAAE,MAAM,gDAAgD,CAAC;AAC9G,OAAO,EAAE,6CAA6C,EAAE,MAAM,iDAAiD,CAAC;AAChH,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,+CAA+C,EAAE,MAAM,mDAAmD,CAAC;AACpH,OAAO,EAAE,sDAAsD,EAAE,MAAM,0DAA0D,CAAC;AAClI,OAAO,EAAE,8CAA8C,EAAE,MAAM,kDAAkD,CAAC;AAClH,OAAO,EAAE,6CAA6C,EAAE,MAAM,iDAAiD,CAAC"}
|
|
@@ -8,4 +8,5 @@ export { REFUSAL_CLASSIFICATION_EVALUATOR_CONFIG } from "./REFUSAL_CLASSIFICATIO
|
|
|
8
8
|
export { TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG } from "./TOOL_INVOCATION_CLASSIFICATION_EVALUATOR_CONFIG.js";
|
|
9
9
|
export { TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG } from "./TOOL_RESPONSE_HANDLING_CLASSIFICATION_EVALUATOR_CONFIG.js";
|
|
10
10
|
export { TOOL_SELECTION_CLASSIFICATION_EVALUATOR_CONFIG } from "./TOOL_SELECTION_CLASSIFICATION_EVALUATOR_CONFIG.js";
|
|
11
|
+
export { USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG } from "./USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.js";
|
|
11
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/__generated__/default_templates/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,OAAO,EAAE,2CAA2C,EAAE,MAAM,+CAA+C,CAAC;AAC5G,OAAO,EAAE,2CAA2C,EAAE,MAAM,+CAA+C,CAAC;AAC5G,OAAO,EAAE,kDAAkD,EAAE,MAAM,sDAAsD,CAAC;AAC1H,OAAO,EAAE,4CAA4C,EAAE,MAAM,gDAAgD,CAAC;AAC9G,OAAO,EAAE,6CAA6C,EAAE,MAAM,iDAAiD,CAAC;AAChH,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,+CAA+C,EAAE,MAAM,mDAAmD,CAAC;AACpH,OAAO,EAAE,sDAAsD,EAAE,MAAM,0DAA0D,CAAC;AAClI,OAAO,EAAE,8CAA8C,EAAE,MAAM,kDAAkD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/__generated__/default_templates/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,OAAO,EAAE,2CAA2C,EAAE,MAAM,+CAA+C,CAAC;AAC5G,OAAO,EAAE,2CAA2C,EAAE,MAAM,+CAA+C,CAAC;AAC5G,OAAO,EAAE,kDAAkD,EAAE,MAAM,sDAAsD,CAAC;AAC1H,OAAO,EAAE,4CAA4C,EAAE,MAAM,gDAAgD,CAAC;AAC9G,OAAO,EAAE,6CAA6C,EAAE,MAAM,iDAAiD,CAAC;AAChH,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,+CAA+C,EAAE,MAAM,mDAAmD,CAAC;AACpH,OAAO,EAAE,sDAAsD,EAAE,MAAM,0DAA0D,CAAC;AAClI,OAAO,EAAE,8CAA8C,EAAE,MAAM,kDAAkD,CAAC;AAClH,OAAO,EAAE,6CAA6C,EAAE,MAAM,iDAAiD,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CreateClassificationEvaluatorArgs } from "../types/evals.js";
|
|
2
|
+
import type { ClassificationEvaluator } from "./ClassificationEvaluator.js";
|
|
3
|
+
export interface UserFrictionEvaluatorArgs<RecordType extends Record<string, unknown> = UserFrictionEvaluationRecord> 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
|
+
/** A conversation and the latest user message to evaluate for expressed friction. */
|
|
10
|
+
export interface UserFrictionEvaluationRecord {
|
|
11
|
+
/**
|
|
12
|
+
* Human-readable conversation history before the target user message.
|
|
13
|
+
*/
|
|
14
|
+
conversation: string;
|
|
15
|
+
/**
|
|
16
|
+
* The latest user message to classify for expressed friction.
|
|
17
|
+
*/
|
|
18
|
+
userMessage: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a user friction evaluator function.
|
|
23
|
+
*
|
|
24
|
+
* This function returns an evaluator that detects expressed user friction
|
|
25
|
+
* with an assistant's preceding behavior, such as corrections, retries,
|
|
26
|
+
* frustration, and challenges to unrequested or unexplained actions.
|
|
27
|
+
*
|
|
28
|
+
* @param args - The arguments for creating the user friction evaluator.
|
|
29
|
+
* @param args.model - The model to use for classification.
|
|
30
|
+
* @param args.choices - The possible classification choices (defaults to friction/no_friction).
|
|
31
|
+
* @param args.promptTemplate - The prompt template to use (defaults to USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.template).
|
|
32
|
+
* @param args.telemetry - The telemetry to use for the evaluator.
|
|
33
|
+
*
|
|
34
|
+
* @returns An evaluator function that takes a {@link UserFrictionEvaluationRecord} and returns a classification result
|
|
35
|
+
* indicating whether the latest user message expresses friction or no friction.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const evaluator = createUserFrictionEvaluator({ model: openai("gpt-4o-mini") });
|
|
40
|
+
* const result = await evaluator.evaluate({
|
|
41
|
+
* conversation: "User: Show recent orders.\nAssistant: Here are last month's orders.",
|
|
42
|
+
* userMessage: "No, I asked for this week.",
|
|
43
|
+
* });
|
|
44
|
+
* console.log(result.label); // "friction"
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function createUserFrictionEvaluator<RecordType extends Record<string, unknown> = UserFrictionEvaluationRecord>(args: UserFrictionEvaluatorArgs<RecordType>): ClassificationEvaluator<RecordType>;
|
|
48
|
+
//# sourceMappingURL=createUserFrictionEvaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createUserFrictionEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/createUserFrictionEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAGzE,MAAM,WAAW,yBAAyB,CACxC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,4BAA4B,CACzE,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,qFAAqF;AACrF,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,4BAA4B,EAEzE,IAAI,EAAE,yBAAyB,CAAC,UAAU,CAAC,GAC1C,uBAAuB,CAAC,UAAU,CAAC,CAerC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG } from "../__generated__/default_templates/index.js";
|
|
2
|
+
import { createClassificationEvaluator } from "./createClassificationEvaluator.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a user friction evaluator function.
|
|
5
|
+
*
|
|
6
|
+
* This function returns an evaluator that detects expressed user friction
|
|
7
|
+
* with an assistant's preceding behavior, such as corrections, retries,
|
|
8
|
+
* frustration, and challenges to unrequested or unexplained actions.
|
|
9
|
+
*
|
|
10
|
+
* @param args - The arguments for creating the user friction evaluator.
|
|
11
|
+
* @param args.model - The model to use for classification.
|
|
12
|
+
* @param args.choices - The possible classification choices (defaults to friction/no_friction).
|
|
13
|
+
* @param args.promptTemplate - The prompt template to use (defaults to USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.template).
|
|
14
|
+
* @param args.telemetry - The telemetry to use for the evaluator.
|
|
15
|
+
*
|
|
16
|
+
* @returns An evaluator function that takes a {@link UserFrictionEvaluationRecord} and returns a classification result
|
|
17
|
+
* indicating whether the latest user message expresses friction or no friction.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const evaluator = createUserFrictionEvaluator({ model: openai("gpt-4o-mini") });
|
|
22
|
+
* const result = await evaluator.evaluate({
|
|
23
|
+
* conversation: "User: Show recent orders.\nAssistant: Here are last month's orders.",
|
|
24
|
+
* userMessage: "No, I asked for this week.",
|
|
25
|
+
* });
|
|
26
|
+
* console.log(result.label); // "friction"
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function createUserFrictionEvaluator(args) {
|
|
30
|
+
const { choices = USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.choices, promptTemplate = USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.template, optimizationDirection = USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.optimizationDirection, name = USER_FRICTION_CLASSIFICATION_EVALUATOR_CONFIG.name, ...rest } = args;
|
|
31
|
+
return createClassificationEvaluator({
|
|
32
|
+
...rest,
|
|
33
|
+
promptTemplate,
|
|
34
|
+
choices,
|
|
35
|
+
optimizationDirection,
|
|
36
|
+
name,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=createUserFrictionEvaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createUserFrictionEvaluator.js","sourceRoot":"","sources":["../../../src/llm/createUserFrictionEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6CAA6C,EAAE,MAAM,oCAAoC,CAAC;AAGnG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AA2BhF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,2BAA2B,CAGzC,IAA2C;IAE3C,MAAM,EACJ,OAAO,GAAG,6CAA6C,CAAC,OAAO,EAC/D,cAAc,GAAG,6CAA6C,CAAC,QAAQ,EACvE,qBAAqB,GAAG,6CAA6C,CAAC,qBAAqB,EAC3F,IAAI,GAAG,6CAA6C,CAAC,IAAI,EACzD,GAAG,IAAI,EACR,GAAG,IAAI,CAAC;IACT,OAAO,6BAA6B,CAAa;QAC/C,GAAG,IAAI;QACP,cAAc;QACd,OAAO;QACP,qBAAqB;QACrB,IAAI;KACL,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -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;AACnD,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;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,oBAAoB,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;AACnD,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;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,oBAAoB,CAAC,CA4B/B"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { generateObject } from "ai";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { tracer } from "../telemetry/index.js";
|
|
3
|
+
import { getTelemetryIntegrations, tracer } from "../telemetry/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* A function that leverages an llm to perform a classification
|
|
6
6
|
*/
|
|
7
7
|
export async function generateClassification(args) {
|
|
8
8
|
const { labels, model, schemaName, schemaDescription, telemetry, ...prompt } = args;
|
|
9
|
-
const
|
|
9
|
+
const telemetryOptions = {
|
|
10
10
|
isEnabled: telemetry?.isEnabled ?? true,
|
|
11
11
|
functionId: "generateClassification",
|
|
12
|
-
|
|
12
|
+
integrations: getTelemetryIntegrations(telemetry?.tracer ?? tracer),
|
|
13
13
|
};
|
|
14
14
|
const result = await generateObject({
|
|
15
15
|
model,
|
|
@@ -19,7 +19,10 @@ export async function generateClassification(args) {
|
|
|
19
19
|
explanation: z.string(), // We place the explanation in hopes it uses reasoning to explain the label.
|
|
20
20
|
label: z.enum(labels),
|
|
21
21
|
}),
|
|
22
|
-
|
|
22
|
+
telemetry: telemetryOptions,
|
|
23
|
+
// AI SDK 7 rejects system messages inside `messages` by default; keep
|
|
24
|
+
// accepting them since prompt templates may include system messages.
|
|
25
|
+
allowSystemInMessages: true,
|
|
23
26
|
...prompt,
|
|
24
27
|
});
|
|
25
28
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"generateClassification.js","sourceRoot":"","sources":["../../../src/llm/generateClassification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAoBhE;;GAEG;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,MAAM,gBAAgB,GAAG;QACvB,SAAS,EAAE,SAAS,EAAE,SAAS,IAAI,IAAI;QACvC,UAAU,EAAE,wBAAwB;QACpC,YAAY,EAAE,wBAAwB,CAAC,SAAS,EAAE,MAAM,IAAI,MAAM,CAAC;KACpE,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC;QAClC,KAAK;QACL,UAAU;QACV,iBAAiB;QACjB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,4EAA4E;YACrG,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;SACtB,CAAC;QACF,SAAS,EAAE,gBAAgB;QAC3B,sEAAsE;QACtE,qEAAqE;QACrE,qBAAqB,EAAE,IAAI;QAC3B,GAAG,MAAM;KACV,CAAC,CAAC;IACH,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;QAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW;KACvC,CAAC;AACJ,CAAC"}
|
package/dist/esm/llm/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./createRefusalEvaluator.js";
|
|
|
10
10
|
export * from "./createToolInvocationEvaluator.js";
|
|
11
11
|
export * from "./createToolResponseHandlingEvaluator.js";
|
|
12
12
|
export * from "./createToolSelectionEvaluator.js";
|
|
13
|
+
export * from "./createUserFrictionEvaluator.js";
|
|
13
14
|
export * from "./generateClassification.js";
|
|
14
15
|
export * from "./LLMEvaluator.js";
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,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,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC"}
|
package/dist/esm/llm/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./createRefusalEvaluator.js";
|
|
|
10
10
|
export * from "./createToolInvocationEvaluator.js";
|
|
11
11
|
export * from "./createToolResponseHandlingEvaluator.js";
|
|
12
12
|
export * from "./createToolSelectionEvaluator.js";
|
|
13
|
+
export * from "./createUserFrictionEvaluator.js";
|
|
13
14
|
export * from "./generateClassification.js";
|
|
14
15
|
export * from "./LLMEvaluator.js";
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC,CAAC,8CAA8C;AAC9F,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","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,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC,CAAC,8CAA8C;AAC9F,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Tracer } from "@opentelemetry/api";
|
|
2
|
+
import type { Telemetry } from "ai";
|
|
2
3
|
/**
|
|
3
4
|
* Returns a lazy tracer that resolves from `trace.getTracer()` on every call,
|
|
4
5
|
* so evaluator spans follow whichever provider is currently mounted as global.
|
|
@@ -8,4 +9,13 @@ import { type Tracer } from "@opentelemetry/api";
|
|
|
8
9
|
*/
|
|
9
10
|
export declare function getTracer(name?: string): Tracer;
|
|
10
11
|
export declare const tracer: Tracer;
|
|
12
|
+
/**
|
|
13
|
+
* Builds the AI SDK telemetry integrations for an evaluator call. Per-call
|
|
14
|
+
* `integrations` replace the SDK's globally registered ones, so the globals
|
|
15
|
+
* (application logging, metrics, tracing to other backends) are carried
|
|
16
|
+
* forward with a Phoenix tracing integration appended. If a global
|
|
17
|
+
* integration already traces with the same tracer instance, the globals are
|
|
18
|
+
* used as-is so the call is not traced twice.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getTelemetryIntegrations(integrationTracer: Tracer): Telemetry[];
|
|
11
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/telemetry/index.ts"],"names":[],"mappings":"
|
|
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,3 +1,4 @@
|
|
|
1
|
+
import { OpenTelemetry } from "@ai-sdk/otel";
|
|
1
2
|
import { trace } from "@opentelemetry/api";
|
|
2
3
|
const DEFAULT_TRACER_NAME = "phoenix-evals";
|
|
3
4
|
/**
|
|
@@ -19,4 +20,33 @@ export function getTracer(name = DEFAULT_TRACER_NAME) {
|
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
export const tracer = getTracer();
|
|
23
|
+
/**
|
|
24
|
+
* Builds the AI SDK telemetry integrations for an evaluator call. Per-call
|
|
25
|
+
* `integrations` replace the SDK's globally registered ones, so the globals
|
|
26
|
+
* (application logging, metrics, tracing to other backends) are carried
|
|
27
|
+
* forward with a Phoenix tracing integration appended. If a global
|
|
28
|
+
* integration already traces with the same tracer instance, the globals are
|
|
29
|
+
* used as-is so the call is not traced twice.
|
|
30
|
+
*/
|
|
31
|
+
export function getTelemetryIntegrations(integrationTracer) {
|
|
32
|
+
const globalIntegrations = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS ?? [];
|
|
33
|
+
const hasTracerIntegration = globalIntegrations.some(
|
|
34
|
+
// Duck-typed so integrations from a different copy of `@ai-sdk/otel`
|
|
35
|
+
// are still recognized.
|
|
36
|
+
(integration) => integration.tracer === integrationTracer);
|
|
37
|
+
if (hasTracerIntegration) {
|
|
38
|
+
return globalIntegrations;
|
|
39
|
+
}
|
|
40
|
+
return [
|
|
41
|
+
...globalIntegrations,
|
|
42
|
+
new OpenTelemetry({
|
|
43
|
+
tracer: integrationTracer,
|
|
44
|
+
// Supplemental AI SDK attributes recommended for fuller OpenInference
|
|
45
|
+
// coverage of generateObject calls.
|
|
46
|
+
usage: true,
|
|
47
|
+
providerMetadata: true,
|
|
48
|
+
schema: true,
|
|
49
|
+
}),
|
|
50
|
+
];
|
|
51
|
+
}
|
|
22
52
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAe,MAAM,oBAAoB,CAAC;AAGxD,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,IAAI,GAAW,mBAAmB;IAC1D,OAAO;QACL,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO;YAClC,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACrE,CAAC;QACD,eAAe,CAAC,GAAG,IAAe;YAChC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACrC,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7D,CAAC;KACQ,CAAC;AACd,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,iBAAyB;IAEzB,MAAM,kBAAkB,GAAG,UAAU,CAAC,6BAA6B,IAAI,EAAE,CAAC;IAC1E,MAAM,oBAAoB,GAAG,kBAAkB,CAAC,IAAI;IAClD,qEAAqE;IACrE,wBAAwB;IACxB,CAAC,WAAW,EAAE,EAAE,CACb,WAAoC,CAAC,MAAM,KAAK,iBAAiB,CACrE,CAAC;IACF,IAAI,oBAAoB,EAAE,CAAC;QACzB,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IACD,OAAO;QACL,GAAG,kBAAkB;QACrB,IAAI,aAAa,CAAC;YAChB,MAAM,EAAE,iBAAiB;YACzB,sEAAsE;YACtE,oCAAoC;YACpC,KAAK,EAAE,IAAI;YACX,gBAAgB,EAAE,IAAI;YACtB,MAAM,EAAE,IAAI;SACb,CAAC;KACH,CAAC;AACJ,CAAC"}
|