modelfusion 0.125.0 → 0.126.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +9 -9
- package/core/FunctionEvent.d.ts +3 -3
- package/package.json +1 -1
- package/tool/index.cjs +2 -2
- package/tool/index.d.ts +2 -2
- package/tool/index.js +2 -2
- package/tool/run-tool/RunToolEvent.d.ts +7 -0
- package/tool/{use-tool → run-tool}/index.cjs +2 -2
- package/tool/run-tool/index.d.ts +2 -0
- package/tool/run-tool/index.js +2 -0
- package/tool/{use-tool/useTool.cjs → run-tool/runTool.cjs} +5 -5
- package/tool/{use-tool/useTool.d.ts → run-tool/runTool.d.ts} +2 -2
- package/tool/{use-tool/useTool.js → run-tool/runTool.js} +3 -3
- package/tool/run-tools/RunToolsEvent.d.ts +7 -0
- package/tool/{use-tools → run-tools}/index.cjs +2 -2
- package/tool/run-tools/index.d.ts +2 -0
- package/tool/run-tools/index.js +2 -0
- package/tool/{use-tools/useTools.cjs → run-tools/runTools.cjs} +4 -4
- package/tool/{use-tools/useTools.d.ts → run-tools/runTools.d.ts} +1 -1
- package/tool/{use-tools/useTools.js → run-tools/runTools.js} +2 -2
- package/tool/use-tool/UseToolEvent.d.ts +0 -7
- package/tool/use-tool/index.d.ts +0 -2
- package/tool/use-tool/index.js +0 -2
- package/tool/use-tools/UseToolsEvent.d.ts +0 -7
- package/tool/use-tools/index.d.ts +0 -2
- package/tool/use-tools/index.js +0 -2
- /package/tool/{use-tool/UseToolEvent.cjs → run-tool/RunToolEvent.cjs} +0 -0
- /package/tool/{use-tool/UseToolEvent.js → run-tool/RunToolEvent.js} +0 -0
- /package/tool/{use-tools/UseToolsEvent.cjs → run-tools/RunToolsEvent.cjs} +0 -0
- /package/tool/{use-tools/UseToolsEvent.js → run-tools/RunToolsEvent.js} +0 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
@@ -372,12 +372,12 @@ Tools are functions (and associated metadata) that can be executed by an AI mode
|
|
372
372
|
|
373
373
|
ModelFusion offers several tools out-of-the-box: [Math.js](https://modelfusion.dev/guide/tools/available-tools/mathjs), [MediaWiki Search](https://modelfusion.dev/guide/tools/available-tools/mediawiki-search), [SerpAPI](https://modelfusion.dev/guide/tools/available-tools/serpapi), [Google Custom Search](https://modelfusion.dev/guide/tools/available-tools/google-custom-search). You can also create [custom tools](https://modelfusion.dev/guide/tools).
|
374
374
|
|
375
|
-
#### [
|
375
|
+
#### [runTool](https://modelfusion.dev/guide/tools/run-tool)
|
376
376
|
|
377
|
-
With `
|
377
|
+
With `runTool`, you can ask a tool-compatible language model (e.g. OpenAI chat) to invoke a single tool. `runTool` first generates a tool call and then executes the tool with the arguments.
|
378
378
|
|
379
379
|
```ts
|
380
|
-
const { tool, toolCall, args, ok, result } = await
|
380
|
+
const { tool, toolCall, args, ok, result } = await runTool({
|
381
381
|
model: openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }),
|
382
382
|
too: calculator,
|
383
383
|
prompt: [openai.ChatMessage.user("What's fourteen times twelve?")],
|
@@ -390,12 +390,12 @@ console.log(`Ok:`, ok);
|
|
390
390
|
console.log(`Result or Error:`, result);
|
391
391
|
```
|
392
392
|
|
393
|
-
#### [
|
393
|
+
#### [runTools](https://modelfusion.dev/guide/tools/run-tools)
|
394
394
|
|
395
|
-
With `
|
395
|
+
With `runTools`, you can ask a language model to generate several tool calls as well as text. The model will choose which tools (if any) should be called with which arguments. Both the text and the tool calls are optional. This function executes the tools.
|
396
396
|
|
397
397
|
```ts
|
398
|
-
const { text, toolResults } = await
|
398
|
+
const { text, toolResults } = await runTools({
|
399
399
|
model: openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }),
|
400
400
|
tools: [calculator /* ... */],
|
401
401
|
prompt: [openai.ChatMessage.user("What's fourteen times twelve?")],
|
@@ -404,7 +404,7 @@ const { text, toolResults } = await useTools({
|
|
404
404
|
|
405
405
|
#### [Agent Loop](https://modelfusion.dev/guide/tools/agent-loop)
|
406
406
|
|
407
|
-
You can use `
|
407
|
+
You can use `runTools` to implement an agent loop that responds to user messages and executes tools. [Learn more](https://modelfusion.dev/guide/tools/agent-loop).
|
408
408
|
|
409
409
|
### [Vector Indices](https://modelfusion.dev/guide/vector-index)
|
410
410
|
|
@@ -580,8 +580,8 @@ modelfusion.setLogFormat("detailed-object"); // log full events
|
|
580
580
|
- [Embed Value](https://modelfusion.dev/guide/function/embed)
|
581
581
|
- [Classify Value](https://modelfusion.dev/guide/function/classify)
|
582
582
|
- [Tools](https://modelfusion.dev/guide/tools)
|
583
|
-
- [Use Tool](https://modelfusion.dev/guide/tools/
|
584
|
-
- [Use Tools](https://modelfusion.dev/guide/tools/
|
583
|
+
- [Use Tool](https://modelfusion.dev/guide/tools/run-tool)
|
584
|
+
- [Use Tools](https://modelfusion.dev/guide/tools/run-tools)
|
585
585
|
- [Agent Loop](https://modelfusion.dev/guide/tools/agent-loop)
|
586
586
|
- [Available Tools](https://modelfusion.dev/guide/tools/available-tools/)
|
587
587
|
- [Custom Tools](https://modelfusion.dev/guide/tools/custom-tools)
|
package/core/FunctionEvent.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
|
2
2
|
import { RetrieveFinishedEvent, RetrieveStartedEvent } from "../retriever/RetrieveEvent.js";
|
3
3
|
import { ExecuteToolFinishedEvent, ExecuteToolStartedEvent } from "../tool/execute-tool/ExecuteToolEvent.js";
|
4
|
-
import {
|
5
|
-
import {
|
4
|
+
import { runToolFinishedEvent, runToolStartedEvent } from "../tool/run-tool/RunToolEvent.js";
|
5
|
+
import { runToolsFinishedEvent, runToolsStartedEvent } from "../tool/run-tools/RunToolsEvent.js";
|
6
6
|
import { UpsertIntoVectorIndexFinishedEvent, UpsertIntoVectorIndexStartedEvent } from "../vector-index/UpsertIntoVectorIndexEvent.js";
|
7
7
|
import { ExecuteFunctionFinishedEvent, ExecuteFunctionStartedEvent } from "./ExecuteFunctionEvent.js";
|
8
8
|
import { ExtensionFunctionFinishedEvent, ExtensionFunctionStartedEvent } from "./ExtensionFunctionEvent.js";
|
@@ -82,4 +82,4 @@ export interface BaseFunctionFinishedEvent extends BaseFunctionEvent {
|
|
82
82
|
*/
|
83
83
|
result: BaseFunctionFinishedEventResult;
|
84
84
|
}
|
85
|
-
export type FunctionEvent = ExecuteFunctionStartedEvent | ExecuteFunctionFinishedEvent | ExecuteToolStartedEvent | ExecuteToolFinishedEvent | ExtensionFunctionStartedEvent | ExtensionFunctionFinishedEvent | ModelCallStartedEvent | ModelCallFinishedEvent | RetrieveStartedEvent | RetrieveFinishedEvent | UpsertIntoVectorIndexStartedEvent | UpsertIntoVectorIndexFinishedEvent |
|
85
|
+
export type FunctionEvent = ExecuteFunctionStartedEvent | ExecuteFunctionFinishedEvent | ExecuteToolStartedEvent | ExecuteToolFinishedEvent | ExtensionFunctionStartedEvent | ExtensionFunctionFinishedEvent | ModelCallStartedEvent | ModelCallFinishedEvent | RetrieveStartedEvent | RetrieveFinishedEvent | UpsertIntoVectorIndexStartedEvent | UpsertIntoVectorIndexFinishedEvent | runToolStartedEvent | runToolFinishedEvent | runToolsStartedEvent | runToolsFinishedEvent;
|
package/package.json
CHANGED
package/tool/index.cjs
CHANGED
@@ -27,5 +27,5 @@ __exportStar(require("./WebSearchTool.cjs"), exports);
|
|
27
27
|
__exportStar(require("./execute-tool/index.cjs"), exports);
|
28
28
|
__exportStar(require("./generate-tool-call/index.cjs"), exports);
|
29
29
|
__exportStar(require("./generate-tool-calls/index.cjs"), exports);
|
30
|
-
__exportStar(require("./
|
31
|
-
__exportStar(require("./
|
30
|
+
__exportStar(require("./run-tool/index.cjs"), exports);
|
31
|
+
__exportStar(require("./run-tools/index.cjs"), exports);
|
package/tool/index.d.ts
CHANGED
@@ -11,5 +11,5 @@ export * from "./WebSearchTool.js";
|
|
11
11
|
export * from "./execute-tool/index.js";
|
12
12
|
export * from "./generate-tool-call/index.js";
|
13
13
|
export * from "./generate-tool-calls/index.js";
|
14
|
-
export * from "./
|
15
|
-
export * from "./
|
14
|
+
export * from "./run-tool/index.js";
|
15
|
+
export * from "./run-tools/index.js";
|
package/tool/index.js
CHANGED
@@ -11,5 +11,5 @@ export * from "./WebSearchTool.js";
|
|
11
11
|
export * from "./execute-tool/index.js";
|
12
12
|
export * from "./generate-tool-call/index.js";
|
13
13
|
export * from "./generate-tool-calls/index.js";
|
14
|
-
export * from "./
|
15
|
-
export * from "./
|
14
|
+
export * from "./run-tool/index.js";
|
15
|
+
export * from "./run-tools/index.js";
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../../core/FunctionEvent.js";
|
2
|
+
export interface runToolStartedEvent extends BaseFunctionStartedEvent {
|
3
|
+
functionType: "run-tool";
|
4
|
+
}
|
5
|
+
export interface runToolFinishedEvent extends BaseFunctionFinishedEvent {
|
6
|
+
functionType: "run-tool";
|
7
|
+
}
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./
|
18
|
-
__exportStar(require("./
|
17
|
+
__exportStar(require("./RunToolEvent.cjs"), exports);
|
18
|
+
__exportStar(require("./runTool.cjs"), exports);
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.runTool = void 0;
|
4
4
|
const executeFunctionCall_js_1 = require("../../core/executeFunctionCall.cjs");
|
5
5
|
const safeExecuteToolCall_js_1 = require("../execute-tool/safeExecuteToolCall.cjs");
|
6
6
|
const generateToolCall_js_1 = require("../generate-tool-call/generateToolCall.cjs");
|
7
7
|
/**
|
8
|
-
* `
|
8
|
+
* `runTool` uses `generateToolCall` to generate parameters for a tool and
|
9
9
|
* then executes the tool with the parameters using `executeTool`.
|
10
10
|
*
|
11
11
|
* @returns The result contains the name of the tool (`tool` property),
|
@@ -15,7 +15,7 @@ const generateToolCall_js_1 = require("../generate-tool-call/generateToolCall.cj
|
|
15
15
|
* @see {@link generateToolCall}
|
16
16
|
* @see {@link executeTool}
|
17
17
|
*/
|
18
|
-
async function
|
18
|
+
async function runTool({ model, tool, prompt, ...options }) {
|
19
19
|
// Note: PROMPT must not be a function.
|
20
20
|
const expandedPrompt = typeof prompt === "function"
|
21
21
|
? prompt(tool)
|
@@ -23,8 +23,8 @@ async function useTool({ model, tool, prompt, ...options }) {
|
|
23
23
|
return (0, executeFunctionCall_js_1.executeFunctionCall)({
|
24
24
|
options,
|
25
25
|
input: expandedPrompt,
|
26
|
-
functionType: "
|
26
|
+
functionType: "run-tool",
|
27
27
|
execute: async (options) => (0, safeExecuteToolCall_js_1.safeExecuteToolCall)(tool, await (0, generateToolCall_js_1.generateToolCall)({ model, tool, prompt: expandedPrompt, ...options }), options),
|
28
28
|
});
|
29
29
|
}
|
30
|
-
exports.
|
30
|
+
exports.runTool = runTool;
|
@@ -3,7 +3,7 @@ import { Tool } from "../Tool.js";
|
|
3
3
|
import { ToolCallResult } from "../ToolCallResult.js";
|
4
4
|
import { ToolCallGenerationModel, ToolCallGenerationModelSettings } from "../generate-tool-call/ToolCallGenerationModel.js";
|
5
5
|
/**
|
6
|
-
* `
|
6
|
+
* `runTool` uses `generateToolCall` to generate parameters for a tool and
|
7
7
|
* then executes the tool with the parameters using `executeTool`.
|
8
8
|
*
|
9
9
|
* @returns The result contains the name of the tool (`tool` property),
|
@@ -13,7 +13,7 @@ import { ToolCallGenerationModel, ToolCallGenerationModelSettings } from "../gen
|
|
13
13
|
* @see {@link generateToolCall}
|
14
14
|
* @see {@link executeTool}
|
15
15
|
*/
|
16
|
-
export declare function
|
16
|
+
export declare function runTool<PROMPT, TOOL extends Tool<string, any, any>>({ model, tool, prompt, ...options }: {
|
17
17
|
model: ToolCallGenerationModel<PROMPT, ToolCallGenerationModelSettings>;
|
18
18
|
tool: TOOL;
|
19
19
|
prompt: PROMPT | ((tool: TOOL) => PROMPT);
|
@@ -2,7 +2,7 @@ import { executeFunctionCall } from "../../core/executeFunctionCall.js";
|
|
2
2
|
import { safeExecuteToolCall } from "../execute-tool/safeExecuteToolCall.js";
|
3
3
|
import { generateToolCall } from "../generate-tool-call/generateToolCall.js";
|
4
4
|
/**
|
5
|
-
* `
|
5
|
+
* `runTool` uses `generateToolCall` to generate parameters for a tool and
|
6
6
|
* then executes the tool with the parameters using `executeTool`.
|
7
7
|
*
|
8
8
|
* @returns The result contains the name of the tool (`tool` property),
|
@@ -12,7 +12,7 @@ import { generateToolCall } from "../generate-tool-call/generateToolCall.js";
|
|
12
12
|
* @see {@link generateToolCall}
|
13
13
|
* @see {@link executeTool}
|
14
14
|
*/
|
15
|
-
export async function
|
15
|
+
export async function runTool({ model, tool, prompt, ...options }) {
|
16
16
|
// Note: PROMPT must not be a function.
|
17
17
|
const expandedPrompt = typeof prompt === "function"
|
18
18
|
? prompt(tool)
|
@@ -20,7 +20,7 @@ export async function useTool({ model, tool, prompt, ...options }) {
|
|
20
20
|
return executeFunctionCall({
|
21
21
|
options,
|
22
22
|
input: expandedPrompt,
|
23
|
-
functionType: "
|
23
|
+
functionType: "run-tool",
|
24
24
|
execute: async (options) => safeExecuteToolCall(tool, await generateToolCall({ model, tool, prompt: expandedPrompt, ...options }), options),
|
25
25
|
});
|
26
26
|
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../../core/FunctionEvent.js";
|
2
|
+
export interface runToolsStartedEvent extends BaseFunctionStartedEvent {
|
3
|
+
functionType: "run-tools";
|
4
|
+
}
|
5
|
+
export interface runToolsFinishedEvent extends BaseFunctionFinishedEvent {
|
6
|
+
functionType: "run-tools";
|
7
|
+
}
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./
|
18
|
-
__exportStar(require("./
|
17
|
+
__exportStar(require("./RunToolsEvent.cjs"), exports);
|
18
|
+
__exportStar(require("./runTools.cjs"), exports);
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.runTools = void 0;
|
4
4
|
const executeFunctionCall_js_1 = require("../../core/executeFunctionCall.cjs");
|
5
5
|
const ToolCallError_js_1 = require("../ToolCallError.cjs");
|
6
6
|
const safeExecuteToolCall_js_1 = require("../execute-tool/safeExecuteToolCall.cjs");
|
7
7
|
const generateToolCalls_js_1 = require("../generate-tool-calls/generateToolCalls.cjs");
|
8
|
-
async function
|
8
|
+
async function runTools({ model, tools, prompt, ...options }) {
|
9
9
|
// Note: PROMPT must not be a function.
|
10
10
|
const expandedPrompt = typeof prompt === "function"
|
11
11
|
? prompt(tools)
|
@@ -13,7 +13,7 @@ async function useTools({ model, tools, prompt, ...options }) {
|
|
13
13
|
return (0, executeFunctionCall_js_1.executeFunctionCall)({
|
14
14
|
options,
|
15
15
|
input: expandedPrompt,
|
16
|
-
functionType: "
|
16
|
+
functionType: "run-tools",
|
17
17
|
execute: async (options) => {
|
18
18
|
const modelResponse = await (0, generateToolCalls_js_1.generateToolCalls)({
|
19
19
|
model,
|
@@ -51,4 +51,4 @@ async function useTools({ model, tools, prompt, ...options }) {
|
|
51
51
|
},
|
52
52
|
});
|
53
53
|
}
|
54
|
-
exports.
|
54
|
+
exports.runTools = runTools;
|
@@ -11,7 +11,7 @@ type ToToolCallUnion<T> = {
|
|
11
11
|
[KEY in StringKeys<T>]: T[KEY] extends Tool<any, infer PARAMETERS, infer OUTPUT> ? ToolCallResult<KEY, PARAMETERS, OUTPUT> : never;
|
12
12
|
}[StringKeys<T>];
|
13
13
|
type ToOutputValue<TOOLS extends ToolArray<Tool<any, any, any>[]>> = ToToolCallUnion<ToToolMap<TOOLS>>;
|
14
|
-
export declare function
|
14
|
+
export declare function runTools<PROMPT, TOOLS extends Array<Tool<any, any, any>>>({ model, tools, prompt, ...options }: {
|
15
15
|
model: ToolCallsGenerationModel<PROMPT, ToolCallsGenerationModelSettings>;
|
16
16
|
tools: TOOLS;
|
17
17
|
prompt: PROMPT | ((tools: TOOLS) => PROMPT);
|
@@ -2,7 +2,7 @@ import { executeFunctionCall } from "../../core/executeFunctionCall.js";
|
|
2
2
|
import { ToolCallError } from "../ToolCallError.js";
|
3
3
|
import { safeExecuteToolCall } from "../execute-tool/safeExecuteToolCall.js";
|
4
4
|
import { generateToolCalls } from "../generate-tool-calls/generateToolCalls.js";
|
5
|
-
export async function
|
5
|
+
export async function runTools({ model, tools, prompt, ...options }) {
|
6
6
|
// Note: PROMPT must not be a function.
|
7
7
|
const expandedPrompt = typeof prompt === "function"
|
8
8
|
? prompt(tools)
|
@@ -10,7 +10,7 @@ export async function useTools({ model, tools, prompt, ...options }) {
|
|
10
10
|
return executeFunctionCall({
|
11
11
|
options,
|
12
12
|
input: expandedPrompt,
|
13
|
-
functionType: "
|
13
|
+
functionType: "run-tools",
|
14
14
|
execute: async (options) => {
|
15
15
|
const modelResponse = await generateToolCalls({
|
16
16
|
model,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../../core/FunctionEvent.js";
|
2
|
-
export interface UseToolStartedEvent extends BaseFunctionStartedEvent {
|
3
|
-
functionType: "use-tool";
|
4
|
-
}
|
5
|
-
export interface UseToolFinishedEvent extends BaseFunctionFinishedEvent {
|
6
|
-
functionType: "use-tool";
|
7
|
-
}
|
package/tool/use-tool/index.d.ts
DELETED
package/tool/use-tool/index.js
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../../core/FunctionEvent.js";
|
2
|
-
export interface useToolsStartedEvent extends BaseFunctionStartedEvent {
|
3
|
-
functionType: "use-tools";
|
4
|
-
}
|
5
|
-
export interface useToolsFinishedEvent extends BaseFunctionFinishedEvent {
|
6
|
-
functionType: "use-tools";
|
7
|
-
}
|
package/tool/use-tools/index.js
DELETED
File without changes
|
File without changes
|
File without changes
|
File without changes
|