modelfusion 0.71.0 → 0.73.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 (151) hide show
  1. package/README.md +57 -45
  2. package/core/FunctionEvent.d.ts +5 -5
  3. package/core/api/ApiCallError.cjs +2 -1
  4. package/core/api/ApiCallError.d.ts +3 -3
  5. package/core/api/ApiCallError.js +2 -1
  6. package/core/api/postToApi.cjs +10 -3
  7. package/core/api/postToApi.js +10 -3
  8. package/guard/guard.cjs +5 -4
  9. package/guard/guard.d.ts +1 -1
  10. package/guard/guard.js +5 -4
  11. package/model-function/ModelCallEvent.d.ts +2 -2
  12. package/model-function/generate-structure/StructureGenerationEvent.d.ts +2 -2
  13. package/model-function/generate-structure/StructureParseError.cjs +10 -0
  14. package/model-function/generate-structure/StructureParseError.d.ts +8 -0
  15. package/model-function/generate-structure/StructureParseError.js +10 -0
  16. package/model-function/generate-structure/index.cjs +0 -3
  17. package/model-function/generate-structure/index.d.ts +0 -3
  18. package/model-function/generate-structure/index.js +0 -3
  19. package/model-function/index.cjs +0 -1
  20. package/model-function/index.d.ts +0 -1
  21. package/model-function/index.js +0 -1
  22. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
  23. package/model-provider/ollama/OllamaError.cjs +21 -7
  24. package/model-provider/ollama/OllamaError.d.ts +10 -3
  25. package/model-provider/ollama/OllamaError.js +21 -7
  26. package/model-provider/ollama/OllamaTextGenerationModel.cjs +2 -2
  27. package/model-provider/ollama/OllamaTextGenerationModel.d.ts +5 -5
  28. package/model-provider/ollama/OllamaTextGenerationModel.js +2 -2
  29. package/model-provider/openai/chat/OpenAIChatMessage.cjs +16 -25
  30. package/model-provider/openai/chat/OpenAIChatMessage.d.ts +10 -28
  31. package/model-provider/openai/chat/OpenAIChatMessage.js +16 -25
  32. package/model-provider/openai/chat/OpenAIChatModel.cjs +2 -48
  33. package/model-provider/openai/chat/OpenAIChatModel.d.ts +15 -107
  34. package/model-provider/openai/chat/OpenAIChatModel.js +2 -48
  35. package/package.json +1 -1
  36. package/tool/Tool.cjs +5 -16
  37. package/tool/Tool.d.ts +9 -14
  38. package/tool/Tool.js +5 -16
  39. package/tool/ToolCall.d.ts +15 -0
  40. package/tool/ToolCallArgumentsValidationError.cjs +49 -0
  41. package/tool/ToolCallArgumentsValidationError.d.ts +23 -0
  42. package/tool/ToolCallArgumentsValidationError.js +45 -0
  43. package/tool/ToolCallError.cjs +34 -0
  44. package/tool/ToolCallError.d.ts +17 -0
  45. package/tool/ToolCallError.js +30 -0
  46. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.cjs +4 -4
  47. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.d.ts +1 -1
  48. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.js +2 -2
  49. package/{model-function/generate-tool-call/ToolCallParametersValidationError.cjs → tool/ToolCallParseError.cjs} +13 -13
  50. package/{model-function/generate-tool-call/ToolCallParametersValidationError.d.ts → tool/ToolCallParseError.d.ts} +6 -6
  51. package/{model-function/generate-tool-call/ToolCallParametersValidationError.js → tool/ToolCallParseError.js} +11 -11
  52. package/tool/ToolCallResult.d.ts +13 -0
  53. package/{model-function/generate-tool-call → tool}/ToolDefinition.d.ts +2 -2
  54. package/tool/ToolExecutionError.cjs +5 -4
  55. package/tool/ToolExecutionError.d.ts +4 -4
  56. package/tool/ToolExecutionError.js +5 -4
  57. package/tool/WebSearchTool.cjs +4 -4
  58. package/tool/WebSearchTool.d.ts +2 -2
  59. package/tool/WebSearchTool.js +4 -4
  60. package/tool/{ExecuteToolEvent.d.ts → execute-tool/ExecuteToolEvent.d.ts} +1 -1
  61. package/tool/{executeTool.cjs → execute-tool/executeTool.cjs} +15 -15
  62. package/tool/{executeTool.d.ts → execute-tool/executeTool.d.ts} +6 -6
  63. package/tool/{executeTool.js → execute-tool/executeTool.js} +15 -15
  64. package/tool/execute-tool/index.cjs +18 -0
  65. package/tool/execute-tool/index.d.ts +2 -0
  66. package/tool/execute-tool/index.js +2 -0
  67. package/tool/execute-tool/safeExecuteToolCall.cjs +34 -0
  68. package/tool/execute-tool/safeExecuteToolCall.d.ts +5 -0
  69. package/tool/execute-tool/safeExecuteToolCall.js +30 -0
  70. package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +59 -0
  71. package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +35 -0
  72. package/tool/generate-tool-call/TextGenerationToolCallModel.js +55 -0
  73. package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.d.ts +1 -1
  74. package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.d.ts +3 -3
  75. package/{model-function → tool}/generate-tool-call/generateToolCall.cjs +11 -11
  76. package/{model-function → tool}/generate-tool-call/generateToolCall.d.ts +3 -3
  77. package/{model-function → tool}/generate-tool-call/generateToolCall.js +11 -11
  78. package/tool/generate-tool-call/index.cjs +20 -0
  79. package/tool/generate-tool-call/index.d.ts +4 -0
  80. package/tool/generate-tool-call/index.js +4 -0
  81. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.d.ts +1 -1
  82. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.d.ts +3 -3
  83. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.cjs +8 -8
  84. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.d.ts +3 -3
  85. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.js +8 -8
  86. package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/index.cjs +0 -7
  87. package/tool/generate-tool-calls-or-text/index.d.ts +3 -0
  88. package/tool/generate-tool-calls-or-text/index.js +3 -0
  89. package/tool/index.cjs +12 -7
  90. package/tool/index.d.ts +12 -7
  91. package/tool/index.js +12 -7
  92. package/tool/{UseToolEvent.d.ts → use-tool/UseToolEvent.d.ts} +1 -1
  93. package/tool/use-tool/index.cjs +18 -0
  94. package/tool/use-tool/index.d.ts +2 -0
  95. package/tool/use-tool/index.js +2 -0
  96. package/tool/use-tool/useTool.cjs +30 -0
  97. package/tool/use-tool/useTool.d.ts +16 -0
  98. package/tool/use-tool/useTool.js +26 -0
  99. package/tool/use-tools-or-generate-text/UseToolsOrGenerateTextEvent.d.ts +7 -0
  100. package/tool/use-tools-or-generate-text/index.cjs +18 -0
  101. package/tool/use-tools-or-generate-text/index.d.ts +2 -0
  102. package/tool/use-tools-or-generate-text/index.js +2 -0
  103. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.cjs +48 -0
  104. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.d.ts +18 -0
  105. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.js +44 -0
  106. package/util/getErrorMessage.cjs +3 -0
  107. package/util/getErrorMessage.d.ts +1 -1
  108. package/util/getErrorMessage.js +3 -0
  109. package/model-function/generate-structure/NoSuchStructureError.cjs +0 -17
  110. package/model-function/generate-structure/NoSuchStructureError.d.ts +0 -4
  111. package/model-function/generate-structure/NoSuchStructureError.js +0 -13
  112. package/model-function/generate-structure/StructureOrTextGenerationModel.d.ts +0 -26
  113. package/model-function/generate-structure/generateStructureOrText.cjs +0 -54
  114. package/model-function/generate-structure/generateStructureOrText.d.ts +0 -97
  115. package/model-function/generate-structure/generateStructureOrText.js +0 -50
  116. package/model-function/generate-tool-call/ToolCall.d.ts +0 -5
  117. package/model-function/generate-tool-call/index.d.ts +0 -10
  118. package/model-function/generate-tool-call/index.js +0 -10
  119. package/tool/NoSuchToolError.cjs +0 -25
  120. package/tool/NoSuchToolError.d.ts +0 -10
  121. package/tool/NoSuchToolError.js +0 -21
  122. package/tool/UseToolOrGenerateTextEvent.d.ts +0 -7
  123. package/tool/useTool.cjs +0 -40
  124. package/tool/useTool.d.ts +0 -15
  125. package/tool/useTool.js +0 -36
  126. package/tool/useToolOrGenerateText.cjs +0 -50
  127. package/tool/useToolOrGenerateText.d.ts +0 -23
  128. package/tool/useToolOrGenerateText.js +0 -46
  129. /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.cjs +0 -0
  130. /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.d.ts +0 -0
  131. /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.js +0 -0
  132. /package/{model-function/generate-tool-call → tool}/ToolCall.cjs +0 -0
  133. /package/{model-function/generate-tool-call → tool}/ToolCall.js +0 -0
  134. /package/{model-function/generate-structure/StructureOrTextGenerationModel.cjs → tool/ToolCallResult.cjs} +0 -0
  135. /package/{model-function/generate-structure/StructureOrTextGenerationModel.js → tool/ToolCallResult.js} +0 -0
  136. /package/{model-function/generate-tool-call → tool}/ToolDefinition.cjs +0 -0
  137. /package/{model-function/generate-tool-call → tool}/ToolDefinition.js +0 -0
  138. /package/tool/{ExecuteToolEvent.cjs → execute-tool/ExecuteToolEvent.cjs} +0 -0
  139. /package/tool/{ExecuteToolEvent.js → execute-tool/ExecuteToolEvent.js} +0 -0
  140. /package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.cjs +0 -0
  141. /package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.js +0 -0
  142. /package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.cjs +0 -0
  143. /package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.js +0 -0
  144. /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.cjs +0 -0
  145. /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.js +0 -0
  146. /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.cjs +0 -0
  147. /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.js +0 -0
  148. /package/tool/{UseToolEvent.cjs → use-tool/UseToolEvent.cjs} +0 -0
  149. /package/tool/{UseToolEvent.js → use-tool/UseToolEvent.js} +0 -0
  150. /package/tool/{UseToolOrGenerateTextEvent.cjs → use-tools-or-generate-text/UseToolsOrGenerateTextEvent.cjs} +0 -0
  151. /package/tool/{UseToolOrGenerateTextEvent.js → use-tools-or-generate-text/UseToolsOrGenerateTextEvent.js} +0 -0
@@ -125,12 +125,12 @@ export declare class OllamaTextGenerationModel<CONTEXT_WINDOW_SIZE extends numbe
125
125
  response: string;
126
126
  model: string;
127
127
  done: true;
128
- context: number[];
129
128
  total_duration: number;
130
129
  load_duration: number;
131
130
  prompt_eval_count: number;
132
131
  eval_count: number;
133
132
  eval_duration: number;
133
+ context?: number[] | undefined;
134
134
  };
135
135
  text: string;
136
136
  }>;
@@ -147,27 +147,27 @@ declare const ollamaTextGenerationResponseSchema: z.ZodObject<{
147
147
  prompt_eval_count: z.ZodNumber;
148
148
  eval_count: z.ZodNumber;
149
149
  eval_duration: z.ZodNumber;
150
- context: z.ZodArray<z.ZodNumber, "many">;
150
+ context: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
151
151
  }, "strip", z.ZodTypeAny, {
152
152
  response: string;
153
153
  model: string;
154
154
  done: true;
155
- context: number[];
156
155
  total_duration: number;
157
156
  load_duration: number;
158
157
  prompt_eval_count: number;
159
158
  eval_count: number;
160
159
  eval_duration: number;
160
+ context?: number[] | undefined;
161
161
  }, {
162
162
  response: string;
163
163
  model: string;
164
164
  done: true;
165
- context: number[];
166
165
  total_duration: number;
167
166
  load_duration: number;
168
167
  prompt_eval_count: number;
169
168
  eval_count: number;
170
169
  eval_duration: number;
170
+ context?: number[] | undefined;
171
171
  }>;
172
172
  export type OllamaTextGenerationResponse = z.infer<typeof ollamaTextGenerationResponseSchema>;
173
173
  export type OllamaTextGenerationDelta = {
@@ -189,12 +189,12 @@ export declare const OllamaTextGenerationResponseFormat: {
189
189
  response: string;
190
190
  model: string;
191
191
  done: true;
192
- context: number[];
193
192
  total_duration: number;
194
193
  load_duration: number;
195
194
  prompt_eval_count: number;
196
195
  eval_count: number;
197
196
  eval_duration: number;
197
+ context?: number[] | undefined;
198
198
  }>;
199
199
  };
200
200
  /**
@@ -115,7 +115,7 @@ const ollamaTextGenerationResponseSchema = z.object({
115
115
  prompt_eval_count: z.number(),
116
116
  eval_count: z.number(),
117
117
  eval_duration: z.number(),
118
- context: z.array(z.number()),
118
+ context: z.array(z.number()).optional(),
119
119
  });
120
120
  const ollamaTextStreamingResponseSchema = new ZodSchema(z.discriminatedUnion("done", [
121
121
  z.object({
@@ -136,7 +136,7 @@ const ollamaTextStreamingResponseSchema = new ZodSchema(z.discriminatedUnion("do
136
136
  prompt_eval_duration: z.number().optional(),
137
137
  eval_count: z.number(),
138
138
  eval_duration: z.number(),
139
- context: z.array(z.number()),
139
+ context: z.array(z.number()).optional(),
140
140
  }),
141
141
  ]));
142
142
  async function callOllamaTextGenerationAPI({ api = new OllamaApiConfiguration(), abortSignal, responseFormat, prompt, model, format, contextWindowSize, maxCompletionTokens, mirostat, mirostat_eta, mirostat_tau, num_gpu, num_gqa, num_threads, repeat_last_n, repeat_penalty, seed, stopSequences, temperature, tfs_z, top_k, top_p, system, template, context, raw, }) {
@@ -21,40 +21,31 @@ exports.OpenAIChatMessage = {
21
21
  }
22
22
  return { role: "user", content, name: options?.name };
23
23
  },
24
- assistant(content) {
25
- return { role: "assistant", content };
26
- },
27
- functionCall(content, functionCall) {
28
- return {
29
- role: "assistant",
30
- content,
31
- function_call: functionCall,
32
- };
33
- },
34
- functionResult(name, content) {
35
- return { role: "function", name, content };
36
- },
37
24
  /**
38
- * Creates a function call chat message for tool calls.
25
+ * Creates an assistant chat message. The assistant message can optionally contain tool calls.
39
26
  */
40
- toolCall({ text, tool, parameters, }) {
27
+ assistant(content, options) {
41
28
  return {
42
29
  role: "assistant",
43
- content: text,
44
- function_call: {
45
- name: tool,
46
- arguments: JSON.stringify(parameters),
47
- },
30
+ content,
31
+ tool_calls: options?.toolCalls?.map((toolCall) => ({
32
+ id: toolCall.id,
33
+ type: "function",
34
+ function: {
35
+ name: toolCall.name,
36
+ arguments: JSON.stringify(toolCall.args),
37
+ },
38
+ })) ?? undefined,
48
39
  };
49
40
  },
50
41
  /**
51
- * Creates a function result chat message for tool call results.
42
+ * Creates a tool result chat message with the result of a tool call.
52
43
  */
53
- toolResult({ tool, result }) {
44
+ tool({ toolCallId, content, }) {
54
45
  return {
55
- role: "function",
56
- name: tool,
57
- content: JSON.stringify(result),
46
+ role: "tool",
47
+ tool_call_id: toolCallId,
48
+ content: JSON.stringify(content),
58
49
  };
59
50
  },
60
51
  };
@@ -1,3 +1,4 @@
1
+ import { ToolCall } from "../../../tool/ToolCall.js";
1
2
  export type OpenAIChatMessage = {
2
3
  role: "system";
3
4
  content: string;
@@ -49,36 +50,17 @@ export declare const OpenAIChatMessage: {
49
50
  mimeType?: string;
50
51
  };
51
52
  }): OpenAIChatMessage;
52
- assistant(content: string): OpenAIChatMessage;
53
- functionCall(content: string | null, functionCall: {
54
- name: string;
55
- arguments: string;
56
- }): OpenAIChatMessage;
57
- functionResult(name: string, content: string): OpenAIChatMessage;
58
53
  /**
59
- * Creates a function call chat message for tool calls.
54
+ * Creates an assistant chat message. The assistant message can optionally contain tool calls.
60
55
  */
61
- toolCall({ text, tool, parameters, }: {
62
- text: string | null;
63
- tool: string;
64
- parameters: unknown;
65
- }): {
66
- role: "assistant";
67
- content: string | null;
68
- function_call: {
69
- name: string;
70
- arguments: string;
71
- };
72
- };
56
+ assistant(content: string | null, options?: {
57
+ toolCalls: Array<ToolCall<string, unknown>> | null | undefined;
58
+ }): OpenAIChatMessage;
73
59
  /**
74
- * Creates a function result chat message for tool call results.
60
+ * Creates a tool result chat message with the result of a tool call.
75
61
  */
76
- toolResult({ tool, result }: {
77
- tool: string;
78
- result: unknown;
79
- }): {
80
- role: "function";
81
- name: string;
82
- content: string;
83
- };
62
+ tool({ toolCallId, content, }: {
63
+ toolCallId: string;
64
+ content: unknown;
65
+ }): OpenAIChatMessage;
84
66
  };
@@ -18,40 +18,31 @@ export const OpenAIChatMessage = {
18
18
  }
19
19
  return { role: "user", content, name: options?.name };
20
20
  },
21
- assistant(content) {
22
- return { role: "assistant", content };
23
- },
24
- functionCall(content, functionCall) {
25
- return {
26
- role: "assistant",
27
- content,
28
- function_call: functionCall,
29
- };
30
- },
31
- functionResult(name, content) {
32
- return { role: "function", name, content };
33
- },
34
21
  /**
35
- * Creates a function call chat message for tool calls.
22
+ * Creates an assistant chat message. The assistant message can optionally contain tool calls.
36
23
  */
37
- toolCall({ text, tool, parameters, }) {
24
+ assistant(content, options) {
38
25
  return {
39
26
  role: "assistant",
40
- content: text,
41
- function_call: {
42
- name: tool,
43
- arguments: JSON.stringify(parameters),
44
- },
27
+ content,
28
+ tool_calls: options?.toolCalls?.map((toolCall) => ({
29
+ id: toolCall.id,
30
+ type: "function",
31
+ function: {
32
+ name: toolCall.name,
33
+ arguments: JSON.stringify(toolCall.args),
34
+ },
35
+ })) ?? undefined,
45
36
  };
46
37
  },
47
38
  /**
48
- * Creates a function result chat message for tool call results.
39
+ * Creates a tool result chat message with the result of a tool call.
49
40
  */
50
- toolResult({ tool, result }) {
41
+ tool({ toolCallId, content, }) {
51
42
  return {
52
- role: "function",
53
- name: tool,
54
- content: JSON.stringify(result),
43
+ role: "tool",
44
+ tool_call_id: toolCallId,
45
+ content: JSON.stringify(content),
55
46
  };
56
47
  },
57
48
  };
@@ -315,52 +315,6 @@ class OpenAIChatModel extends AbstractModel_js_1.AbstractModel {
315
315
  ],
316
316
  });
317
317
  }
318
- async doGenerateStructureOrText(structureDefinitions, prompt, options) {
319
- const response = await this.callAPI(prompt, {
320
- ...options,
321
- responseFormat: exports.OpenAIChatResponseFormat.json,
322
- functionCall: "auto",
323
- functions: structureDefinitions.map((structureDefinition) => ({
324
- name: structureDefinition.name,
325
- description: structureDefinition.description,
326
- parameters: structureDefinition.schema.getJsonSchema(),
327
- })),
328
- });
329
- const message = response.choices[0].message;
330
- const content = message.content;
331
- const functionCall = message.function_call;
332
- if (functionCall == null) {
333
- return {
334
- response,
335
- structureAndText: {
336
- structure: null,
337
- value: null,
338
- valueText: null,
339
- text: content ?? "",
340
- },
341
- usage: this.extractUsage(response),
342
- };
343
- }
344
- try {
345
- return {
346
- response,
347
- structureAndText: {
348
- structure: functionCall.name,
349
- value: secure_json_parse_1.default.parse(functionCall.arguments),
350
- valueText: functionCall.arguments,
351
- text: content,
352
- },
353
- usage: this.extractUsage(response),
354
- };
355
- }
356
- catch (error) {
357
- throw new StructureParseError_js_1.StructureParseError({
358
- structureName: functionCall.name,
359
- valueText: functionCall.arguments,
360
- cause: error,
361
- });
362
- }
363
- }
364
318
  async doGenerateToolCall(tool, prompt, options) {
365
319
  const response = await this.callAPI(prompt, {
366
320
  ...options,
@@ -387,7 +341,7 @@ class OpenAIChatModel extends AbstractModel_js_1.AbstractModel {
387
341
  ? null
388
342
  : {
389
343
  id: toolCalls[0].id,
390
- parameters: (0, parseJSON_js_1.parseJSON)({ text: toolCalls[0].function.arguments }),
344
+ args: (0, parseJSON_js_1.parseJSON)({ text: toolCalls[0].function.arguments }),
391
345
  },
392
346
  usage: this.extractUsage(response),
393
347
  };
@@ -413,7 +367,7 @@ class OpenAIChatModel extends AbstractModel_js_1.AbstractModel {
413
367
  toolCalls: message.tool_calls?.map((toolCall) => ({
414
368
  id: toolCall.id,
415
369
  name: toolCall.function.name,
416
- parameters: (0, parseJSON_js_1.parseJSON)({ text: toolCall.function.arguments }),
370
+ args: (0, parseJSON_js_1.parseJSON)({ text: toolCall.function.arguments }),
417
371
  })) ?? null,
418
372
  usage: this.extractUsage(response),
419
373
  };
@@ -6,13 +6,12 @@ import { StructureDefinition } from "../../../core/schema/StructureDefinition.js
6
6
  import { AbstractModel } from "../../../model-function/AbstractModel.js";
7
7
  import { Delta } from "../../../model-function/Delta.js";
8
8
  import { StructureGenerationModel } from "../../../model-function/generate-structure/StructureGenerationModel.js";
9
- import { StructureOrTextGenerationModel } from "../../../model-function/generate-structure/StructureOrTextGenerationModel.js";
10
9
  import { PromptFormatTextStreamingModel } from "../../../model-function/generate-text/PromptFormatTextStreamingModel.js";
11
10
  import { TextGenerationModelSettings, TextStreamingModel } from "../../../model-function/generate-text/TextGenerationModel.js";
12
11
  import { TextGenerationPromptFormat } from "../../../model-function/generate-text/TextGenerationPromptFormat.js";
13
- import { ToolCallGenerationModel } from "../../../model-function/generate-tool-call/ToolCallGenerationModel.js";
14
- import { ToolCallsOrTextGenerationModel } from "../../../model-function/generate-tool-call/ToolCallsOrTextGenerationModel.js";
15
- import { ToolDefinition } from "../../../model-function/generate-tool-call/ToolDefinition.js";
12
+ import { ToolDefinition } from "../../../tool/ToolDefinition.js";
13
+ import { ToolCallGenerationModel } from "../../../tool/generate-tool-call/ToolCallGenerationModel.js";
14
+ import { ToolCallsOrTextGenerationModel } from "../../../tool/generate-tool-calls-or-text/ToolCallsOrTextGenerationModel.js";
16
15
  import { TikTokenTokenizer } from "../TikTokenTokenizer.js";
17
16
  import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
18
17
  export declare const OPENAI_CHAT_MODELS: {
@@ -169,7 +168,7 @@ export interface OpenAIChatSettings extends TextGenerationModelSettings, Omit<Op
169
168
  * ),
170
169
  * ]);
171
170
  */
172
- export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> implements TextStreamingModel<OpenAIChatMessage[], OpenAIChatSettings>, StructureGenerationModel<OpenAIChatMessage[], OpenAIChatSettings>, StructureOrTextGenerationModel<OpenAIChatMessage[], OpenAIChatSettings>, ToolCallGenerationModel<OpenAIChatMessage[], OpenAIChatSettings>, ToolCallsOrTextGenerationModel<OpenAIChatMessage[], OpenAIChatSettings> {
171
+ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> implements TextStreamingModel<OpenAIChatMessage[], OpenAIChatSettings>, StructureGenerationModel<OpenAIChatMessage[], OpenAIChatSettings>, ToolCallGenerationModel<OpenAIChatMessage[], OpenAIChatSettings>, ToolCallsOrTextGenerationModel<OpenAIChatMessage[], OpenAIChatSettings> {
173
172
  constructor(settings: OpenAIChatSettings);
174
173
  readonly provider: "openai";
175
174
  get modelName(): OpenAIChatModelType;
@@ -218,7 +217,7 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
218
217
  };
219
218
  index: number;
220
219
  logprobs?: any;
221
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
220
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
222
221
  }[];
223
222
  created: number;
224
223
  system_fingerprint?: string | undefined;
@@ -267,7 +266,7 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
267
266
  };
268
267
  index: number;
269
268
  logprobs?: any;
270
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
269
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
271
270
  }[];
272
271
  created: number;
273
272
  system_fingerprint?: string | undefined;
@@ -281,97 +280,6 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
281
280
  };
282
281
  }>;
283
282
  doStreamStructure(structureDefinition: StructureDefinition<string, unknown>, prompt: OpenAIChatMessage[], options?: FunctionOptions): Promise<AsyncIterable<Delta<unknown>>>;
284
- doGenerateStructureOrText(structureDefinitions: Array<StructureDefinition<string, unknown>>, prompt: OpenAIChatMessage[], options?: FunctionOptions): Promise<{
285
- response: {
286
- object: "chat.completion";
287
- usage: {
288
- prompt_tokens: number;
289
- total_tokens: number;
290
- completion_tokens: number;
291
- };
292
- model: string;
293
- id: string;
294
- choices: {
295
- message: {
296
- role: "assistant";
297
- content: string | null;
298
- function_call?: {
299
- name: string;
300
- arguments: string;
301
- } | undefined;
302
- tool_calls?: {
303
- function: {
304
- name: string;
305
- arguments: string;
306
- };
307
- type: "function";
308
- id: string;
309
- }[] | undefined;
310
- };
311
- index: number;
312
- logprobs?: any;
313
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
314
- }[];
315
- created: number;
316
- system_fingerprint?: string | undefined;
317
- };
318
- structureAndText: {
319
- structure: null;
320
- value: null;
321
- valueText: null;
322
- text: string;
323
- };
324
- usage: {
325
- promptTokens: number;
326
- completionTokens: number;
327
- totalTokens: number;
328
- };
329
- } | {
330
- response: {
331
- object: "chat.completion";
332
- usage: {
333
- prompt_tokens: number;
334
- total_tokens: number;
335
- completion_tokens: number;
336
- };
337
- model: string;
338
- id: string;
339
- choices: {
340
- message: {
341
- role: "assistant";
342
- content: string | null;
343
- function_call?: {
344
- name: string;
345
- arguments: string;
346
- } | undefined;
347
- tool_calls?: {
348
- function: {
349
- name: string;
350
- arguments: string;
351
- };
352
- type: "function";
353
- id: string;
354
- }[] | undefined;
355
- };
356
- index: number;
357
- logprobs?: any;
358
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
359
- }[];
360
- created: number;
361
- system_fingerprint?: string | undefined;
362
- };
363
- structureAndText: {
364
- structure: string;
365
- value: any;
366
- valueText: string;
367
- text: string | null;
368
- };
369
- usage: {
370
- promptTokens: number;
371
- completionTokens: number;
372
- totalTokens: number;
373
- };
374
- }>;
375
283
  doGenerateToolCall(tool: ToolDefinition<string, unknown>, prompt: OpenAIChatMessage[], options?: FunctionOptions): Promise<{
376
284
  response: {
377
285
  object: "chat.completion";
@@ -401,14 +309,14 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
401
309
  };
402
310
  index: number;
403
311
  logprobs?: any;
404
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
312
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
405
313
  }[];
406
314
  created: number;
407
315
  system_fingerprint?: string | undefined;
408
316
  };
409
317
  toolCall: {
410
318
  id: string;
411
- parameters: unknown;
319
+ args: unknown;
412
320
  } | null;
413
321
  usage: {
414
322
  promptTokens: number;
@@ -445,7 +353,7 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
445
353
  };
446
354
  index: number;
447
355
  logprobs?: any;
448
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
356
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
449
357
  }[];
450
358
  created: number;
451
359
  system_fingerprint?: string | undefined;
@@ -454,7 +362,7 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
454
362
  toolCalls: {
455
363
  id: string;
456
364
  name: string;
457
- parameters: unknown;
365
+ args: unknown;
458
366
  }[] | null;
459
367
  usage: {
460
368
  promptTokens: number;
@@ -575,7 +483,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
575
483
  };
576
484
  index: number;
577
485
  logprobs?: any;
578
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
486
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
579
487
  }, {
580
488
  message: {
581
489
  role: "assistant";
@@ -595,7 +503,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
595
503
  };
596
504
  index: number;
597
505
  logprobs?: any;
598
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
506
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
599
507
  }>, "many">;
600
508
  created: z.ZodNumber;
601
509
  model: z.ZodString;
@@ -642,7 +550,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
642
550
  };
643
551
  index: number;
644
552
  logprobs?: any;
645
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
553
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
646
554
  }[];
647
555
  created: number;
648
556
  system_fingerprint?: string | undefined;
@@ -674,7 +582,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
674
582
  };
675
583
  index: number;
676
584
  logprobs?: any;
677
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
585
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
678
586
  }[];
679
587
  created: number;
680
588
  system_fingerprint?: string | undefined;
@@ -718,7 +626,7 @@ export declare const OpenAIChatResponseFormat: {
718
626
  };
719
627
  index: number;
720
628
  logprobs?: any;
721
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
629
+ finish_reason?: "length" | "stop" | "tool_calls" | "function_call" | "content_filter" | null | undefined;
722
630
  }[];
723
631
  created: number;
724
632
  system_fingerprint?: string | undefined;
@@ -306,52 +306,6 @@ export class OpenAIChatModel extends AbstractModel {
306
306
  ],
307
307
  });
308
308
  }
309
- async doGenerateStructureOrText(structureDefinitions, prompt, options) {
310
- const response = await this.callAPI(prompt, {
311
- ...options,
312
- responseFormat: OpenAIChatResponseFormat.json,
313
- functionCall: "auto",
314
- functions: structureDefinitions.map((structureDefinition) => ({
315
- name: structureDefinition.name,
316
- description: structureDefinition.description,
317
- parameters: structureDefinition.schema.getJsonSchema(),
318
- })),
319
- });
320
- const message = response.choices[0].message;
321
- const content = message.content;
322
- const functionCall = message.function_call;
323
- if (functionCall == null) {
324
- return {
325
- response,
326
- structureAndText: {
327
- structure: null,
328
- value: null,
329
- valueText: null,
330
- text: content ?? "",
331
- },
332
- usage: this.extractUsage(response),
333
- };
334
- }
335
- try {
336
- return {
337
- response,
338
- structureAndText: {
339
- structure: functionCall.name,
340
- value: SecureJSON.parse(functionCall.arguments),
341
- valueText: functionCall.arguments,
342
- text: content,
343
- },
344
- usage: this.extractUsage(response),
345
- };
346
- }
347
- catch (error) {
348
- throw new StructureParseError({
349
- structureName: functionCall.name,
350
- valueText: functionCall.arguments,
351
- cause: error,
352
- });
353
- }
354
- }
355
309
  async doGenerateToolCall(tool, prompt, options) {
356
310
  const response = await this.callAPI(prompt, {
357
311
  ...options,
@@ -378,7 +332,7 @@ export class OpenAIChatModel extends AbstractModel {
378
332
  ? null
379
333
  : {
380
334
  id: toolCalls[0].id,
381
- parameters: parseJSON({ text: toolCalls[0].function.arguments }),
335
+ args: parseJSON({ text: toolCalls[0].function.arguments }),
382
336
  },
383
337
  usage: this.extractUsage(response),
384
338
  };
@@ -404,7 +358,7 @@ export class OpenAIChatModel extends AbstractModel {
404
358
  toolCalls: message.tool_calls?.map((toolCall) => ({
405
359
  id: toolCall.id,
406
360
  name: toolCall.function.name,
407
- parameters: parseJSON({ text: toolCall.function.arguments }),
361
+ args: parseJSON({ text: toolCall.function.arguments }),
408
362
  })) ?? null,
409
363
  usage: this.extractUsage(response),
410
364
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "The TypeScript library for building multi-modal AI applications.",
4
- "version": "0.71.0",
4
+ "version": "0.73.0",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
package/tool/Tool.cjs CHANGED
@@ -8,7 +8,7 @@ const namePattern = /^[a-zA-Z0-9_-]{1,64}$/;
8
8
  * by agents and chatbots.
9
9
  */
10
10
  class Tool {
11
- constructor({ name, description, inputSchema, outputSchema, execute, }) {
11
+ constructor({ name, description, parameters, returnType, execute, }) {
12
12
  /**
13
13
  * The name of the tool.
14
14
  * It has to be a function name that matches the regular expression pattern '^[a-zA-Z0-9_-]{1,64}$'.
@@ -33,7 +33,7 @@ class Tool {
33
33
  * The schema of the input that the tool expects. The language model will use this to generate the input.
34
34
  * Use descriptions to make the input understandable for the language model.
35
35
  */
36
- Object.defineProperty(this, "inputSchema", {
36
+ Object.defineProperty(this, "parameters", {
37
37
  enumerable: true,
38
38
  configurable: true,
39
39
  writable: true,
@@ -42,7 +42,7 @@ class Tool {
42
42
  /**
43
43
  * An optional schema of the output that the tool produces. This will be used to validate the output.
44
44
  */
45
- Object.defineProperty(this, "outputSchema", {
45
+ Object.defineProperty(this, "returnType", {
46
46
  enumerable: true,
47
47
  configurable: true,
48
48
  writable: true,
@@ -66,20 +66,9 @@ class Tool {
66
66
  }
67
67
  this.name = name;
68
68
  this.description = description;
69
- this.inputSchema = inputSchema;
70
- this.outputSchema = outputSchema;
69
+ this.parameters = parameters;
70
+ this.returnType = returnType;
71
71
  this.execute = execute;
72
72
  }
73
- /**
74
- * Provides a structure definition with the name, description and schema of the input.
75
- * This is used by `useTool`.
76
- */
77
- get inputStructureDefinition() {
78
- return {
79
- name: this.name,
80
- description: this.description,
81
- schema: this.inputSchema,
82
- };
83
- }
84
73
  }
85
74
  exports.Tool = Tool;