modelfusion 0.7.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/README.md +14 -4
- package/composed-function/index.cjs +0 -3
- package/composed-function/index.d.ts +0 -3
- package/composed-function/index.js +0 -3
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/model-function/Model.d.ts +2 -2
- package/model-function/ModelCallEvent.d.ts +4 -6
- package/model-function/SuccessfulModelCall.cjs +6 -3
- package/model-function/SuccessfulModelCall.d.ts +3 -3
- package/model-function/SuccessfulModelCall.js +6 -3
- package/model-function/executeCall.cjs +6 -6
- package/model-function/executeCall.js +6 -6
- package/model-function/generate-json/JsonGenerationEvent.d.ts +2 -2
- package/model-function/generate-json/generateJsonOrText.cjs +4 -4
- package/model-function/generate-json/generateJsonOrText.js +4 -4
- package/model-function/generate-text/streamText.cjs +7 -7
- package/model-function/generate-text/streamText.js +7 -7
- package/model-function/index.cjs +1 -1
- package/model-function/index.d.ts +1 -1
- package/model-function/index.js +1 -1
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
- package/model-provider/openai/chat/OpenAIChatPrompt.d.ts +1 -1
- package/package.json +1 -1
- package/run/ConsoleLogger.cjs +2 -2
- package/run/ConsoleLogger.d.ts +5 -5
- package/run/ConsoleLogger.js +2 -2
- package/run/DefaultRun.cjs +7 -7
- package/run/DefaultRun.d.ts +6 -6
- package/run/DefaultRun.js +7 -7
- package/run/Run.d.ts +2 -2
- package/run/RunFunction.d.ts +0 -4
- package/run/RunFunctionEvent.d.ts +12 -0
- package/{model-function/ModelCallEventSource.cjs → run/RunFunctionEventSource.cjs} +7 -7
- package/run/RunFunctionEventSource.d.ts +13 -0
- package/{model-function/ModelCallEventSource.js → run/RunFunctionEventSource.js} +5 -5
- package/run/RunFunctionObserver.cjs +2 -0
- package/run/RunFunctionObserver.d.ts +5 -0
- package/run/RunFunctionObserver.js +1 -0
- package/run/index.cjs +3 -0
- package/run/index.d.ts +3 -0
- package/run/index.js +3 -0
- package/tool/ExecuteToolEvent.cjs +2 -0
- package/tool/ExecuteToolEvent.d.ts +22 -0
- package/tool/ExecuteToolEvent.js +1 -0
- package/{composed-function/use-tool → tool}/Tool.cjs +31 -0
- package/tool/Tool.d.ts +42 -0
- package/tool/Tool.js +70 -0
- package/tool/ToolExecutionError.cjs +31 -0
- package/tool/ToolExecutionError.d.ts +11 -0
- package/tool/ToolExecutionError.js +27 -0
- package/tool/WebSearchTool.cjs +43 -0
- package/tool/WebSearchTool.d.ts +81 -0
- package/tool/WebSearchTool.js +39 -0
- package/tool/executeTool.cjs +79 -0
- package/tool/executeTool.d.ts +23 -0
- package/tool/executeTool.js +75 -0
- package/tool/index.cjs +23 -0
- package/tool/index.d.ts +7 -0
- package/tool/index.js +7 -0
- package/tool/useTool.cjs +33 -0
- package/tool/useTool.d.ts +15 -0
- package/tool/useTool.js +29 -0
- package/tool/useToolOrGenerateText.cjs +38 -0
- package/{composed-function/use-tool/useTool.d.ts → tool/useToolOrGenerateText.d.ts} +2 -15
- package/tool/useToolOrGenerateText.js +34 -0
- package/composed-function/use-tool/Tool.d.ts +0 -15
- package/composed-function/use-tool/Tool.js +0 -39
- package/composed-function/use-tool/useTool.cjs +0 -62
- package/composed-function/use-tool/useTool.js +0 -57
- package/model-function/ModelCallEventSource.d.ts +0 -13
- package/model-function/ModelCallObserver.d.ts +0 -5
- /package/{model-function/ModelCallObserver.cjs → run/RunFunctionEvent.cjs} +0 -0
- /package/{model-function/ModelCallObserver.js → run/RunFunctionEvent.js} +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.cjs +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.d.ts +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.js +0 -0
@@ -1,57 +0,0 @@
|
|
1
|
-
import { generateJson } from "../../model-function/generate-json/generateJson.js";
|
2
|
-
import { generateJsonOrText } from "../../model-function/generate-json/generateJsonOrText.js";
|
3
|
-
import { NoSuchToolError } from "./NoSuchToolError.js";
|
4
|
-
// In this file, using 'any' is required to allow for flexibility in the inputs. The actual types are
|
5
|
-
// retrieved through lookups such as TOOL["name"], such that any does not affect any client.
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
7
|
-
/**
|
8
|
-
* `useTool` uses `generateJson` to generate parameters for a tool and then executes the tool with the parameters.
|
9
|
-
*
|
10
|
-
* @returns The result contains the name of the tool (`tool` property),
|
11
|
-
* the parameters (`parameters` property, typed),
|
12
|
-
* and the result of the tool execution (`result` property, typed).
|
13
|
-
*/
|
14
|
-
export async function useTool(model, tool, prompt, options) {
|
15
|
-
const { value } = await generateJson(model, {
|
16
|
-
name: tool.name,
|
17
|
-
description: tool.description,
|
18
|
-
schema: tool.inputSchema,
|
19
|
-
}, () => prompt(tool), {
|
20
|
-
...(options ?? {}),
|
21
|
-
fullResponse: true,
|
22
|
-
});
|
23
|
-
return {
|
24
|
-
tool: tool.name,
|
25
|
-
parameters: value,
|
26
|
-
result: await tool.execute(value),
|
27
|
-
};
|
28
|
-
}
|
29
|
-
export async function useToolOrGenerateText(model, tools, prompt, options) {
|
30
|
-
const expandedPrompt = prompt(tools);
|
31
|
-
const modelResponse = await generateJsonOrText(model, tools.map((tool) => ({
|
32
|
-
name: tool.name,
|
33
|
-
description: tool.description,
|
34
|
-
schema: tool.inputSchema,
|
35
|
-
})), () => expandedPrompt, options);
|
36
|
-
const { schema, text } = modelResponse;
|
37
|
-
if (schema == null) {
|
38
|
-
return {
|
39
|
-
tool: null,
|
40
|
-
parameters: null,
|
41
|
-
result: null,
|
42
|
-
text,
|
43
|
-
};
|
44
|
-
}
|
45
|
-
const tool = tools.find((tool) => tool.name === schema);
|
46
|
-
if (tool == null) {
|
47
|
-
throw new NoSuchToolError(schema.toString());
|
48
|
-
}
|
49
|
-
const toolParameters = modelResponse.value;
|
50
|
-
const result = await tool.execute(toolParameters);
|
51
|
-
return {
|
52
|
-
tool: schema,
|
53
|
-
result,
|
54
|
-
parameters: toolParameters,
|
55
|
-
text: text, // string | null is the expected value here
|
56
|
-
};
|
57
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { ErrorHandler } from "../util/ErrorHandler.js";
|
2
|
-
import { ModelCallFinishedEvent, ModelCallStartedEvent } from "./ModelCallEvent.js";
|
3
|
-
import { ModelCallObserver } from "./ModelCallObserver.js";
|
4
|
-
export declare class ModelCallEventSource {
|
5
|
-
readonly observers: ModelCallObserver[];
|
6
|
-
readonly errorHandler: ErrorHandler;
|
7
|
-
constructor({ observers, errorHandler, }: {
|
8
|
-
observers: ModelCallObserver[];
|
9
|
-
errorHandler?: ErrorHandler;
|
10
|
-
});
|
11
|
-
notifyModelCallStarted(event: ModelCallStartedEvent): void;
|
12
|
-
notifyModelCallFinished(event: ModelCallFinishedEvent): void;
|
13
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|