modelfusion 0.13.0 → 0.15.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 +16 -10
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +1 -1
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +1 -1
- package/model-function/Model.d.ts +2 -2
- package/model-function/generate-text/TextGenerationModel.d.ts +18 -18
- package/model-function/generate-text/generateText.cjs +2 -2
- package/model-function/generate-text/generateText.js +2 -2
- package/model-provider/cohere/CohereTextGenerationModel.cjs +19 -20
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +4 -9
- package/model-provider/cohere/CohereTextGenerationModel.js +19 -20
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +13 -18
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +4 -8
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +13 -18
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +16 -16
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +9 -14
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +16 -16
- package/model-provider/openai/OpenAITextGenerationModel.cjs +20 -18
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +4 -9
- package/model-provider/openai/OpenAITextGenerationModel.js +20 -18
- package/model-provider/openai/chat/OpenAIChatModel.cjs +15 -18
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +5 -8
- package/model-provider/openai/chat/OpenAIChatModel.js +15 -18
- package/package.json +3 -3
- package/prompt/{AlpacaPromptMapping.cjs → AlpacaPromptFormat.cjs} +6 -6
- package/prompt/{AlpacaPromptMapping.d.ts → AlpacaPromptFormat.d.ts} +3 -3
- package/prompt/{AlpacaPromptMapping.js → AlpacaPromptFormat.js} +4 -4
- package/prompt/{Llama2PromptMapping.cjs → Llama2PromptFormat.cjs} +13 -10
- package/prompt/Llama2PromptFormat.d.ts +13 -0
- package/prompt/{Llama2PromptMapping.js → Llama2PromptFormat.js} +10 -7
- package/prompt/{OpenAIChatPromptMapping.cjs → OpenAIChatPromptFormat.cjs} +15 -9
- package/prompt/OpenAIChatPromptFormat.d.ts +12 -0
- package/prompt/{OpenAIChatPromptMapping.js → OpenAIChatPromptFormat.js} +12 -6
- package/prompt/PromptFormat.d.ts +14 -0
- package/prompt/{PromptMappingTextGenerationModel.js → PromptFormatTextGenerationModel.cjs} +19 -28
- package/prompt/{PromptMappingTextGenerationModel.d.ts → PromptFormatTextGenerationModel.d.ts} +6 -9
- package/prompt/{PromptMappingTextGenerationModel.cjs → PromptFormatTextGenerationModel.js} +15 -32
- package/prompt/{TextPromptMapping.cjs → TextPromptFormat.cjs} +13 -10
- package/prompt/TextPromptFormat.d.ts +17 -0
- package/prompt/{TextPromptMapping.js → TextPromptFormat.js} +10 -7
- package/prompt/{VicunaPromptMapping.cjs → VicunaPromptFormat.cjs} +6 -6
- package/prompt/{VicunaPromptMapping.d.ts → VicunaPromptFormat.d.ts} +3 -3
- package/prompt/{VicunaPromptMapping.js → VicunaPromptFormat.js} +4 -4
- package/prompt/chat/trimChatPrompt.cjs +2 -2
- package/prompt/chat/trimChatPrompt.d.ts +1 -1
- package/prompt/chat/trimChatPrompt.js +2 -2
- package/prompt/index.cjs +7 -7
- package/prompt/index.d.ts +7 -7
- package/prompt/index.js +7 -7
- package/tool/WebSearchTool.cjs +7 -28
- package/tool/WebSearchTool.d.ts +6 -67
- package/tool/WebSearchTool.js +7 -28
- package/tool/executeTool.cjs +1 -0
- package/tool/executeTool.d.ts +5 -4
- package/tool/executeTool.js +1 -0
- package/prompt/Llama2PromptMapping.d.ts +0 -10
- package/prompt/OpenAIChatPromptMapping.d.ts +0 -6
- package/prompt/PromptMapping.d.ts +0 -7
- package/prompt/TextPromptMapping.d.ts +0 -14
- /package/prompt/{PromptMapping.cjs → PromptFormat.cjs} +0 -0
- /package/prompt/{PromptMapping.js → PromptFormat.js} +0 -0
package/prompt/index.cjs
CHANGED
@@ -14,14 +14,14 @@ 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("./
|
17
|
+
__exportStar(require("./AlpacaPromptFormat.cjs"), exports);
|
18
18
|
__exportStar(require("./InstructionPrompt.cjs"), exports);
|
19
|
-
__exportStar(require("./
|
20
|
-
__exportStar(require("./
|
21
|
-
__exportStar(require("./
|
22
|
-
__exportStar(require("./
|
23
|
-
__exportStar(require("./
|
24
|
-
__exportStar(require("./
|
19
|
+
__exportStar(require("./Llama2PromptFormat.cjs"), exports);
|
20
|
+
__exportStar(require("./OpenAIChatPromptFormat.cjs"), exports);
|
21
|
+
__exportStar(require("./PromptFormat.cjs"), exports);
|
22
|
+
__exportStar(require("./PromptFormatTextGenerationModel.cjs"), exports);
|
23
|
+
__exportStar(require("./TextPromptFormat.cjs"), exports);
|
24
|
+
__exportStar(require("./VicunaPromptFormat.cjs"), exports);
|
25
25
|
__exportStar(require("./chat/ChatPrompt.cjs"), exports);
|
26
26
|
__exportStar(require("./chat/trimChatPrompt.cjs"), exports);
|
27
27
|
__exportStar(require("./chat/validateChatPrompt.cjs"), exports);
|
package/prompt/index.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
export * from "./
|
1
|
+
export * from "./AlpacaPromptFormat.js";
|
2
2
|
export * from "./InstructionPrompt.js";
|
3
|
-
export * from "./
|
4
|
-
export * from "./
|
5
|
-
export * from "./
|
6
|
-
export * from "./
|
7
|
-
export * from "./
|
8
|
-
export * from "./
|
3
|
+
export * from "./Llama2PromptFormat.js";
|
4
|
+
export * from "./OpenAIChatPromptFormat.js";
|
5
|
+
export * from "./PromptFormat.js";
|
6
|
+
export * from "./PromptFormatTextGenerationModel.js";
|
7
|
+
export * from "./TextPromptFormat.js";
|
8
|
+
export * from "./VicunaPromptFormat.js";
|
9
9
|
export * from "./chat/ChatPrompt.js";
|
10
10
|
export * from "./chat/trimChatPrompt.js";
|
11
11
|
export * from "./chat/validateChatPrompt.js";
|
package/prompt/index.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
export * from "./
|
1
|
+
export * from "./AlpacaPromptFormat.js";
|
2
2
|
export * from "./InstructionPrompt.js";
|
3
|
-
export * from "./
|
4
|
-
export * from "./
|
5
|
-
export * from "./
|
6
|
-
export * from "./
|
7
|
-
export * from "./
|
8
|
-
export * from "./
|
3
|
+
export * from "./Llama2PromptFormat.js";
|
4
|
+
export * from "./OpenAIChatPromptFormat.js";
|
5
|
+
export * from "./PromptFormat.js";
|
6
|
+
export * from "./PromptFormatTextGenerationModel.js";
|
7
|
+
export * from "./TextPromptFormat.js";
|
8
|
+
export * from "./VicunaPromptFormat.js";
|
9
9
|
export * from "./chat/ChatPrompt.js";
|
10
10
|
export * from "./chat/trimChatPrompt.js";
|
11
11
|
export * from "./chat/validateChatPrompt.js";
|
package/tool/WebSearchTool.cjs
CHANGED
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WebSearchTool = void 0;
|
4
4
|
const zod_1 = require("zod");
|
5
5
|
const Tool_js_1 = require("./Tool.cjs");
|
6
|
-
const INPUT_SCHEMA = zod_1.z.object({
|
7
|
-
query: zod_1.z.string(),
|
8
|
-
});
|
9
6
|
const OUTPUT_SCHEMA = zod_1.z.object({
|
10
7
|
results: zod_1.z.array(zod_1.z.object({
|
11
8
|
title: zod_1.z.string(),
|
@@ -13,39 +10,21 @@ const OUTPUT_SCHEMA = zod_1.z.object({
|
|
13
10
|
snippet: zod_1.z.string(),
|
14
11
|
})),
|
15
12
|
});
|
13
|
+
// expose the schemas to library consumers:
|
14
|
+
const createInputSchema = (description) =>
|
15
|
+
// same structure, but with description:
|
16
|
+
zod_1.z.object({
|
17
|
+
query: zod_1.z.string().describe(description),
|
18
|
+
});
|
16
19
|
class WebSearchTool extends Tool_js_1.Tool {
|
17
20
|
constructor({ name, description, queryDescription = "Search query", execute, }) {
|
18
21
|
super({
|
19
22
|
name,
|
20
23
|
description,
|
21
|
-
inputSchema:
|
24
|
+
inputSchema: createInputSchema(queryDescription),
|
22
25
|
outputSchema: OUTPUT_SCHEMA,
|
23
26
|
execute,
|
24
27
|
});
|
25
|
-
Object.defineProperty(this, "outputSchema", {
|
26
|
-
enumerable: true,
|
27
|
-
configurable: true,
|
28
|
-
writable: true,
|
29
|
-
value: void 0
|
30
|
-
});
|
31
|
-
this.outputSchema = OUTPUT_SCHEMA;
|
32
28
|
}
|
33
29
|
}
|
34
30
|
exports.WebSearchTool = WebSearchTool;
|
35
|
-
// expose the schemas to library consumers:
|
36
|
-
Object.defineProperty(WebSearchTool, "createInputSchema", {
|
37
|
-
enumerable: true,
|
38
|
-
configurable: true,
|
39
|
-
writable: true,
|
40
|
-
value: (description) =>
|
41
|
-
// same structure, but with description:
|
42
|
-
zod_1.z.object({
|
43
|
-
query: zod_1.z.string().describe(description),
|
44
|
-
})
|
45
|
-
});
|
46
|
-
Object.defineProperty(WebSearchTool, "createOutputSchema", {
|
47
|
-
enumerable: true,
|
48
|
-
configurable: true,
|
49
|
-
writable: true,
|
50
|
-
value: () => OUTPUT_SCHEMA
|
51
|
-
});
|
package/tool/WebSearchTool.d.ts
CHANGED
@@ -1,80 +1,19 @@
|
|
1
|
-
import { z } from "zod";
|
2
1
|
import { Tool } from "./Tool.js";
|
3
|
-
|
4
|
-
query: z.ZodString;
|
5
|
-
}, "strip", z.ZodTypeAny, {
|
2
|
+
export type WebSearchToolInput = {
|
6
3
|
query: string;
|
7
|
-
}
|
8
|
-
|
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, {
|
4
|
+
};
|
5
|
+
export type WebSearchToolOutput = {
|
25
6
|
results: {
|
26
|
-
link: string;
|
27
7
|
title: string;
|
28
|
-
snippet: string;
|
29
|
-
}[];
|
30
|
-
}, {
|
31
|
-
results: {
|
32
8
|
link: string;
|
33
|
-
title: string;
|
34
9
|
snippet: string;
|
35
10
|
}[];
|
36
|
-
}
|
37
|
-
export declare class WebSearchTool<NAME extends string> extends Tool<NAME,
|
38
|
-
static readonly createInputSchema: (description: string) => z.ZodObject<{
|
39
|
-
query: z.ZodString;
|
40
|
-
}, "strip", z.ZodTypeAny, {
|
41
|
-
query: string;
|
42
|
-
}, {
|
43
|
-
query: string;
|
44
|
-
}>;
|
45
|
-
static readonly createOutputSchema: () => z.ZodObject<{
|
46
|
-
results: z.ZodArray<z.ZodObject<{
|
47
|
-
title: z.ZodString;
|
48
|
-
link: z.ZodString;
|
49
|
-
snippet: z.ZodString;
|
50
|
-
}, "strip", z.ZodTypeAny, {
|
51
|
-
link: string;
|
52
|
-
title: string;
|
53
|
-
snippet: string;
|
54
|
-
}, {
|
55
|
-
link: string;
|
56
|
-
title: string;
|
57
|
-
snippet: string;
|
58
|
-
}>, "many">;
|
59
|
-
}, "strip", z.ZodTypeAny, {
|
60
|
-
results: {
|
61
|
-
link: string;
|
62
|
-
title: string;
|
63
|
-
snippet: string;
|
64
|
-
}[];
|
65
|
-
}, {
|
66
|
-
results: {
|
67
|
-
link: string;
|
68
|
-
title: string;
|
69
|
-
snippet: string;
|
70
|
-
}[];
|
71
|
-
}>;
|
72
|
-
readonly outputSchema: typeof OUTPUT_SCHEMA;
|
11
|
+
};
|
12
|
+
export declare class WebSearchTool<NAME extends string> extends Tool<NAME, WebSearchToolInput, WebSearchToolOutput> {
|
73
13
|
constructor({ name, description, queryDescription, execute, }: {
|
74
14
|
name: NAME;
|
75
15
|
description: string;
|
76
16
|
queryDescription?: string;
|
77
|
-
execute(input:
|
17
|
+
execute(input: WebSearchToolInput): Promise<WebSearchToolOutput>;
|
78
18
|
});
|
79
19
|
}
|
80
|
-
export {};
|
package/tool/WebSearchTool.js
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import { Tool } from "./Tool.js";
|
3
|
-
const INPUT_SCHEMA = z.object({
|
4
|
-
query: z.string(),
|
5
|
-
});
|
6
3
|
const OUTPUT_SCHEMA = z.object({
|
7
4
|
results: z.array(z.object({
|
8
5
|
title: z.string(),
|
@@ -10,38 +7,20 @@ const OUTPUT_SCHEMA = z.object({
|
|
10
7
|
snippet: z.string(),
|
11
8
|
})),
|
12
9
|
});
|
10
|
+
// expose the schemas to library consumers:
|
11
|
+
const createInputSchema = (description) =>
|
12
|
+
// same structure, but with description:
|
13
|
+
z.object({
|
14
|
+
query: z.string().describe(description),
|
15
|
+
});
|
13
16
|
export class WebSearchTool extends Tool {
|
14
17
|
constructor({ name, description, queryDescription = "Search query", execute, }) {
|
15
18
|
super({
|
16
19
|
name,
|
17
20
|
description,
|
18
|
-
inputSchema:
|
21
|
+
inputSchema: createInputSchema(queryDescription),
|
19
22
|
outputSchema: OUTPUT_SCHEMA,
|
20
23
|
execute,
|
21
24
|
});
|
22
|
-
Object.defineProperty(this, "outputSchema", {
|
23
|
-
enumerable: true,
|
24
|
-
configurable: true,
|
25
|
-
writable: true,
|
26
|
-
value: void 0
|
27
|
-
});
|
28
|
-
this.outputSchema = OUTPUT_SCHEMA;
|
29
25
|
}
|
30
26
|
}
|
31
|
-
// expose the schemas to library consumers:
|
32
|
-
Object.defineProperty(WebSearchTool, "createInputSchema", {
|
33
|
-
enumerable: true,
|
34
|
-
configurable: true,
|
35
|
-
writable: true,
|
36
|
-
value: (description) =>
|
37
|
-
// same structure, but with description:
|
38
|
-
z.object({
|
39
|
-
query: z.string().describe(description),
|
40
|
-
})
|
41
|
-
});
|
42
|
-
Object.defineProperty(WebSearchTool, "createOutputSchema", {
|
43
|
-
enumerable: true,
|
44
|
-
configurable: true,
|
45
|
-
writable: true,
|
46
|
-
value: () => OUTPUT_SCHEMA
|
47
|
-
});
|
package/tool/executeTool.cjs
CHANGED
@@ -7,6 +7,7 @@ const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
|
|
7
7
|
const AbortError_js_1 = require("../util/api/AbortError.cjs");
|
8
8
|
const runSafe_js_1 = require("../util/runSafe.cjs");
|
9
9
|
const ToolExecutionError_js_1 = require("./ToolExecutionError.cjs");
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
10
11
|
async function executeTool(tool, input, options) {
|
11
12
|
const run = options?.run;
|
12
13
|
const eventSource = new RunFunctionEventSource_js_1.RunFunctionEventSource({
|
package/tool/executeTool.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { FunctionOptions } from "../model-function/FunctionOptions.js";
|
2
2
|
import { Tool } from "./Tool.js";
|
3
|
+
import { z } from "zod";
|
3
4
|
export type ExecuteToolMetadata = {
|
4
5
|
callId: string;
|
5
6
|
runId?: string;
|
@@ -12,12 +13,12 @@ export type ExecuteToolMetadata = {
|
|
12
13
|
/**
|
13
14
|
* `executeTool` directly executes a tool with the given parameters.
|
14
15
|
*/
|
15
|
-
export declare function executeTool<
|
16
|
+
export declare function executeTool<TOOL extends Tool<any, any, any>>(tool: TOOL, input: z.infer<TOOL["inputSchema"]>, options: FunctionOptions<undefined> & {
|
16
17
|
fullResponse: true;
|
17
18
|
}): Promise<{
|
18
|
-
output:
|
19
|
+
output: Awaited<ReturnType<TOOL["execute"]>>;
|
19
20
|
metadata: ExecuteToolMetadata;
|
20
21
|
}>;
|
21
|
-
export declare function executeTool<
|
22
|
+
export declare function executeTool<TOOL extends Tool<any, any, any>>(tool: TOOL, input: z.infer<TOOL["inputSchema"]>, options?: FunctionOptions<undefined> & {
|
22
23
|
fullResponse?: false;
|
23
|
-
}): Promise<
|
24
|
+
}): Promise<ReturnType<TOOL["execute"]>>;
|
package/tool/executeTool.js
CHANGED
@@ -4,6 +4,7 @@ import { startDurationMeasurement } from "../util/DurationMeasurement.js";
|
|
4
4
|
import { AbortError } from "../util/api/AbortError.js";
|
5
5
|
import { runSafe } from "../util/runSafe.js";
|
6
6
|
import { ToolExecutionError } from "./ToolExecutionError.js";
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
7
8
|
export async function executeTool(tool, input, options) {
|
8
9
|
const run = options?.run;
|
9
10
|
const eventSource = new RunFunctionEventSource({
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { PromptMapping } from "./PromptMapping.js";
|
2
|
-
import { InstructionPrompt } from "./InstructionPrompt.js";
|
3
|
-
import { ChatPrompt } from "./chat/ChatPrompt.js";
|
4
|
-
/**
|
5
|
-
* Maps an instruction prompt to the Llama2 prompt format.
|
6
|
-
*
|
7
|
-
* @see https://www.philschmid.de/llama-2#how-to-prompt-llama-2-chat
|
8
|
-
*/
|
9
|
-
export declare const InstructionToLlama2PromptMapping: () => PromptMapping<InstructionPrompt, string>;
|
10
|
-
export declare const ChatToLlama2PromptMapping: () => PromptMapping<ChatPrompt, string>;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import { OpenAIChatMessage } from "../model-provider/openai/chat/OpenAIChatMessage.js";
|
2
|
-
import { ChatPrompt } from "./chat/ChatPrompt.js";
|
3
|
-
import { InstructionPrompt } from "./InstructionPrompt.js";
|
4
|
-
import { PromptMapping } from "./PromptMapping.js";
|
5
|
-
export declare const InstructionToOpenAIChatPromptMapping: () => PromptMapping<InstructionPrompt, Array<OpenAIChatMessage>>;
|
6
|
-
export declare const ChatToOpenAIChatPromptMapping: () => PromptMapping<ChatPrompt, Array<OpenAIChatMessage>>;
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { PromptMapping } from "./PromptMapping.js";
|
2
|
-
import { InstructionPrompt } from "./InstructionPrompt.js";
|
3
|
-
import { ChatPrompt } from "./chat/ChatPrompt.js";
|
4
|
-
export declare const InstructionToTextPromptMapping: () => PromptMapping<InstructionPrompt, string>;
|
5
|
-
/**
|
6
|
-
* A mapping from a chat prompt to a text prompt.
|
7
|
-
*
|
8
|
-
* @param user The label of the user in the chat.
|
9
|
-
* @param ai The name of the AI in the chat.
|
10
|
-
*/
|
11
|
-
export declare const ChatToTextPromptMapping: ({ user, ai, }: {
|
12
|
-
user: string;
|
13
|
-
ai: string;
|
14
|
-
}) => PromptMapping<ChatPrompt, string>;
|
File without changes
|
File without changes
|