@aigne/test-utils 0.2.0 → 0.3.1
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 +23 -0
- package/lib/utils/event-stream.d.ts +5 -0
- package/lib/utils/event-stream.js +13 -0
- package/lib/utils/openai-like-utils.d.ts +7 -0
- package/lib/utils/openai-like-utils.js +76 -0
- package/package.json +4 -2
- package/src/utils/event-stream.ts +13 -0
- package/src/utils/openai-like-utils.ts +99 -0
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.1](https://github.com/AIGNE-io/aigne-framework/compare/test-utils-v0.3.0...test-utils-v0.3.1) (2025-05-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Dependencies
|
|
7
|
+
|
|
8
|
+
* The following workspace dependencies were updated
|
|
9
|
+
* dependencies
|
|
10
|
+
* @aigne/core bumped to 1.17.0
|
|
11
|
+
|
|
12
|
+
## [0.3.0](https://github.com/AIGNE-io/aigne-framework/compare/test-utils-v0.2.0...test-utils-v0.3.0) (2025-05-23)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **models:** publish model adapters as standalone packages ([#126](https://github.com/AIGNE-io/aigne-framework/issues/126)) ([588b8ae](https://github.com/AIGNE-io/aigne-framework/commit/588b8aea6abcee5fa87def1358bf51f84021c6ef))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Dependencies
|
|
21
|
+
|
|
22
|
+
* The following workspace dependencies were updated
|
|
23
|
+
* dependencies
|
|
24
|
+
* @aigne/core bumped to 1.16.0
|
|
25
|
+
|
|
3
26
|
## [0.2.0](https://github.com/AIGNE-io/aigne-framework/compare/test-utils-v0.1.0...test-utils-v0.2.0) (2025-05-12)
|
|
4
27
|
|
|
5
28
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
export function createMockEventStream(data) {
|
|
3
|
+
return new ReadableStream({
|
|
4
|
+
async start(controller) {
|
|
5
|
+
const file = "path" in data ? await readFile(data.path) : data.raw;
|
|
6
|
+
for (const line of file.toString().split("\n")) {
|
|
7
|
+
if (line)
|
|
8
|
+
controller.enqueue(JSON.parse(line.replace("data:", "")));
|
|
9
|
+
}
|
|
10
|
+
controller.close();
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ChatModelInputResponseFormat, type ChatModelInputTool, type ChatModelOutputToolCall, type Message } from "@aigne/core";
|
|
2
|
+
export declare const COMMON_TOOLS: ChatModelInputTool[];
|
|
3
|
+
export declare const COMMON_RESPONSE_FORMAT: ChatModelInputResponseFormat;
|
|
4
|
+
export declare const createWeatherToolMessages: () => import("@aigne/core").ChatModelInputMessage[];
|
|
5
|
+
export declare const createWeatherToolExpected: () => any;
|
|
6
|
+
export declare const createWeatherToolCallMessages: () => import("@aigne/core").ChatModelInputMessage[];
|
|
7
|
+
export declare function createToolCallResponse(functionName: string, args: Message): ChatModelOutputToolCall;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { expect } from "bun:test";
|
|
2
|
+
import { AgentMessageTemplate, ChatMessagesTemplate, SystemMessageTemplate, ToolMessageTemplate, UserMessageTemplate, } from "@aigne/core";
|
|
3
|
+
export const COMMON_TOOLS = [
|
|
4
|
+
{
|
|
5
|
+
type: "function",
|
|
6
|
+
function: {
|
|
7
|
+
name: "get_weather",
|
|
8
|
+
parameters: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
city: {
|
|
12
|
+
type: "string",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
required: ["city"],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
export const COMMON_RESPONSE_FORMAT = {
|
|
21
|
+
type: "json_schema",
|
|
22
|
+
jsonSchema: {
|
|
23
|
+
name: "output",
|
|
24
|
+
schema: {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
text: {
|
|
28
|
+
type: "string",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
required: ["text"],
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
},
|
|
34
|
+
strict: true,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const createBaseMessages = () => [
|
|
38
|
+
SystemMessageTemplate.from("You are a chatbot"),
|
|
39
|
+
UserMessageTemplate.from([{ type: "text", text: "What is the weather in New York?" }]),
|
|
40
|
+
];
|
|
41
|
+
export const createWeatherToolMessages = () => ChatMessagesTemplate.from(createBaseMessages()).format();
|
|
42
|
+
export const createWeatherToolExpected = () => expect.objectContaining({
|
|
43
|
+
toolCalls: [
|
|
44
|
+
{
|
|
45
|
+
function: {
|
|
46
|
+
arguments: {
|
|
47
|
+
city: "New York",
|
|
48
|
+
},
|
|
49
|
+
name: "get_weather",
|
|
50
|
+
},
|
|
51
|
+
id: expect.any(String),
|
|
52
|
+
type: "function",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
export const createWeatherToolCallMessages = () => ChatMessagesTemplate.from([
|
|
57
|
+
...createBaseMessages(),
|
|
58
|
+
AgentMessageTemplate.from(undefined, [
|
|
59
|
+
{
|
|
60
|
+
id: "get_weather",
|
|
61
|
+
type: "function",
|
|
62
|
+
function: { name: "get_weather", arguments: { city: "New York" } },
|
|
63
|
+
},
|
|
64
|
+
]),
|
|
65
|
+
ToolMessageTemplate.from({ temperature: 20 }, "get_weather"),
|
|
66
|
+
]).format();
|
|
67
|
+
export function createToolCallResponse(functionName, args) {
|
|
68
|
+
return {
|
|
69
|
+
id: functionName,
|
|
70
|
+
type: "function",
|
|
71
|
+
function: {
|
|
72
|
+
name: functionName,
|
|
73
|
+
arguments: args,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/test-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Test utils for AIGNE framework",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
]
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
-
"dependencies": {
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@aigne/core": "^1.17.0"
|
|
28
|
+
},
|
|
27
29
|
"devDependencies": {
|
|
28
30
|
"@types/bun": "^1.2.12",
|
|
29
31
|
"@types/node": "^22.15.15",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
export function createMockEventStream<T>(data: { path: string } | { raw: string }): T {
|
|
4
|
+
return new ReadableStream({
|
|
5
|
+
async start(controller) {
|
|
6
|
+
const file = "path" in data ? await readFile(data.path) : data.raw;
|
|
7
|
+
for (const line of file.toString().split("\n")) {
|
|
8
|
+
if (line) controller.enqueue(JSON.parse(line.replace("data:", "")));
|
|
9
|
+
}
|
|
10
|
+
controller.close();
|
|
11
|
+
},
|
|
12
|
+
}) as unknown as T;
|
|
13
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { expect } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
AgentMessageTemplate,
|
|
4
|
+
ChatMessagesTemplate,
|
|
5
|
+
type ChatModelInputResponseFormat,
|
|
6
|
+
type ChatModelInputTool,
|
|
7
|
+
type ChatModelOutputToolCall,
|
|
8
|
+
type Message,
|
|
9
|
+
SystemMessageTemplate,
|
|
10
|
+
ToolMessageTemplate,
|
|
11
|
+
UserMessageTemplate,
|
|
12
|
+
} from "@aigne/core";
|
|
13
|
+
|
|
14
|
+
export const COMMON_TOOLS: ChatModelInputTool[] = [
|
|
15
|
+
{
|
|
16
|
+
type: "function",
|
|
17
|
+
function: {
|
|
18
|
+
name: "get_weather",
|
|
19
|
+
parameters: {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
city: {
|
|
23
|
+
type: "string",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
required: ["city"],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export const COMMON_RESPONSE_FORMAT: ChatModelInputResponseFormat = {
|
|
33
|
+
type: "json_schema",
|
|
34
|
+
jsonSchema: {
|
|
35
|
+
name: "output",
|
|
36
|
+
schema: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
text: {
|
|
40
|
+
type: "string",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
required: ["text"],
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
},
|
|
46
|
+
strict: true,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const createBaseMessages = () => [
|
|
51
|
+
SystemMessageTemplate.from("You are a chatbot"),
|
|
52
|
+
UserMessageTemplate.from([{ type: "text", text: "What is the weather in New York?" }]),
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
export const createWeatherToolMessages = () =>
|
|
56
|
+
ChatMessagesTemplate.from(createBaseMessages()).format();
|
|
57
|
+
|
|
58
|
+
export const createWeatherToolExpected = () =>
|
|
59
|
+
expect.objectContaining({
|
|
60
|
+
toolCalls: [
|
|
61
|
+
{
|
|
62
|
+
function: {
|
|
63
|
+
arguments: {
|
|
64
|
+
city: "New York",
|
|
65
|
+
},
|
|
66
|
+
name: "get_weather",
|
|
67
|
+
},
|
|
68
|
+
id: expect.any(String),
|
|
69
|
+
type: "function",
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const createWeatherToolCallMessages = () =>
|
|
75
|
+
ChatMessagesTemplate.from([
|
|
76
|
+
...createBaseMessages(),
|
|
77
|
+
AgentMessageTemplate.from(undefined, [
|
|
78
|
+
{
|
|
79
|
+
id: "get_weather",
|
|
80
|
+
type: "function",
|
|
81
|
+
function: { name: "get_weather", arguments: { city: "New York" } },
|
|
82
|
+
},
|
|
83
|
+
]),
|
|
84
|
+
ToolMessageTemplate.from({ temperature: 20 }, "get_weather"),
|
|
85
|
+
]).format();
|
|
86
|
+
|
|
87
|
+
export function createToolCallResponse(
|
|
88
|
+
functionName: string,
|
|
89
|
+
args: Message,
|
|
90
|
+
): ChatModelOutputToolCall {
|
|
91
|
+
return {
|
|
92
|
+
id: functionName,
|
|
93
|
+
type: "function",
|
|
94
|
+
function: {
|
|
95
|
+
name: functionName,
|
|
96
|
+
arguments: args,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/run-example-test.ts"],"version":"5.8.3"}
|
|
1
|
+
{"root":["./src/run-example-test.ts","./src/utils/event-stream.ts","./src/utils/openai-like-utils.ts"],"version":"5.8.3"}
|