modelfusion 0.8.0 → 0.9.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/package.json +1 -1
- package/tool/Tool.cjs +24 -0
- package/tool/Tool.d.ts +24 -0
- package/tool/Tool.js +24 -0
- package/tool/WebSearchTool.cjs +43 -0
- package/tool/WebSearchTool.d.ts +81 -0
- package/tool/WebSearchTool.js +39 -0
- package/tool/executeTool.d.ts +3 -0
- package/tool/index.cjs +1 -0
- package/tool/index.d.ts +1 -0
- package/tool/index.js +1 -0
package/package.json
CHANGED
package/tool/Tool.cjs
CHANGED
@@ -1,32 +1,52 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Tool = void 0;
|
4
|
+
/**
|
5
|
+
* A tool is a function with a name, description and defined inputs that can be used
|
6
|
+
* by agents and chatbots.
|
7
|
+
*/
|
4
8
|
class Tool {
|
5
9
|
constructor(options) {
|
10
|
+
/**
|
11
|
+
* The name of the tool. Should be understandable for language models and unique among the tools that they know.
|
12
|
+
*/
|
6
13
|
Object.defineProperty(this, "name", {
|
7
14
|
enumerable: true,
|
8
15
|
configurable: true,
|
9
16
|
writable: true,
|
10
17
|
value: void 0
|
11
18
|
});
|
19
|
+
/**
|
20
|
+
* A description of what the tool does. Will be used by the language model to decide whether to use the tool.
|
21
|
+
*/
|
12
22
|
Object.defineProperty(this, "description", {
|
13
23
|
enumerable: true,
|
14
24
|
configurable: true,
|
15
25
|
writable: true,
|
16
26
|
value: void 0
|
17
27
|
});
|
28
|
+
/**
|
29
|
+
* The schema of the input that the tool expects. The language model will use this to generate the input.
|
30
|
+
* Use descriptions to make the input understandable for the language model.
|
31
|
+
*/
|
18
32
|
Object.defineProperty(this, "inputSchema", {
|
19
33
|
enumerable: true,
|
20
34
|
configurable: true,
|
21
35
|
writable: true,
|
22
36
|
value: void 0
|
23
37
|
});
|
38
|
+
/**
|
39
|
+
* An optional schema of the output that the tool produces. This will be used to validate the output.
|
40
|
+
*/
|
24
41
|
Object.defineProperty(this, "outputSchema", {
|
25
42
|
enumerable: true,
|
26
43
|
configurable: true,
|
27
44
|
writable: true,
|
28
45
|
value: void 0
|
29
46
|
});
|
47
|
+
/**
|
48
|
+
* The actual execution function of the tool.
|
49
|
+
*/
|
30
50
|
Object.defineProperty(this, "execute", {
|
31
51
|
enumerable: true,
|
32
52
|
configurable: true,
|
@@ -39,6 +59,10 @@ class Tool {
|
|
39
59
|
this.outputSchema = options.outputSchema;
|
40
60
|
this.execute = options.execute;
|
41
61
|
}
|
62
|
+
/**
|
63
|
+
* Provdes a schema definition with the name, description and schema of the input.
|
64
|
+
* This is used by `useTool`.
|
65
|
+
*/
|
42
66
|
get inputSchemaDefinition() {
|
43
67
|
return {
|
44
68
|
name: this.name,
|
package/tool/Tool.d.ts
CHANGED
@@ -1,11 +1,31 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import { SchemaDefinition } from "../model-function/generate-json/SchemaDefinition.js";
|
3
3
|
import { RunFunction } from "../run/RunFunction.js";
|
4
|
+
/**
|
5
|
+
* A tool is a function with a name, description and defined inputs that can be used
|
6
|
+
* by agents and chatbots.
|
7
|
+
*/
|
4
8
|
export declare class Tool<NAME extends string, INPUT, OUTPUT> {
|
9
|
+
/**
|
10
|
+
* The name of the tool. Should be understandable for language models and unique among the tools that they know.
|
11
|
+
*/
|
5
12
|
readonly name: NAME;
|
13
|
+
/**
|
14
|
+
* A description of what the tool does. Will be used by the language model to decide whether to use the tool.
|
15
|
+
*/
|
6
16
|
readonly description: string;
|
17
|
+
/**
|
18
|
+
* The schema of the input that the tool expects. The language model will use this to generate the input.
|
19
|
+
* Use descriptions to make the input understandable for the language model.
|
20
|
+
*/
|
7
21
|
readonly inputSchema: z.ZodSchema<INPUT>;
|
22
|
+
/**
|
23
|
+
* An optional schema of the output that the tool produces. This will be used to validate the output.
|
24
|
+
*/
|
8
25
|
readonly outputSchema?: z.ZodSchema<OUTPUT>;
|
26
|
+
/**
|
27
|
+
* The actual execution function of the tool.
|
28
|
+
*/
|
9
29
|
readonly execute: RunFunction<INPUT, OUTPUT>;
|
10
30
|
constructor(options: {
|
11
31
|
name: NAME;
|
@@ -14,5 +34,9 @@ export declare class Tool<NAME extends string, INPUT, OUTPUT> {
|
|
14
34
|
outputSchema?: z.ZodSchema<OUTPUT>;
|
15
35
|
execute(input: INPUT): Promise<OUTPUT>;
|
16
36
|
});
|
37
|
+
/**
|
38
|
+
* Provdes a schema definition with the name, description and schema of the input.
|
39
|
+
* This is used by `useTool`.
|
40
|
+
*/
|
17
41
|
get inputSchemaDefinition(): SchemaDefinition<NAME, INPUT>;
|
18
42
|
}
|
package/tool/Tool.js
CHANGED
@@ -1,29 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
* A tool is a function with a name, description and defined inputs that can be used
|
3
|
+
* by agents and chatbots.
|
4
|
+
*/
|
1
5
|
export class Tool {
|
2
6
|
constructor(options) {
|
7
|
+
/**
|
8
|
+
* The name of the tool. Should be understandable for language models and unique among the tools that they know.
|
9
|
+
*/
|
3
10
|
Object.defineProperty(this, "name", {
|
4
11
|
enumerable: true,
|
5
12
|
configurable: true,
|
6
13
|
writable: true,
|
7
14
|
value: void 0
|
8
15
|
});
|
16
|
+
/**
|
17
|
+
* A description of what the tool does. Will be used by the language model to decide whether to use the tool.
|
18
|
+
*/
|
9
19
|
Object.defineProperty(this, "description", {
|
10
20
|
enumerable: true,
|
11
21
|
configurable: true,
|
12
22
|
writable: true,
|
13
23
|
value: void 0
|
14
24
|
});
|
25
|
+
/**
|
26
|
+
* The schema of the input that the tool expects. The language model will use this to generate the input.
|
27
|
+
* Use descriptions to make the input understandable for the language model.
|
28
|
+
*/
|
15
29
|
Object.defineProperty(this, "inputSchema", {
|
16
30
|
enumerable: true,
|
17
31
|
configurable: true,
|
18
32
|
writable: true,
|
19
33
|
value: void 0
|
20
34
|
});
|
35
|
+
/**
|
36
|
+
* An optional schema of the output that the tool produces. This will be used to validate the output.
|
37
|
+
*/
|
21
38
|
Object.defineProperty(this, "outputSchema", {
|
22
39
|
enumerable: true,
|
23
40
|
configurable: true,
|
24
41
|
writable: true,
|
25
42
|
value: void 0
|
26
43
|
});
|
44
|
+
/**
|
45
|
+
* The actual execution function of the tool.
|
46
|
+
*/
|
27
47
|
Object.defineProperty(this, "execute", {
|
28
48
|
enumerable: true,
|
29
49
|
configurable: true,
|
@@ -36,6 +56,10 @@ export class Tool {
|
|
36
56
|
this.outputSchema = options.outputSchema;
|
37
57
|
this.execute = options.execute;
|
38
58
|
}
|
59
|
+
/**
|
60
|
+
* Provdes a schema definition with the name, description and schema of the input.
|
61
|
+
* This is used by `useTool`.
|
62
|
+
*/
|
39
63
|
get inputSchemaDefinition() {
|
40
64
|
return {
|
41
65
|
name: this.name,
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.WebSearchTool = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
const Tool_js_1 = require("./Tool.cjs");
|
6
|
+
const INPUT_SCHEMA = zod_1.z.object({
|
7
|
+
query: zod_1.z.string(),
|
8
|
+
});
|
9
|
+
const OUTPUT_SCHEMA = zod_1.z.object({
|
10
|
+
results: zod_1.z.array(zod_1.z.object({
|
11
|
+
title: zod_1.z.string(),
|
12
|
+
link: zod_1.z.string().url(),
|
13
|
+
snippet: zod_1.z.string(),
|
14
|
+
})),
|
15
|
+
});
|
16
|
+
/**
|
17
|
+
* @see https://serpapi.com/search-api
|
18
|
+
*/
|
19
|
+
class WebSearchTool extends Tool_js_1.Tool {
|
20
|
+
constructor(options) {
|
21
|
+
super({
|
22
|
+
name: options.name,
|
23
|
+
description: options.description,
|
24
|
+
inputSchema: INPUT_SCHEMA,
|
25
|
+
outputSchema: OUTPUT_SCHEMA,
|
26
|
+
execute: options.execute,
|
27
|
+
});
|
28
|
+
}
|
29
|
+
}
|
30
|
+
exports.WebSearchTool = WebSearchTool;
|
31
|
+
// expose the schemas to library consumers:
|
32
|
+
Object.defineProperty(WebSearchTool, "INPUT_SCHEMA", {
|
33
|
+
enumerable: true,
|
34
|
+
configurable: true,
|
35
|
+
writable: true,
|
36
|
+
value: INPUT_SCHEMA
|
37
|
+
});
|
38
|
+
Object.defineProperty(WebSearchTool, "OUTPUT_SCHEMA", {
|
39
|
+
enumerable: true,
|
40
|
+
configurable: true,
|
41
|
+
writable: true,
|
42
|
+
value: OUTPUT_SCHEMA
|
43
|
+
});
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
import { Tool } from "./Tool.js";
|
3
|
+
declare const INPUT_SCHEMA: z.ZodObject<{
|
4
|
+
query: z.ZodString;
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
6
|
+
query: string;
|
7
|
+
}, {
|
8
|
+
query: string;
|
9
|
+
}>;
|
10
|
+
declare const OUTPUT_SCHEMA: z.ZodObject<{
|
11
|
+
results: z.ZodArray<z.ZodObject<{
|
12
|
+
title: z.ZodString;
|
13
|
+
link: z.ZodString;
|
14
|
+
snippet: z.ZodString;
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
16
|
+
link: string;
|
17
|
+
title: string;
|
18
|
+
snippet: string;
|
19
|
+
}, {
|
20
|
+
link: string;
|
21
|
+
title: string;
|
22
|
+
snippet: string;
|
23
|
+
}>, "many">;
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
25
|
+
results: {
|
26
|
+
link: string;
|
27
|
+
title: string;
|
28
|
+
snippet: string;
|
29
|
+
}[];
|
30
|
+
}, {
|
31
|
+
results: {
|
32
|
+
link: string;
|
33
|
+
title: string;
|
34
|
+
snippet: string;
|
35
|
+
}[];
|
36
|
+
}>;
|
37
|
+
/**
|
38
|
+
* @see https://serpapi.com/search-api
|
39
|
+
*/
|
40
|
+
export declare class WebSearchTool<NAME extends string> extends Tool<NAME, z.infer<typeof INPUT_SCHEMA>, z.infer<typeof OUTPUT_SCHEMA>> {
|
41
|
+
static readonly INPUT_SCHEMA: z.ZodObject<{
|
42
|
+
query: z.ZodString;
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
44
|
+
query: string;
|
45
|
+
}, {
|
46
|
+
query: string;
|
47
|
+
}>;
|
48
|
+
static readonly OUTPUT_SCHEMA: z.ZodObject<{
|
49
|
+
results: z.ZodArray<z.ZodObject<{
|
50
|
+
title: z.ZodString;
|
51
|
+
link: z.ZodString;
|
52
|
+
snippet: z.ZodString;
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
54
|
+
link: string;
|
55
|
+
title: string;
|
56
|
+
snippet: string;
|
57
|
+
}, {
|
58
|
+
link: string;
|
59
|
+
title: string;
|
60
|
+
snippet: string;
|
61
|
+
}>, "many">;
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
63
|
+
results: {
|
64
|
+
link: string;
|
65
|
+
title: string;
|
66
|
+
snippet: string;
|
67
|
+
}[];
|
68
|
+
}, {
|
69
|
+
results: {
|
70
|
+
link: string;
|
71
|
+
title: string;
|
72
|
+
snippet: string;
|
73
|
+
}[];
|
74
|
+
}>;
|
75
|
+
constructor(options: {
|
76
|
+
name: NAME;
|
77
|
+
description: string;
|
78
|
+
execute(input: z.infer<typeof INPUT_SCHEMA>): Promise<z.infer<typeof OUTPUT_SCHEMA>>;
|
79
|
+
});
|
80
|
+
}
|
81
|
+
export {};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
import { Tool } from "./Tool.js";
|
3
|
+
const INPUT_SCHEMA = z.object({
|
4
|
+
query: z.string(),
|
5
|
+
});
|
6
|
+
const OUTPUT_SCHEMA = z.object({
|
7
|
+
results: z.array(z.object({
|
8
|
+
title: z.string(),
|
9
|
+
link: z.string().url(),
|
10
|
+
snippet: z.string(),
|
11
|
+
})),
|
12
|
+
});
|
13
|
+
/**
|
14
|
+
* @see https://serpapi.com/search-api
|
15
|
+
*/
|
16
|
+
export class WebSearchTool extends Tool {
|
17
|
+
constructor(options) {
|
18
|
+
super({
|
19
|
+
name: options.name,
|
20
|
+
description: options.description,
|
21
|
+
inputSchema: INPUT_SCHEMA,
|
22
|
+
outputSchema: OUTPUT_SCHEMA,
|
23
|
+
execute: options.execute,
|
24
|
+
});
|
25
|
+
}
|
26
|
+
}
|
27
|
+
// expose the schemas to library consumers:
|
28
|
+
Object.defineProperty(WebSearchTool, "INPUT_SCHEMA", {
|
29
|
+
enumerable: true,
|
30
|
+
configurable: true,
|
31
|
+
writable: true,
|
32
|
+
value: INPUT_SCHEMA
|
33
|
+
});
|
34
|
+
Object.defineProperty(WebSearchTool, "OUTPUT_SCHEMA", {
|
35
|
+
enumerable: true,
|
36
|
+
configurable: true,
|
37
|
+
writable: true,
|
38
|
+
value: OUTPUT_SCHEMA
|
39
|
+
});
|
package/tool/executeTool.d.ts
CHANGED
@@ -9,6 +9,9 @@ export type ExecuteToolMetadata = {
|
|
9
9
|
startEpochSeconds: number;
|
10
10
|
durationInMs: number;
|
11
11
|
};
|
12
|
+
/**
|
13
|
+
* `executeTool` directly executes a tool with the given parameters.
|
14
|
+
*/
|
12
15
|
export declare function executeTool<INPUT, OUTPUT>(tool: Tool<string, INPUT, OUTPUT>, input: INPUT, options: FunctionOptions<undefined> & {
|
13
16
|
fullResponse: true;
|
14
17
|
}): Promise<{
|
package/tool/index.cjs
CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./NoSuchToolError.cjs"), exports);
|
18
18
|
__exportStar(require("./Tool.cjs"), exports);
|
19
19
|
__exportStar(require("./ToolExecutionError.cjs"), exports);
|
20
|
+
__exportStar(require("./WebSearchTool.cjs"), exports);
|
20
21
|
__exportStar(require("./executeTool.cjs"), exports);
|
21
22
|
__exportStar(require("./useTool.cjs"), exports);
|
22
23
|
__exportStar(require("./useToolOrGenerateText.cjs"), exports);
|
package/tool/index.d.ts
CHANGED
package/tool/index.js
CHANGED