modelfusion 0.13.0 → 0.14.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.
Files changed (55) hide show
  1. package/README.md +5 -5
  2. package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
  3. package/model-provider/cohere/CohereTextGenerationModel.cjs +5 -5
  4. package/model-provider/cohere/CohereTextGenerationModel.d.ts +3 -3
  5. package/model-provider/cohere/CohereTextGenerationModel.js +5 -5
  6. package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +4 -4
  7. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +3 -3
  8. package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +4 -4
  9. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +5 -5
  10. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +3 -3
  11. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +5 -5
  12. package/model-provider/openai/OpenAITextGenerationModel.cjs +5 -5
  13. package/model-provider/openai/OpenAITextGenerationModel.d.ts +3 -3
  14. package/model-provider/openai/OpenAITextGenerationModel.js +5 -5
  15. package/model-provider/openai/chat/OpenAIChatModel.cjs +5 -5
  16. package/model-provider/openai/chat/OpenAIChatModel.d.ts +3 -3
  17. package/model-provider/openai/chat/OpenAIChatModel.js +5 -5
  18. package/package.json +1 -1
  19. package/prompt/{AlpacaPromptMapping.cjs → AlpacaPromptFormat.cjs} +5 -5
  20. package/prompt/{AlpacaPromptMapping.d.ts → AlpacaPromptFormat.d.ts} +3 -3
  21. package/prompt/{AlpacaPromptMapping.js → AlpacaPromptFormat.js} +3 -3
  22. package/prompt/{Llama2PromptMapping.cjs → Llama2PromptFormat.cjs} +11 -8
  23. package/prompt/Llama2PromptFormat.d.ts +13 -0
  24. package/prompt/{Llama2PromptMapping.js → Llama2PromptFormat.js} +8 -5
  25. package/prompt/{OpenAIChatPromptMapping.cjs → OpenAIChatPromptFormat.cjs} +13 -7
  26. package/prompt/OpenAIChatPromptFormat.d.ts +12 -0
  27. package/prompt/{OpenAIChatPromptMapping.js → OpenAIChatPromptFormat.js} +10 -4
  28. package/prompt/PromptFormat.d.ts +14 -0
  29. package/prompt/{PromptMappingTextGenerationModel.cjs → PromptFormatTextGenerationModel.cjs} +19 -19
  30. package/prompt/{PromptMappingTextGenerationModel.d.ts → PromptFormatTextGenerationModel.d.ts} +6 -6
  31. package/prompt/{PromptMappingTextGenerationModel.js → PromptFormatTextGenerationModel.js} +17 -17
  32. package/prompt/{TextPromptMapping.cjs → TextPromptFormat.cjs} +11 -8
  33. package/prompt/TextPromptFormat.d.ts +17 -0
  34. package/prompt/{TextPromptMapping.js → TextPromptFormat.js} +8 -5
  35. package/prompt/{VicunaPromptMapping.cjs → VicunaPromptFormat.cjs} +5 -5
  36. package/prompt/{VicunaPromptMapping.d.ts → VicunaPromptFormat.d.ts} +3 -3
  37. package/prompt/{VicunaPromptMapping.js → VicunaPromptFormat.js} +3 -3
  38. package/prompt/chat/trimChatPrompt.cjs +1 -1
  39. package/prompt/chat/trimChatPrompt.d.ts +1 -1
  40. package/prompt/chat/trimChatPrompt.js +1 -1
  41. package/prompt/index.cjs +7 -7
  42. package/prompt/index.d.ts +7 -7
  43. package/prompt/index.js +7 -7
  44. package/tool/WebSearchTool.cjs +7 -28
  45. package/tool/WebSearchTool.d.ts +6 -67
  46. package/tool/WebSearchTool.js +7 -28
  47. package/tool/executeTool.cjs +1 -0
  48. package/tool/executeTool.d.ts +5 -4
  49. package/tool/executeTool.js +1 -0
  50. package/prompt/Llama2PromptMapping.d.ts +0 -10
  51. package/prompt/OpenAIChatPromptMapping.d.ts +0 -6
  52. package/prompt/PromptMapping.d.ts +0 -7
  53. package/prompt/TextPromptMapping.d.ts +0 -14
  54. /package/prompt/{PromptMapping.cjs → PromptFormat.cjs} +0 -0
  55. /package/prompt/{PromptMapping.js → PromptFormat.js} +0 -0
@@ -1,80 +1,19 @@
1
- import { z } from "zod";
2
1
  import { Tool } from "./Tool.js";
3
- declare const INPUT_SCHEMA: z.ZodObject<{
4
- query: z.ZodString;
5
- }, "strip", z.ZodTypeAny, {
2
+ export type WebSearchToolInput = {
6
3
  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, {
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, z.infer<typeof INPUT_SCHEMA>, z.infer<typeof OUTPUT_SCHEMA>> {
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: z.infer<typeof INPUT_SCHEMA>): Promise<z.infer<typeof OUTPUT_SCHEMA>>;
17
+ execute(input: WebSearchToolInput): Promise<WebSearchToolOutput>;
78
18
  });
79
19
  }
80
- export {};
@@ -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: WebSearchTool.createInputSchema(queryDescription),
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
- });
@@ -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({
@@ -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<INPUT, OUTPUT>(tool: Tool<string, INPUT, OUTPUT>, input: INPUT, options: FunctionOptions<undefined> & {
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: OUTPUT;
19
+ output: Awaited<ReturnType<TOOL["execute"]>>;
19
20
  metadata: ExecuteToolMetadata;
20
21
  }>;
21
- export declare function executeTool<INPUT, OUTPUT>(tool: Tool<string, INPUT, OUTPUT>, input: INPUT, options?: FunctionOptions<undefined> & {
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<OUTPUT>;
24
+ }): Promise<ReturnType<TOOL["execute"]>>;
@@ -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,7 +0,0 @@
1
- /**
2
- * Prompt mappings map a source prompt format to a target prompt format.
3
- */
4
- export interface PromptMapping<SOURCE_PROMPT, TARGET_PROMPT> {
5
- map(sourcePrompt: SOURCE_PROMPT): TARGET_PROMPT;
6
- stopTokens: string[];
7
- }
@@ -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