modelfusion 0.30.1 → 0.32.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 (70) hide show
  1. package/README.md +14 -20
  2. package/model-function/Model.d.ts +1 -1
  3. package/model-function/SuccessfulModelCall.cjs +2 -9
  4. package/model-function/SuccessfulModelCall.d.ts +10 -7
  5. package/model-function/SuccessfulModelCall.js +2 -9
  6. package/model-function/generate-structure/StructureFromTextGenerationModel.cjs +2 -2
  7. package/model-function/generate-structure/StructureFromTextGenerationModel.d.ts +5 -9
  8. package/model-function/generate-structure/StructureFromTextGenerationModel.js +2 -2
  9. package/model-function/generate-structure/StructureGenerationModel.d.ts +3 -2
  10. package/model-function/generate-structure/StructureOrTextGenerationModel.d.ts +4 -5
  11. package/model-function/generate-structure/generateStructure.cjs +5 -2
  12. package/model-function/generate-structure/generateStructure.d.ts +1 -1
  13. package/model-function/generate-structure/generateStructure.js +5 -2
  14. package/model-function/generate-structure/generateStructureOrText.cjs +8 -5
  15. package/model-function/generate-structure/generateStructureOrText.d.ts +2 -2
  16. package/model-function/generate-structure/generateStructureOrText.js +8 -5
  17. package/model-function/index.cjs +2 -3
  18. package/model-function/index.d.ts +2 -3
  19. package/model-function/index.js +2 -3
  20. package/model-provider/openai/OpenAICostCalculator.cjs +6 -5
  21. package/model-provider/openai/OpenAICostCalculator.js +6 -5
  22. package/model-provider/openai/OpenAITextGenerationModel.cjs +41 -17
  23. package/model-provider/openai/OpenAITextGenerationModel.d.ts +32 -14
  24. package/model-provider/openai/OpenAITextGenerationModel.js +41 -17
  25. package/model-provider/openai/TikTokenTokenizer.cjs +3 -2
  26. package/model-provider/openai/TikTokenTokenizer.js +3 -2
  27. package/model-provider/openai/chat/OpenAIChatModel.cjs +47 -9
  28. package/model-provider/openai/chat/OpenAIChatModel.d.ts +15 -5
  29. package/model-provider/openai/chat/OpenAIChatModel.js +47 -9
  30. package/model-provider/openai/chat/OpenAIChatPromptFormat.cjs +78 -0
  31. package/model-provider/openai/chat/OpenAIChatPromptFormat.d.ts +12 -0
  32. package/model-provider/openai/chat/OpenAIChatPromptFormat.js +73 -0
  33. package/model-provider/openai/index.cjs +2 -3
  34. package/model-provider/openai/index.d.ts +1 -1
  35. package/model-provider/openai/index.js +1 -1
  36. package/model-provider/stability/StabilityImageGenerationModel.cjs +6 -0
  37. package/model-provider/stability/StabilityImageGenerationModel.d.ts +4 -2
  38. package/model-provider/stability/StabilityImageGenerationModel.js +6 -0
  39. package/package.json +2 -2
  40. package/prompt/AlpacaPromptFormat.cjs +23 -21
  41. package/prompt/AlpacaPromptFormat.d.ts +1 -1
  42. package/prompt/AlpacaPromptFormat.js +21 -19
  43. package/prompt/InstructionPrompt.d.ts +9 -0
  44. package/prompt/Llama2PromptFormat.cjs +44 -40
  45. package/prompt/Llama2PromptFormat.d.ts +2 -2
  46. package/prompt/Llama2PromptFormat.js +41 -37
  47. package/prompt/TextPromptFormat.cjs +5 -5
  48. package/prompt/TextPromptFormat.d.ts +2 -2
  49. package/prompt/TextPromptFormat.js +2 -2
  50. package/prompt/VicunaPromptFormat.cjs +39 -37
  51. package/prompt/VicunaPromptFormat.d.ts +1 -1
  52. package/prompt/VicunaPromptFormat.js +37 -35
  53. package/prompt/index.cjs +0 -1
  54. package/prompt/index.d.ts +0 -1
  55. package/prompt/index.js +0 -1
  56. package/tool/useTool.cjs +5 -1
  57. package/tool/useTool.d.ts +1 -1
  58. package/tool/useTool.js +5 -1
  59. package/tool/useToolOrGenerateText.cjs +5 -2
  60. package/tool/useToolOrGenerateText.d.ts +2 -2
  61. package/tool/useToolOrGenerateText.js +5 -2
  62. package/model-function/generate-structure/InstructionWithStructurePrompt.cjs +0 -17
  63. package/model-function/generate-structure/InstructionWithStructurePrompt.d.ts +0 -17
  64. package/model-function/generate-structure/InstructionWithStructurePrompt.js +0 -14
  65. package/model-provider/openai/chat/OpenAIChatPrompt.cjs +0 -135
  66. package/model-provider/openai/chat/OpenAIChatPrompt.d.ts +0 -96
  67. package/model-provider/openai/chat/OpenAIChatPrompt.js +0 -127
  68. package/prompt/OpenAIChatPromptFormat.cjs +0 -74
  69. package/prompt/OpenAIChatPromptFormat.d.ts +0 -12
  70. package/prompt/OpenAIChatPromptFormat.js +0 -69
@@ -1,127 +0,0 @@
1
- import SecureJSON from "secure-json-parse";
2
- export const OpenAIChatFunctionPrompt = {
3
- forOpenAIFunctionDescription(options) {
4
- return new OpenAIChatSingleFunctionPrompt(options);
5
- },
6
- forStructure({ messages, structure, }) {
7
- return this.forOpenAIFunctionDescription({
8
- messages,
9
- fn: {
10
- name: structure.name,
11
- description: structure.description,
12
- parameters: structure.schema,
13
- },
14
- });
15
- },
16
- forStructureCurried(messages) {
17
- return (structure) => this.forStructure({ messages, structure });
18
- },
19
- forTool({ messages, tool, }) {
20
- return this.forStructure({
21
- messages,
22
- structure: tool.inputStructureDefinition,
23
- });
24
- },
25
- forToolCurried(messages) {
26
- return (tool) => this.forTool({ messages, tool });
27
- },
28
- forOpenAIFunctionDescriptions(options) {
29
- return new OpenAIChatAutoFunctionPrompt(options);
30
- },
31
- forStructures({ messages, structures, }) {
32
- return this.forOpenAIFunctionDescriptions({
33
- messages,
34
- fns: structures.map((structure) => ({
35
- name: structure.name,
36
- description: structure.description,
37
- parameters: structure.schema,
38
- })),
39
- });
40
- },
41
- forStructuresCurried(messages) {
42
- return (structures) => this.forStructures({ messages, structures });
43
- },
44
- forTools({ messages, tools, }) {
45
- return this.forStructures({
46
- messages,
47
- structures: tools.map((tool) => tool.inputStructureDefinition),
48
- });
49
- },
50
- forToolsCurried(messages) {
51
- return (tools) => this.forTools({ messages, tools });
52
- },
53
- };
54
- export class OpenAIChatSingleFunctionPrompt {
55
- constructor({ messages, fn, }) {
56
- Object.defineProperty(this, "messages", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: void 0
61
- });
62
- Object.defineProperty(this, "fn", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: void 0
67
- });
68
- this.messages = messages;
69
- this.fn = fn;
70
- }
71
- get functionCall() {
72
- return { name: this.fn.name };
73
- }
74
- get functions() {
75
- return [
76
- {
77
- name: this.fn.name,
78
- description: this.fn.description,
79
- parameters: this.fn.parameters.getJsonSchema(),
80
- },
81
- ];
82
- }
83
- }
84
- export class OpenAIChatAutoFunctionPrompt {
85
- constructor({ messages, fns, }) {
86
- Object.defineProperty(this, "messages", {
87
- enumerable: true,
88
- configurable: true,
89
- writable: true,
90
- value: void 0
91
- });
92
- Object.defineProperty(this, "fns", {
93
- enumerable: true,
94
- configurable: true,
95
- writable: true,
96
- value: void 0
97
- });
98
- this.messages = messages;
99
- this.fns = fns;
100
- }
101
- extractStructureAndText(response) {
102
- const message = response.choices[0].message;
103
- const content = message.content;
104
- const functionCall = message.function_call;
105
- return functionCall == null
106
- ? {
107
- structure: null,
108
- value: null,
109
- text: content ?? "",
110
- }
111
- : {
112
- structure: functionCall.name,
113
- value: SecureJSON.parse(functionCall.arguments),
114
- text: content,
115
- };
116
- }
117
- get functionCall() {
118
- return "auto";
119
- }
120
- get functions() {
121
- return this.fns.map((fn) => ({
122
- name: fn.name,
123
- description: fn.description,
124
- parameters: fn.parameters.getJsonSchema(),
125
- }));
126
- }
127
- }
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenAIChatChatPromptFormat = exports.OpenAIChatInstructionPromptFormat = void 0;
4
- const validateChatPrompt_js_1 = require("./chat/validateChatPrompt.cjs");
5
- /**
6
- * Formats an instruction prompt as an OpenAI chat prompt.
7
- */
8
- const OpenAIChatInstructionPromptFormat = () => ({
9
- format: (instruction) => {
10
- const messages = [];
11
- if (instruction.system != null) {
12
- messages.push({
13
- role: "system",
14
- content: instruction.system,
15
- });
16
- }
17
- messages.push({
18
- role: "user",
19
- content: instruction.instruction,
20
- });
21
- if (instruction.input != null) {
22
- messages.push({
23
- role: "user",
24
- content: instruction.input,
25
- });
26
- }
27
- return messages;
28
- },
29
- stopSequences: [],
30
- });
31
- exports.OpenAIChatInstructionPromptFormat = OpenAIChatInstructionPromptFormat;
32
- /**
33
- * Formats a chat prompt as an OpenAI chat prompt.
34
- */
35
- const OpenAIChatChatPromptFormat = () => ({
36
- format: (chatPrompt) => {
37
- (0, validateChatPrompt_js_1.validateChatPrompt)(chatPrompt);
38
- const messages = [];
39
- for (let i = 0; i < chatPrompt.length; i++) {
40
- const message = chatPrompt[i];
41
- // system message:
42
- if (i === 0 &&
43
- "system" in message &&
44
- typeof message.system === "string") {
45
- messages.push({
46
- role: "system",
47
- content: message.system,
48
- });
49
- continue;
50
- }
51
- // user message
52
- if ("user" in message) {
53
- messages.push({
54
- role: "user",
55
- content: message.user,
56
- });
57
- continue;
58
- }
59
- // ai message:
60
- if ("ai" in message) {
61
- messages.push({
62
- role: "assistant",
63
- content: message.ai,
64
- });
65
- continue;
66
- }
67
- // unsupported message:
68
- throw new Error(`Unsupported message: ${JSON.stringify(message)}`);
69
- }
70
- return messages;
71
- },
72
- stopSequences: [],
73
- });
74
- exports.OpenAIChatChatPromptFormat = OpenAIChatChatPromptFormat;
@@ -1,12 +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 { PromptFormat } from "./PromptFormat.js";
5
- /**
6
- * Formats an instruction prompt as an OpenAI chat prompt.
7
- */
8
- export declare const OpenAIChatInstructionPromptFormat: () => PromptFormat<InstructionPrompt, Array<OpenAIChatMessage>>;
9
- /**
10
- * Formats a chat prompt as an OpenAI chat prompt.
11
- */
12
- export declare const OpenAIChatChatPromptFormat: () => PromptFormat<ChatPrompt, Array<OpenAIChatMessage>>;
@@ -1,69 +0,0 @@
1
- import { validateChatPrompt } from "./chat/validateChatPrompt.js";
2
- /**
3
- * Formats an instruction prompt as an OpenAI chat prompt.
4
- */
5
- export const OpenAIChatInstructionPromptFormat = () => ({
6
- format: (instruction) => {
7
- const messages = [];
8
- if (instruction.system != null) {
9
- messages.push({
10
- role: "system",
11
- content: instruction.system,
12
- });
13
- }
14
- messages.push({
15
- role: "user",
16
- content: instruction.instruction,
17
- });
18
- if (instruction.input != null) {
19
- messages.push({
20
- role: "user",
21
- content: instruction.input,
22
- });
23
- }
24
- return messages;
25
- },
26
- stopSequences: [],
27
- });
28
- /**
29
- * Formats a chat prompt as an OpenAI chat prompt.
30
- */
31
- export const OpenAIChatChatPromptFormat = () => ({
32
- format: (chatPrompt) => {
33
- validateChatPrompt(chatPrompt);
34
- const messages = [];
35
- for (let i = 0; i < chatPrompt.length; i++) {
36
- const message = chatPrompt[i];
37
- // system message:
38
- if (i === 0 &&
39
- "system" in message &&
40
- typeof message.system === "string") {
41
- messages.push({
42
- role: "system",
43
- content: message.system,
44
- });
45
- continue;
46
- }
47
- // user message
48
- if ("user" in message) {
49
- messages.push({
50
- role: "user",
51
- content: message.user,
52
- });
53
- continue;
54
- }
55
- // ai message:
56
- if ("ai" in message) {
57
- messages.push({
58
- role: "assistant",
59
- content: message.ai,
60
- });
61
- continue;
62
- }
63
- // unsupported message:
64
- throw new Error(`Unsupported message: ${JSON.stringify(message)}`);
65
- }
66
- return messages;
67
- },
68
- stopSequences: [],
69
- });