@assay-ai/ai-sdk 0.1.0-beta
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/LICENSE +21 -0
- package/dist/index.cjs +150 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +110 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.js +121 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Assay AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
fromGenerateText: () => fromGenerateText,
|
|
24
|
+
fromMessages: () => fromMessages,
|
|
25
|
+
fromStreamText: () => fromStreamText
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/adapter.ts
|
|
30
|
+
function fromGenerateText(result, input, options) {
|
|
31
|
+
const testCase = {
|
|
32
|
+
input,
|
|
33
|
+
actualOutput: result.text
|
|
34
|
+
};
|
|
35
|
+
if (result.usage?.totalTokens != null) {
|
|
36
|
+
testCase.tokenCost = result.usage.totalTokens;
|
|
37
|
+
}
|
|
38
|
+
if (options?.expectedOutput != null) {
|
|
39
|
+
testCase.expectedOutput = options.expectedOutput;
|
|
40
|
+
}
|
|
41
|
+
if (options?.context != null) {
|
|
42
|
+
testCase.context = options.context;
|
|
43
|
+
}
|
|
44
|
+
if (options?.retrievalContext != null) {
|
|
45
|
+
testCase.retrievalContext = options.retrievalContext;
|
|
46
|
+
}
|
|
47
|
+
if (options?.name != null) {
|
|
48
|
+
testCase.name = options.name;
|
|
49
|
+
}
|
|
50
|
+
if (options?.tags != null) {
|
|
51
|
+
testCase.tags = options.tags;
|
|
52
|
+
}
|
|
53
|
+
return testCase;
|
|
54
|
+
}
|
|
55
|
+
async function fromStreamText(result, input, options) {
|
|
56
|
+
const [text, usage] = await Promise.all([
|
|
57
|
+
Promise.resolve(result.text),
|
|
58
|
+
result.usage != null ? Promise.resolve(result.usage) : Promise.resolve(void 0)
|
|
59
|
+
]);
|
|
60
|
+
const testCase = {
|
|
61
|
+
input,
|
|
62
|
+
actualOutput: text
|
|
63
|
+
};
|
|
64
|
+
if (usage?.totalTokens != null) {
|
|
65
|
+
testCase.tokenCost = usage.totalTokens;
|
|
66
|
+
}
|
|
67
|
+
if (options?.expectedOutput != null) {
|
|
68
|
+
testCase.expectedOutput = options.expectedOutput;
|
|
69
|
+
}
|
|
70
|
+
if (options?.context != null) {
|
|
71
|
+
testCase.context = options.context;
|
|
72
|
+
}
|
|
73
|
+
if (options?.retrievalContext != null) {
|
|
74
|
+
testCase.retrievalContext = options.retrievalContext;
|
|
75
|
+
}
|
|
76
|
+
if (options?.name != null) {
|
|
77
|
+
testCase.name = options.name;
|
|
78
|
+
}
|
|
79
|
+
if (options?.tags != null) {
|
|
80
|
+
testCase.tags = options.tags;
|
|
81
|
+
}
|
|
82
|
+
return testCase;
|
|
83
|
+
}
|
|
84
|
+
function fromMessages(messages, options) {
|
|
85
|
+
if (messages.length === 0) {
|
|
86
|
+
throw new Error("fromMessages requires at least one message");
|
|
87
|
+
}
|
|
88
|
+
let lastUserMessage;
|
|
89
|
+
let lastAssistantMessage;
|
|
90
|
+
const contextParts = [];
|
|
91
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
92
|
+
const msg = messages[i];
|
|
93
|
+
if (msg.role === "assistant" && lastAssistantMessage == null) {
|
|
94
|
+
lastAssistantMessage = msg.content;
|
|
95
|
+
} else if (msg.role === "user" && lastUserMessage == null) {
|
|
96
|
+
lastUserMessage = msg.content;
|
|
97
|
+
}
|
|
98
|
+
if (lastUserMessage != null && lastAssistantMessage != null) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
let foundLastUser = false;
|
|
103
|
+
let foundLastAssistant = false;
|
|
104
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
105
|
+
const msg = messages[i];
|
|
106
|
+
if (msg.role === "user" && msg.content === lastUserMessage && !foundLastUser) {
|
|
107
|
+
foundLastUser = true;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (msg.role === "assistant" && msg.content === lastAssistantMessage && !foundLastAssistant) {
|
|
111
|
+
foundLastAssistant = true;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
contextParts.unshift(`[${msg.role}]: ${msg.content}`);
|
|
115
|
+
}
|
|
116
|
+
const input = lastUserMessage ?? messages[0]?.content ?? "";
|
|
117
|
+
const testCase = {
|
|
118
|
+
input
|
|
119
|
+
};
|
|
120
|
+
if (lastAssistantMessage != null) {
|
|
121
|
+
testCase.actualOutput = lastAssistantMessage;
|
|
122
|
+
}
|
|
123
|
+
const allContext = [
|
|
124
|
+
...contextParts.length > 0 ? contextParts : [],
|
|
125
|
+
...options?.context ?? []
|
|
126
|
+
];
|
|
127
|
+
if (allContext.length > 0) {
|
|
128
|
+
testCase.context = allContext;
|
|
129
|
+
}
|
|
130
|
+
if (options?.expectedOutput != null) {
|
|
131
|
+
testCase.expectedOutput = options.expectedOutput;
|
|
132
|
+
}
|
|
133
|
+
if (options?.retrievalContext != null) {
|
|
134
|
+
testCase.retrievalContext = options.retrievalContext;
|
|
135
|
+
}
|
|
136
|
+
if (options?.name != null) {
|
|
137
|
+
testCase.name = options.name;
|
|
138
|
+
}
|
|
139
|
+
if (options?.tags != null) {
|
|
140
|
+
testCase.tags = options.tags;
|
|
141
|
+
}
|
|
142
|
+
return testCase;
|
|
143
|
+
}
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
fromGenerateText,
|
|
147
|
+
fromMessages,
|
|
148
|
+
fromStreamText
|
|
149
|
+
});
|
|
150
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/adapter.ts"],"sourcesContent":["export { fromGenerateText, fromStreamText, fromMessages } from \"./adapter\";\n","import type { LLMTestCase } from \"@assay-ai/core\";\n\n/**\n * A duck-typed interface matching the result of `generateText()` from the\n * Vercel AI SDK. We use structural typing so users don't need to install\n * a specific version of the AI SDK.\n */\ninterface GenerateTextResultLike {\n text: string;\n usage?: {\n totalTokens?: number;\n promptTokens?: number;\n completionTokens?: number;\n };\n finishReason?: string;\n}\n\n/**\n * A duck-typed interface matching the result of `streamText()` from the\n * Vercel AI SDK. The `text` and `usage` properties may be promises that\n * resolve once the stream completes.\n */\ninterface StreamTextResultLike {\n text: Promise<string> | string;\n usage?:\n | Promise<{ totalTokens?: number; promptTokens?: number; completionTokens?: number }>\n | { totalTokens?: number; promptTokens?: number; completionTokens?: number };\n}\n\ninterface AdapterOptions {\n /** Expected output for comparison-based metrics. */\n expectedOutput?: string;\n /** Context passages for retrieval-based metrics (e.g., RAG). */\n context?: string[];\n /** Retrieved context for faithfulness/hallucination evaluation. */\n retrievalContext?: string[];\n /** Human-readable name for the test case. */\n name?: string;\n /** Tags for filtering/grouping test cases. */\n tags?: string[];\n}\n\n/**\n * Convert a `generateText()` result into an `LLMTestCase` for evaluation.\n *\n * @param result - The result from Vercel AI SDK's `generateText()`.\n * @param input - The original prompt/input that was sent to the model.\n * @param options - Additional fields for the test case.\n * @returns A fully populated `LLMTestCase`.\n *\n * @example\n * ```ts\n * import { generateText } from \"ai\";\n * import { fromGenerateText } from \"@assay-ai/ai-sdk\";\n *\n * const result = await generateText({ model, prompt: \"What is 2+2?\" });\n * const testCase = fromGenerateText(result, \"What is 2+2?\", {\n * expectedOutput: \"4\",\n * });\n * ```\n */\nexport function fromGenerateText(\n result: GenerateTextResultLike,\n input: string,\n options?: AdapterOptions,\n): LLMTestCase {\n const testCase: LLMTestCase = {\n input,\n actualOutput: result.text,\n };\n\n if (result.usage?.totalTokens != null) {\n testCase.tokenCost = result.usage.totalTokens;\n }\n\n if (options?.expectedOutput != null) {\n testCase.expectedOutput = options.expectedOutput;\n }\n if (options?.context != null) {\n testCase.context = options.context;\n }\n if (options?.retrievalContext != null) {\n testCase.retrievalContext = options.retrievalContext;\n }\n if (options?.name != null) {\n testCase.name = options.name;\n }\n if (options?.tags != null) {\n testCase.tags = options.tags;\n }\n\n return testCase;\n}\n\n/**\n * Convert a `streamText()` result into an `LLMTestCase` for evaluation.\n * This awaits the streamed text and usage before building the test case.\n *\n * @param result - The result from Vercel AI SDK's `streamText()`.\n * @param input - The original prompt/input that was sent to the model.\n * @param options - Additional fields for the test case.\n * @returns A promise that resolves to a fully populated `LLMTestCase`.\n *\n * @example\n * ```ts\n * import { streamText } from \"ai\";\n * import { fromStreamText } from \"@assay-ai/ai-sdk\";\n *\n * const result = streamText({ model, prompt: \"Explain gravity.\" });\n * const testCase = await fromStreamText(result, \"Explain gravity.\");\n * ```\n */\nexport async function fromStreamText(\n result: StreamTextResultLike,\n input: string,\n options?: AdapterOptions,\n): Promise<LLMTestCase> {\n const [text, usage] = await Promise.all([\n Promise.resolve(result.text),\n result.usage != null ? Promise.resolve(result.usage) : Promise.resolve(undefined),\n ]);\n\n const testCase: LLMTestCase = {\n input,\n actualOutput: text,\n };\n\n if (usage?.totalTokens != null) {\n testCase.tokenCost = usage.totalTokens;\n }\n\n if (options?.expectedOutput != null) {\n testCase.expectedOutput = options.expectedOutput;\n }\n if (options?.context != null) {\n testCase.context = options.context;\n }\n if (options?.retrievalContext != null) {\n testCase.retrievalContext = options.retrievalContext;\n }\n if (options?.name != null) {\n testCase.name = options.name;\n }\n if (options?.tags != null) {\n testCase.tags = options.tags;\n }\n\n return testCase;\n}\n\n/**\n * Convert an array of chat messages into an `LLMTestCase`.\n * The last assistant message is treated as `actualOutput`, and the last\n * user message is treated as `input`. Earlier messages are combined into\n * context for reference.\n *\n * @param messages - Array of chat messages with role and content.\n * @param options - Additional fields for the test case.\n * @returns A fully populated `LLMTestCase`.\n *\n * @example\n * ```ts\n * import { fromMessages } from \"@assay-ai/ai-sdk\";\n *\n * const testCase = fromMessages([\n * { role: \"user\", content: \"What is the capital of France?\" },\n * { role: \"assistant\", content: \"The capital of France is Paris.\" },\n * ]);\n * ```\n */\nexport function fromMessages(\n messages: Array<{ role: string; content: string }>,\n options?: AdapterOptions,\n): LLMTestCase {\n if (messages.length === 0) {\n throw new Error(\"fromMessages requires at least one message\");\n }\n\n // Find the last user message and last assistant message\n let lastUserMessage: string | undefined;\n let lastAssistantMessage: string | undefined;\n const contextParts: string[] = [];\n\n // Walk backward to find the last assistant and user messages\n for (let i = messages.length - 1; i >= 0; i--) {\n const msg = messages[i]!;\n if (msg.role === \"assistant\" && lastAssistantMessage == null) {\n lastAssistantMessage = msg.content;\n } else if (msg.role === \"user\" && lastUserMessage == null) {\n lastUserMessage = msg.content;\n }\n if (lastUserMessage != null && lastAssistantMessage != null) {\n break;\n }\n }\n\n // Build conversation context from all messages except the ones we extracted\n // as input/output\n let foundLastUser = false;\n let foundLastAssistant = false;\n\n for (let i = messages.length - 1; i >= 0; i--) {\n const msg = messages[i]!;\n if (msg.role === \"user\" && msg.content === lastUserMessage && !foundLastUser) {\n foundLastUser = true;\n continue;\n }\n if (msg.role === \"assistant\" && msg.content === lastAssistantMessage && !foundLastAssistant) {\n foundLastAssistant = true;\n continue;\n }\n contextParts.unshift(`[${msg.role}]: ${msg.content}`);\n }\n\n const input = lastUserMessage ?? messages[0]?.content ?? \"\";\n\n const testCase: LLMTestCase = {\n input,\n };\n\n if (lastAssistantMessage != null) {\n testCase.actualOutput = lastAssistantMessage;\n }\n\n // Merge conversation context with any user-provided context\n const allContext = [\n ...(contextParts.length > 0 ? contextParts : []),\n ...(options?.context ?? []),\n ];\n if (allContext.length > 0) {\n testCase.context = allContext;\n }\n\n if (options?.expectedOutput != null) {\n testCase.expectedOutput = options.expectedOutput;\n }\n if (options?.retrievalContext != null) {\n testCase.retrievalContext = options.retrievalContext;\n }\n if (options?.name != null) {\n testCase.name = options.name;\n }\n if (options?.tags != null) {\n testCase.tags = options.tags;\n }\n\n return testCase;\n}\n"],"mappings":"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","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { LLMTestCase } from '@assay-ai/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A duck-typed interface matching the result of `generateText()` from the
|
|
5
|
+
* Vercel AI SDK. We use structural typing so users don't need to install
|
|
6
|
+
* a specific version of the AI SDK.
|
|
7
|
+
*/
|
|
8
|
+
interface GenerateTextResultLike {
|
|
9
|
+
text: string;
|
|
10
|
+
usage?: {
|
|
11
|
+
totalTokens?: number;
|
|
12
|
+
promptTokens?: number;
|
|
13
|
+
completionTokens?: number;
|
|
14
|
+
};
|
|
15
|
+
finishReason?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A duck-typed interface matching the result of `streamText()` from the
|
|
19
|
+
* Vercel AI SDK. The `text` and `usage` properties may be promises that
|
|
20
|
+
* resolve once the stream completes.
|
|
21
|
+
*/
|
|
22
|
+
interface StreamTextResultLike {
|
|
23
|
+
text: Promise<string> | string;
|
|
24
|
+
usage?: Promise<{
|
|
25
|
+
totalTokens?: number;
|
|
26
|
+
promptTokens?: number;
|
|
27
|
+
completionTokens?: number;
|
|
28
|
+
}> | {
|
|
29
|
+
totalTokens?: number;
|
|
30
|
+
promptTokens?: number;
|
|
31
|
+
completionTokens?: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface AdapterOptions {
|
|
35
|
+
/** Expected output for comparison-based metrics. */
|
|
36
|
+
expectedOutput?: string;
|
|
37
|
+
/** Context passages for retrieval-based metrics (e.g., RAG). */
|
|
38
|
+
context?: string[];
|
|
39
|
+
/** Retrieved context for faithfulness/hallucination evaluation. */
|
|
40
|
+
retrievalContext?: string[];
|
|
41
|
+
/** Human-readable name for the test case. */
|
|
42
|
+
name?: string;
|
|
43
|
+
/** Tags for filtering/grouping test cases. */
|
|
44
|
+
tags?: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Convert a `generateText()` result into an `LLMTestCase` for evaluation.
|
|
48
|
+
*
|
|
49
|
+
* @param result - The result from Vercel AI SDK's `generateText()`.
|
|
50
|
+
* @param input - The original prompt/input that was sent to the model.
|
|
51
|
+
* @param options - Additional fields for the test case.
|
|
52
|
+
* @returns A fully populated `LLMTestCase`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { generateText } from "ai";
|
|
57
|
+
* import { fromGenerateText } from "@assay-ai/ai-sdk";
|
|
58
|
+
*
|
|
59
|
+
* const result = await generateText({ model, prompt: "What is 2+2?" });
|
|
60
|
+
* const testCase = fromGenerateText(result, "What is 2+2?", {
|
|
61
|
+
* expectedOutput: "4",
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function fromGenerateText(result: GenerateTextResultLike, input: string, options?: AdapterOptions): LLMTestCase;
|
|
66
|
+
/**
|
|
67
|
+
* Convert a `streamText()` result into an `LLMTestCase` for evaluation.
|
|
68
|
+
* This awaits the streamed text and usage before building the test case.
|
|
69
|
+
*
|
|
70
|
+
* @param result - The result from Vercel AI SDK's `streamText()`.
|
|
71
|
+
* @param input - The original prompt/input that was sent to the model.
|
|
72
|
+
* @param options - Additional fields for the test case.
|
|
73
|
+
* @returns A promise that resolves to a fully populated `LLMTestCase`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { streamText } from "ai";
|
|
78
|
+
* import { fromStreamText } from "@assay-ai/ai-sdk";
|
|
79
|
+
*
|
|
80
|
+
* const result = streamText({ model, prompt: "Explain gravity." });
|
|
81
|
+
* const testCase = await fromStreamText(result, "Explain gravity.");
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function fromStreamText(result: StreamTextResultLike, input: string, options?: AdapterOptions): Promise<LLMTestCase>;
|
|
85
|
+
/**
|
|
86
|
+
* Convert an array of chat messages into an `LLMTestCase`.
|
|
87
|
+
* The last assistant message is treated as `actualOutput`, and the last
|
|
88
|
+
* user message is treated as `input`. Earlier messages are combined into
|
|
89
|
+
* context for reference.
|
|
90
|
+
*
|
|
91
|
+
* @param messages - Array of chat messages with role and content.
|
|
92
|
+
* @param options - Additional fields for the test case.
|
|
93
|
+
* @returns A fully populated `LLMTestCase`.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { fromMessages } from "@assay-ai/ai-sdk";
|
|
98
|
+
*
|
|
99
|
+
* const testCase = fromMessages([
|
|
100
|
+
* { role: "user", content: "What is the capital of France?" },
|
|
101
|
+
* { role: "assistant", content: "The capital of France is Paris." },
|
|
102
|
+
* ]);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function fromMessages(messages: Array<{
|
|
106
|
+
role: string;
|
|
107
|
+
content: string;
|
|
108
|
+
}>, options?: AdapterOptions): LLMTestCase;
|
|
109
|
+
|
|
110
|
+
export { fromGenerateText, fromMessages, fromStreamText };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { LLMTestCase } from '@assay-ai/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A duck-typed interface matching the result of `generateText()` from the
|
|
5
|
+
* Vercel AI SDK. We use structural typing so users don't need to install
|
|
6
|
+
* a specific version of the AI SDK.
|
|
7
|
+
*/
|
|
8
|
+
interface GenerateTextResultLike {
|
|
9
|
+
text: string;
|
|
10
|
+
usage?: {
|
|
11
|
+
totalTokens?: number;
|
|
12
|
+
promptTokens?: number;
|
|
13
|
+
completionTokens?: number;
|
|
14
|
+
};
|
|
15
|
+
finishReason?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A duck-typed interface matching the result of `streamText()` from the
|
|
19
|
+
* Vercel AI SDK. The `text` and `usage` properties may be promises that
|
|
20
|
+
* resolve once the stream completes.
|
|
21
|
+
*/
|
|
22
|
+
interface StreamTextResultLike {
|
|
23
|
+
text: Promise<string> | string;
|
|
24
|
+
usage?: Promise<{
|
|
25
|
+
totalTokens?: number;
|
|
26
|
+
promptTokens?: number;
|
|
27
|
+
completionTokens?: number;
|
|
28
|
+
}> | {
|
|
29
|
+
totalTokens?: number;
|
|
30
|
+
promptTokens?: number;
|
|
31
|
+
completionTokens?: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface AdapterOptions {
|
|
35
|
+
/** Expected output for comparison-based metrics. */
|
|
36
|
+
expectedOutput?: string;
|
|
37
|
+
/** Context passages for retrieval-based metrics (e.g., RAG). */
|
|
38
|
+
context?: string[];
|
|
39
|
+
/** Retrieved context for faithfulness/hallucination evaluation. */
|
|
40
|
+
retrievalContext?: string[];
|
|
41
|
+
/** Human-readable name for the test case. */
|
|
42
|
+
name?: string;
|
|
43
|
+
/** Tags for filtering/grouping test cases. */
|
|
44
|
+
tags?: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Convert a `generateText()` result into an `LLMTestCase` for evaluation.
|
|
48
|
+
*
|
|
49
|
+
* @param result - The result from Vercel AI SDK's `generateText()`.
|
|
50
|
+
* @param input - The original prompt/input that was sent to the model.
|
|
51
|
+
* @param options - Additional fields for the test case.
|
|
52
|
+
* @returns A fully populated `LLMTestCase`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { generateText } from "ai";
|
|
57
|
+
* import { fromGenerateText } from "@assay-ai/ai-sdk";
|
|
58
|
+
*
|
|
59
|
+
* const result = await generateText({ model, prompt: "What is 2+2?" });
|
|
60
|
+
* const testCase = fromGenerateText(result, "What is 2+2?", {
|
|
61
|
+
* expectedOutput: "4",
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function fromGenerateText(result: GenerateTextResultLike, input: string, options?: AdapterOptions): LLMTestCase;
|
|
66
|
+
/**
|
|
67
|
+
* Convert a `streamText()` result into an `LLMTestCase` for evaluation.
|
|
68
|
+
* This awaits the streamed text and usage before building the test case.
|
|
69
|
+
*
|
|
70
|
+
* @param result - The result from Vercel AI SDK's `streamText()`.
|
|
71
|
+
* @param input - The original prompt/input that was sent to the model.
|
|
72
|
+
* @param options - Additional fields for the test case.
|
|
73
|
+
* @returns A promise that resolves to a fully populated `LLMTestCase`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { streamText } from "ai";
|
|
78
|
+
* import { fromStreamText } from "@assay-ai/ai-sdk";
|
|
79
|
+
*
|
|
80
|
+
* const result = streamText({ model, prompt: "Explain gravity." });
|
|
81
|
+
* const testCase = await fromStreamText(result, "Explain gravity.");
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function fromStreamText(result: StreamTextResultLike, input: string, options?: AdapterOptions): Promise<LLMTestCase>;
|
|
85
|
+
/**
|
|
86
|
+
* Convert an array of chat messages into an `LLMTestCase`.
|
|
87
|
+
* The last assistant message is treated as `actualOutput`, and the last
|
|
88
|
+
* user message is treated as `input`. Earlier messages are combined into
|
|
89
|
+
* context for reference.
|
|
90
|
+
*
|
|
91
|
+
* @param messages - Array of chat messages with role and content.
|
|
92
|
+
* @param options - Additional fields for the test case.
|
|
93
|
+
* @returns A fully populated `LLMTestCase`.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { fromMessages } from "@assay-ai/ai-sdk";
|
|
98
|
+
*
|
|
99
|
+
* const testCase = fromMessages([
|
|
100
|
+
* { role: "user", content: "What is the capital of France?" },
|
|
101
|
+
* { role: "assistant", content: "The capital of France is Paris." },
|
|
102
|
+
* ]);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function fromMessages(messages: Array<{
|
|
106
|
+
role: string;
|
|
107
|
+
content: string;
|
|
108
|
+
}>, options?: AdapterOptions): LLMTestCase;
|
|
109
|
+
|
|
110
|
+
export { fromGenerateText, fromMessages, fromStreamText };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// src/adapter.ts
|
|
2
|
+
function fromGenerateText(result, input, options) {
|
|
3
|
+
const testCase = {
|
|
4
|
+
input,
|
|
5
|
+
actualOutput: result.text
|
|
6
|
+
};
|
|
7
|
+
if (result.usage?.totalTokens != null) {
|
|
8
|
+
testCase.tokenCost = result.usage.totalTokens;
|
|
9
|
+
}
|
|
10
|
+
if (options?.expectedOutput != null) {
|
|
11
|
+
testCase.expectedOutput = options.expectedOutput;
|
|
12
|
+
}
|
|
13
|
+
if (options?.context != null) {
|
|
14
|
+
testCase.context = options.context;
|
|
15
|
+
}
|
|
16
|
+
if (options?.retrievalContext != null) {
|
|
17
|
+
testCase.retrievalContext = options.retrievalContext;
|
|
18
|
+
}
|
|
19
|
+
if (options?.name != null) {
|
|
20
|
+
testCase.name = options.name;
|
|
21
|
+
}
|
|
22
|
+
if (options?.tags != null) {
|
|
23
|
+
testCase.tags = options.tags;
|
|
24
|
+
}
|
|
25
|
+
return testCase;
|
|
26
|
+
}
|
|
27
|
+
async function fromStreamText(result, input, options) {
|
|
28
|
+
const [text, usage] = await Promise.all([
|
|
29
|
+
Promise.resolve(result.text),
|
|
30
|
+
result.usage != null ? Promise.resolve(result.usage) : Promise.resolve(void 0)
|
|
31
|
+
]);
|
|
32
|
+
const testCase = {
|
|
33
|
+
input,
|
|
34
|
+
actualOutput: text
|
|
35
|
+
};
|
|
36
|
+
if (usage?.totalTokens != null) {
|
|
37
|
+
testCase.tokenCost = usage.totalTokens;
|
|
38
|
+
}
|
|
39
|
+
if (options?.expectedOutput != null) {
|
|
40
|
+
testCase.expectedOutput = options.expectedOutput;
|
|
41
|
+
}
|
|
42
|
+
if (options?.context != null) {
|
|
43
|
+
testCase.context = options.context;
|
|
44
|
+
}
|
|
45
|
+
if (options?.retrievalContext != null) {
|
|
46
|
+
testCase.retrievalContext = options.retrievalContext;
|
|
47
|
+
}
|
|
48
|
+
if (options?.name != null) {
|
|
49
|
+
testCase.name = options.name;
|
|
50
|
+
}
|
|
51
|
+
if (options?.tags != null) {
|
|
52
|
+
testCase.tags = options.tags;
|
|
53
|
+
}
|
|
54
|
+
return testCase;
|
|
55
|
+
}
|
|
56
|
+
function fromMessages(messages, options) {
|
|
57
|
+
if (messages.length === 0) {
|
|
58
|
+
throw new Error("fromMessages requires at least one message");
|
|
59
|
+
}
|
|
60
|
+
let lastUserMessage;
|
|
61
|
+
let lastAssistantMessage;
|
|
62
|
+
const contextParts = [];
|
|
63
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
64
|
+
const msg = messages[i];
|
|
65
|
+
if (msg.role === "assistant" && lastAssistantMessage == null) {
|
|
66
|
+
lastAssistantMessage = msg.content;
|
|
67
|
+
} else if (msg.role === "user" && lastUserMessage == null) {
|
|
68
|
+
lastUserMessage = msg.content;
|
|
69
|
+
}
|
|
70
|
+
if (lastUserMessage != null && lastAssistantMessage != null) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
let foundLastUser = false;
|
|
75
|
+
let foundLastAssistant = false;
|
|
76
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
77
|
+
const msg = messages[i];
|
|
78
|
+
if (msg.role === "user" && msg.content === lastUserMessage && !foundLastUser) {
|
|
79
|
+
foundLastUser = true;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (msg.role === "assistant" && msg.content === lastAssistantMessage && !foundLastAssistant) {
|
|
83
|
+
foundLastAssistant = true;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
contextParts.unshift(`[${msg.role}]: ${msg.content}`);
|
|
87
|
+
}
|
|
88
|
+
const input = lastUserMessage ?? messages[0]?.content ?? "";
|
|
89
|
+
const testCase = {
|
|
90
|
+
input
|
|
91
|
+
};
|
|
92
|
+
if (lastAssistantMessage != null) {
|
|
93
|
+
testCase.actualOutput = lastAssistantMessage;
|
|
94
|
+
}
|
|
95
|
+
const allContext = [
|
|
96
|
+
...contextParts.length > 0 ? contextParts : [],
|
|
97
|
+
...options?.context ?? []
|
|
98
|
+
];
|
|
99
|
+
if (allContext.length > 0) {
|
|
100
|
+
testCase.context = allContext;
|
|
101
|
+
}
|
|
102
|
+
if (options?.expectedOutput != null) {
|
|
103
|
+
testCase.expectedOutput = options.expectedOutput;
|
|
104
|
+
}
|
|
105
|
+
if (options?.retrievalContext != null) {
|
|
106
|
+
testCase.retrievalContext = options.retrievalContext;
|
|
107
|
+
}
|
|
108
|
+
if (options?.name != null) {
|
|
109
|
+
testCase.name = options.name;
|
|
110
|
+
}
|
|
111
|
+
if (options?.tags != null) {
|
|
112
|
+
testCase.tags = options.tags;
|
|
113
|
+
}
|
|
114
|
+
return testCase;
|
|
115
|
+
}
|
|
116
|
+
export {
|
|
117
|
+
fromGenerateText,
|
|
118
|
+
fromMessages,
|
|
119
|
+
fromStreamText
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type { LLMTestCase } from \"@assay-ai/core\";\n\n/**\n * A duck-typed interface matching the result of `generateText()` from the\n * Vercel AI SDK. We use structural typing so users don't need to install\n * a specific version of the AI SDK.\n */\ninterface GenerateTextResultLike {\n text: string;\n usage?: {\n totalTokens?: number;\n promptTokens?: number;\n completionTokens?: number;\n };\n finishReason?: string;\n}\n\n/**\n * A duck-typed interface matching the result of `streamText()` from the\n * Vercel AI SDK. The `text` and `usage` properties may be promises that\n * resolve once the stream completes.\n */\ninterface StreamTextResultLike {\n text: Promise<string> | string;\n usage?:\n | Promise<{ totalTokens?: number; promptTokens?: number; completionTokens?: number }>\n | { totalTokens?: number; promptTokens?: number; completionTokens?: number };\n}\n\ninterface AdapterOptions {\n /** Expected output for comparison-based metrics. */\n expectedOutput?: string;\n /** Context passages for retrieval-based metrics (e.g., RAG). */\n context?: string[];\n /** Retrieved context for faithfulness/hallucination evaluation. */\n retrievalContext?: string[];\n /** Human-readable name for the test case. */\n name?: string;\n /** Tags for filtering/grouping test cases. */\n tags?: string[];\n}\n\n/**\n * Convert a `generateText()` result into an `LLMTestCase` for evaluation.\n *\n * @param result - The result from Vercel AI SDK's `generateText()`.\n * @param input - The original prompt/input that was sent to the model.\n * @param options - Additional fields for the test case.\n * @returns A fully populated `LLMTestCase`.\n *\n * @example\n * ```ts\n * import { generateText } from \"ai\";\n * import { fromGenerateText } from \"@assay-ai/ai-sdk\";\n *\n * const result = await generateText({ model, prompt: \"What is 2+2?\" });\n * const testCase = fromGenerateText(result, \"What is 2+2?\", {\n * expectedOutput: \"4\",\n * });\n * ```\n */\nexport function fromGenerateText(\n result: GenerateTextResultLike,\n input: string,\n options?: AdapterOptions,\n): LLMTestCase {\n const testCase: LLMTestCase = {\n input,\n actualOutput: result.text,\n };\n\n if (result.usage?.totalTokens != null) {\n testCase.tokenCost = result.usage.totalTokens;\n }\n\n if (options?.expectedOutput != null) {\n testCase.expectedOutput = options.expectedOutput;\n }\n if (options?.context != null) {\n testCase.context = options.context;\n }\n if (options?.retrievalContext != null) {\n testCase.retrievalContext = options.retrievalContext;\n }\n if (options?.name != null) {\n testCase.name = options.name;\n }\n if (options?.tags != null) {\n testCase.tags = options.tags;\n }\n\n return testCase;\n}\n\n/**\n * Convert a `streamText()` result into an `LLMTestCase` for evaluation.\n * This awaits the streamed text and usage before building the test case.\n *\n * @param result - The result from Vercel AI SDK's `streamText()`.\n * @param input - The original prompt/input that was sent to the model.\n * @param options - Additional fields for the test case.\n * @returns A promise that resolves to a fully populated `LLMTestCase`.\n *\n * @example\n * ```ts\n * import { streamText } from \"ai\";\n * import { fromStreamText } from \"@assay-ai/ai-sdk\";\n *\n * const result = streamText({ model, prompt: \"Explain gravity.\" });\n * const testCase = await fromStreamText(result, \"Explain gravity.\");\n * ```\n */\nexport async function fromStreamText(\n result: StreamTextResultLike,\n input: string,\n options?: AdapterOptions,\n): Promise<LLMTestCase> {\n const [text, usage] = await Promise.all([\n Promise.resolve(result.text),\n result.usage != null ? Promise.resolve(result.usage) : Promise.resolve(undefined),\n ]);\n\n const testCase: LLMTestCase = {\n input,\n actualOutput: text,\n };\n\n if (usage?.totalTokens != null) {\n testCase.tokenCost = usage.totalTokens;\n }\n\n if (options?.expectedOutput != null) {\n testCase.expectedOutput = options.expectedOutput;\n }\n if (options?.context != null) {\n testCase.context = options.context;\n }\n if (options?.retrievalContext != null) {\n testCase.retrievalContext = options.retrievalContext;\n }\n if (options?.name != null) {\n testCase.name = options.name;\n }\n if (options?.tags != null) {\n testCase.tags = options.tags;\n }\n\n return testCase;\n}\n\n/**\n * Convert an array of chat messages into an `LLMTestCase`.\n * The last assistant message is treated as `actualOutput`, and the last\n * user message is treated as `input`. Earlier messages are combined into\n * context for reference.\n *\n * @param messages - Array of chat messages with role and content.\n * @param options - Additional fields for the test case.\n * @returns A fully populated `LLMTestCase`.\n *\n * @example\n * ```ts\n * import { fromMessages } from \"@assay-ai/ai-sdk\";\n *\n * const testCase = fromMessages([\n * { role: \"user\", content: \"What is the capital of France?\" },\n * { role: \"assistant\", content: \"The capital of France is Paris.\" },\n * ]);\n * ```\n */\nexport function fromMessages(\n messages: Array<{ role: string; content: string }>,\n options?: AdapterOptions,\n): LLMTestCase {\n if (messages.length === 0) {\n throw new Error(\"fromMessages requires at least one message\");\n }\n\n // Find the last user message and last assistant message\n let lastUserMessage: string | undefined;\n let lastAssistantMessage: string | undefined;\n const contextParts: string[] = [];\n\n // Walk backward to find the last assistant and user messages\n for (let i = messages.length - 1; i >= 0; i--) {\n const msg = messages[i]!;\n if (msg.role === \"assistant\" && lastAssistantMessage == null) {\n lastAssistantMessage = msg.content;\n } else if (msg.role === \"user\" && lastUserMessage == null) {\n lastUserMessage = msg.content;\n }\n if (lastUserMessage != null && lastAssistantMessage != null) {\n break;\n }\n }\n\n // Build conversation context from all messages except the ones we extracted\n // as input/output\n let foundLastUser = false;\n let foundLastAssistant = false;\n\n for (let i = messages.length - 1; i >= 0; i--) {\n const msg = messages[i]!;\n if (msg.role === \"user\" && msg.content === lastUserMessage && !foundLastUser) {\n foundLastUser = true;\n continue;\n }\n if (msg.role === \"assistant\" && msg.content === lastAssistantMessage && !foundLastAssistant) {\n foundLastAssistant = true;\n continue;\n }\n contextParts.unshift(`[${msg.role}]: ${msg.content}`);\n }\n\n const input = lastUserMessage ?? messages[0]?.content ?? \"\";\n\n const testCase: LLMTestCase = {\n input,\n };\n\n if (lastAssistantMessage != null) {\n testCase.actualOutput = lastAssistantMessage;\n }\n\n // Merge conversation context with any user-provided context\n const allContext = [\n ...(contextParts.length > 0 ? contextParts : []),\n ...(options?.context ?? []),\n ];\n if (allContext.length > 0) {\n testCase.context = allContext;\n }\n\n if (options?.expectedOutput != null) {\n testCase.expectedOutput = options.expectedOutput;\n }\n if (options?.retrievalContext != null) {\n testCase.retrievalContext = options.retrievalContext;\n }\n if (options?.name != null) {\n testCase.name = options.name;\n }\n if (options?.tags != null) {\n testCase.tags = options.tags;\n }\n\n return testCase;\n}\n"],"mappings":"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","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@assay-ai/ai-sdk",
|
|
3
|
+
"version": "0.1.0-beta",
|
|
4
|
+
"description": "Vercel AI SDK adapter for the Assay LLM evaluation framework",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"ai": ">=4.0.0",
|
|
27
|
+
"@assay-ai/core": "0.1.0-beta"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"ai": "^4.0.0",
|
|
31
|
+
"tsup": "^8.3.0",
|
|
32
|
+
"typescript": "^5.7.0",
|
|
33
|
+
"@assay-ai/tsconfig": "0.0.0",
|
|
34
|
+
"@assay-ai/core": "0.1.0-beta"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/assay-ai/assay",
|
|
39
|
+
"directory": "packages/ai-sdk"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"dev": "tsup --watch",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"clean": "rm -rf dist .turbo"
|
|
46
|
+
}
|
|
47
|
+
}
|