modelfusion 0.46.0 → 0.47.1

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 (143) hide show
  1. package/README.md +23 -2
  2. package/index.cjs +0 -1
  3. package/index.d.ts +0 -1
  4. package/index.js +0 -1
  5. package/model-function/ModelFunctionPromise.cjs +37 -0
  6. package/model-function/ModelFunctionPromise.d.ts +18 -0
  7. package/model-function/ModelFunctionPromise.js +33 -0
  8. package/{prompt → model-function}/PromptFormat.d.ts +0 -5
  9. package/model-function/describe-image/describeImage.cjs +3 -2
  10. package/model-function/describe-image/describeImage.d.ts +1 -1
  11. package/model-function/describe-image/describeImage.js +3 -2
  12. package/model-function/embed/embed.cjs +5 -4
  13. package/model-function/embed/embed.d.ts +1 -1
  14. package/model-function/embed/embed.js +5 -4
  15. package/model-function/executeCall.cjs +3 -46
  16. package/model-function/executeCall.d.ts +5 -18
  17. package/model-function/executeCall.js +1 -43
  18. package/model-function/generate-image/ImageGenerationModel.d.ts +2 -0
  19. package/model-function/generate-image/ImageGenerationPromise.cjs +50 -0
  20. package/model-function/generate-image/ImageGenerationPromise.d.ts +22 -0
  21. package/model-function/generate-image/ImageGenerationPromise.js +46 -0
  22. package/model-function/generate-image/PromptFormatImageGenerationModel.cjs +44 -0
  23. package/model-function/generate-image/PromptFormatImageGenerationModel.d.ts +20 -0
  24. package/model-function/generate-image/PromptFormatImageGenerationModel.js +40 -0
  25. package/model-function/generate-image/generateImage.cjs +3 -2
  26. package/model-function/generate-image/generateImage.d.ts +2 -2
  27. package/model-function/generate-image/generateImage.js +3 -2
  28. package/model-function/generate-structure/fixJson.test.cjs +183 -181
  29. package/model-function/generate-structure/fixJson.test.js +181 -182
  30. package/model-function/generate-structure/generateStructure.cjs +3 -2
  31. package/model-function/generate-structure/generateStructure.d.ts +1 -1
  32. package/model-function/generate-structure/generateStructure.js +3 -2
  33. package/model-function/generate-structure/generateStructureOrText.cjs +3 -2
  34. package/model-function/generate-structure/generateStructureOrText.d.ts +1 -1
  35. package/model-function/generate-structure/generateStructureOrText.js +3 -2
  36. package/model-function/generate-structure/streamStructure.cjs +2 -7
  37. package/model-function/generate-structure/streamStructure.js +2 -4
  38. package/{prompt → model-function/generate-text}/AlpacaPromptFormat.d.ts +2 -2
  39. package/{prompt → model-function/generate-text}/Llama2PromptFormat.cjs +1 -1
  40. package/model-function/generate-text/Llama2PromptFormat.d.ts +13 -0
  41. package/{prompt → model-function/generate-text}/Llama2PromptFormat.js +1 -1
  42. package/{prompt → model-function/generate-text}/PromptFormatTextGenerationModel.d.ts +7 -7
  43. package/{prompt → model-function/generate-text}/PromptFormatTextStreamingModel.d.ts +6 -6
  44. package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
  45. package/model-function/generate-text/TextGenerationPromptFormat.cjs +2 -0
  46. package/model-function/generate-text/TextGenerationPromptFormat.d.ts +11 -0
  47. package/model-function/generate-text/TextGenerationPromptFormat.js +1 -0
  48. package/{prompt → model-function/generate-text}/TextPromptFormat.cjs +1 -1
  49. package/{prompt → model-function/generate-text}/TextPromptFormat.d.ts +4 -4
  50. package/{prompt → model-function/generate-text}/TextPromptFormat.js +1 -1
  51. package/{prompt → model-function/generate-text}/VicunaPromptFormat.cjs +1 -1
  52. package/{prompt → model-function/generate-text}/VicunaPromptFormat.d.ts +3 -3
  53. package/{prompt → model-function/generate-text}/VicunaPromptFormat.js +1 -1
  54. package/model-function/generate-text/generateText.cjs +6 -3
  55. package/model-function/generate-text/generateText.d.ts +1 -1
  56. package/model-function/generate-text/generateText.js +6 -3
  57. package/{prompt → model-function/generate-text}/index.cjs +9 -4
  58. package/model-function/generate-text/index.d.ts +16 -0
  59. package/model-function/generate-text/index.js +16 -0
  60. package/{prompt/chat → model-function/generate-text}/trimChatPrompt.d.ts +1 -1
  61. package/model-function/index.cjs +3 -5
  62. package/model-function/index.d.ts +3 -5
  63. package/model-function/index.js +3 -5
  64. package/model-function/synthesize-speech/synthesizeSpeech.cjs +3 -2
  65. package/model-function/synthesize-speech/synthesizeSpeech.d.ts +1 -1
  66. package/model-function/synthesize-speech/synthesizeSpeech.js +3 -2
  67. package/model-function/transcribe-speech/transcribe.cjs +3 -2
  68. package/model-function/transcribe-speech/transcribe.d.ts +1 -1
  69. package/model-function/transcribe-speech/transcribe.js +3 -2
  70. package/model-provider/anthropic/AnthropicPromptFormat.cjs +1 -1
  71. package/model-provider/anthropic/AnthropicPromptFormat.d.ts +5 -5
  72. package/model-provider/anthropic/AnthropicPromptFormat.js +1 -1
  73. package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +1 -1
  74. package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +3 -3
  75. package/model-provider/anthropic/AnthropicTextGenerationModel.js +1 -1
  76. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +11 -0
  77. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +12 -12
  78. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +11 -0
  79. package/model-provider/automatic1111/Automatic1111ImageGenerationPrompt.cjs +12 -0
  80. package/model-provider/automatic1111/Automatic1111ImageGenerationPrompt.d.ts +10 -0
  81. package/model-provider/automatic1111/Automatic1111ImageGenerationPrompt.js +8 -0
  82. package/model-provider/automatic1111/index.cjs +1 -0
  83. package/model-provider/automatic1111/index.d.ts +1 -0
  84. package/model-provider/automatic1111/index.js +1 -0
  85. package/model-provider/cohere/CohereTextGenerationModel.cjs +2 -2
  86. package/model-provider/cohere/CohereTextGenerationModel.d.ts +3 -3
  87. package/model-provider/cohere/CohereTextGenerationModel.js +2 -2
  88. package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +2 -2
  89. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +5 -5
  90. package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +2 -2
  91. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +1 -1
  92. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +3 -3
  93. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +1 -1
  94. package/model-provider/openai/OpenAIImageGenerationModel.cjs +8 -1
  95. package/model-provider/openai/OpenAIImageGenerationModel.d.ts +6 -3
  96. package/model-provider/openai/OpenAIImageGenerationModel.js +8 -1
  97. package/model-provider/openai/OpenAITextGenerationModel.cjs +2 -2
  98. package/model-provider/openai/OpenAITextGenerationModel.d.ts +3 -3
  99. package/model-provider/openai/OpenAITextGenerationModel.js +2 -2
  100. package/model-provider/openai/chat/OpenAIChatModel.cjs +1 -1
  101. package/model-provider/openai/chat/OpenAIChatModel.d.ts +3 -3
  102. package/model-provider/openai/chat/OpenAIChatModel.js +1 -1
  103. package/model-provider/openai/chat/OpenAIChatPromptFormat.cjs +1 -1
  104. package/model-provider/openai/chat/OpenAIChatPromptFormat.d.ts +5 -5
  105. package/model-provider/openai/chat/OpenAIChatPromptFormat.js +1 -1
  106. package/model-provider/stability/StabilityImageGenerationModel.cjs +11 -0
  107. package/model-provider/stability/StabilityImageGenerationModel.d.ts +15 -14
  108. package/model-provider/stability/StabilityImageGenerationModel.js +11 -0
  109. package/model-provider/stability/StabilityImageGenerationPrompt.cjs +12 -0
  110. package/model-provider/stability/StabilityImageGenerationPrompt.d.ts +9 -0
  111. package/model-provider/stability/StabilityImageGenerationPrompt.js +8 -0
  112. package/model-provider/stability/index.cjs +1 -0
  113. package/model-provider/stability/index.d.ts +1 -0
  114. package/model-provider/stability/index.js +1 -0
  115. package/package.json +4 -4
  116. package/util/isDeepEqualData.cjs +53 -0
  117. package/util/isDeepEqualData.d.ts +8 -0
  118. package/util/isDeepEqualData.js +49 -0
  119. package/util/isDeepEqualData.test.cjs +108 -0
  120. package/util/isDeepEqualData.test.d.ts +1 -0
  121. package/util/isDeepEqualData.test.js +103 -0
  122. package/prompt/Llama2PromptFormat.d.ts +0 -13
  123. package/prompt/index.d.ts +0 -11
  124. package/prompt/index.js +0 -11
  125. /package/{prompt → model-function}/PromptFormat.cjs +0 -0
  126. /package/{prompt → model-function}/PromptFormat.js +0 -0
  127. /package/{prompt → model-function/generate-text}/AlpacaPromptFormat.cjs +0 -0
  128. /package/{prompt → model-function/generate-text}/AlpacaPromptFormat.js +0 -0
  129. /package/{prompt/chat → model-function/generate-text}/ChatPrompt.cjs +0 -0
  130. /package/{prompt/chat → model-function/generate-text}/ChatPrompt.d.ts +0 -0
  131. /package/{prompt/chat → model-function/generate-text}/ChatPrompt.js +0 -0
  132. /package/{prompt → model-function/generate-text}/InstructionPrompt.cjs +0 -0
  133. /package/{prompt → model-function/generate-text}/InstructionPrompt.d.ts +0 -0
  134. /package/{prompt → model-function/generate-text}/InstructionPrompt.js +0 -0
  135. /package/{prompt → model-function/generate-text}/PromptFormatTextGenerationModel.cjs +0 -0
  136. /package/{prompt → model-function/generate-text}/PromptFormatTextGenerationModel.js +0 -0
  137. /package/{prompt → model-function/generate-text}/PromptFormatTextStreamingModel.cjs +0 -0
  138. /package/{prompt → model-function/generate-text}/PromptFormatTextStreamingModel.js +0 -0
  139. /package/{prompt/chat → model-function/generate-text}/trimChatPrompt.cjs +0 -0
  140. /package/{prompt/chat → model-function/generate-text}/trimChatPrompt.js +0 -0
  141. /package/{prompt/chat → model-function/generate-text}/validateChatPrompt.cjs +0 -0
  142. /package/{prompt/chat → model-function/generate-text}/validateChatPrompt.d.ts +0 -0
  143. /package/{prompt/chat → model-function/generate-text}/validateChatPrompt.js +0 -0
@@ -1,184 +1,183 @@
1
- import { expect, test, describe } from "vitest";
2
- import { fixJson } from "./fixJson";
3
- describe("fixJson", () => {
4
- test("should handle empty input", () => {
5
- expect(fixJson("")).toBe("");
6
- });
7
- describe("literals", () => {
8
- test("should handle incomplete null", () => {
9
- expect(fixJson("nul")).toBe("null");
10
- });
11
- test("should handle incomplete true", () => {
12
- expect(fixJson("t")).toBe("true");
13
- });
14
- test("should handle incomplete false", () => {
15
- expect(fixJson("fals")).toBe("false");
16
- });
17
- });
18
- describe("number", () => {
19
- test("should handle incomplete numbers", () => {
20
- expect(fixJson("12.")).toBe("12");
21
- });
22
- test("should handle numbers with dot", () => {
23
- expect(fixJson("12.2")).toBe("12.2");
24
- });
25
- test("should handle negative numbers", () => {
26
- expect(fixJson("-12")).toBe("-12");
27
- });
28
- test("should handle incomplete negative numbers", () => {
29
- expect(fixJson("-")).toBe("");
30
- });
31
- test("should handle e-notation numbers", () => {
32
- expect(fixJson("2.5e")).toBe("2.5");
33
- expect(fixJson("2.5e-")).toBe("2.5");
34
- expect(fixJson("2.5e3")).toBe("2.5e3");
35
- expect(fixJson("-2.5e3")).toBe("-2.5e3");
36
- });
37
- test("should handle uppercase e-notation numbers", () => {
38
- expect(fixJson("2.5E")).toBe("2.5");
39
- expect(fixJson("2.5E-")).toBe("2.5");
40
- expect(fixJson("2.5E3")).toBe("2.5E3");
41
- expect(fixJson("-2.5E3")).toBe("-2.5E3");
42
- });
43
- test("should handle incomplete numbers", () => {
44
- expect(fixJson("12.e")).toBe("12");
45
- expect(fixJson("12.34e")).toBe("12.34");
46
- expect(fixJson("5e")).toBe("5");
47
- });
48
- });
49
- describe("string", () => {
50
- test("should handle incomplete strings", () => {
51
- expect(fixJson('"abc')).toBe('"abc"');
52
- });
53
- test("should handle escape sequences", () => {
54
- expect(fixJson('"value with \\"quoted\\" text and \\\\ escape')).toBe('"value with \\"quoted\\" text and \\\\ escape"');
55
- });
56
- test("should handle incomplete escape sequences", () => {
57
- expect(fixJson('"value with \\')).toBe('"value with "');
58
- });
59
- test("should handle unicode characters", () => {
60
- expect(fixJson('"value with unicode \u003C"')).toBe('"value with unicode \u003C"');
61
- });
62
- });
63
- describe("array", () => {
64
- test("should handle incomplete array", () => {
65
- expect(fixJson("[")).toBe("[]");
66
- });
67
- test("should handle closing bracket after number in array", () => {
68
- expect(fixJson("[[1], [2")).toBe("[[1], [2]]");
69
- });
70
- test("should handle closing bracket after string in array", () => {
71
- expect(fixJson(`[["1"], ["2`)).toBe(`[["1"], ["2"]]`);
72
- });
73
- test("should handle closing bracket after literal in array", () => {
74
- expect(fixJson("[[false], [nu")).toBe("[[false], [null]]");
75
- });
76
- test("should handle closing bracket after array in array", () => {
77
- expect(fixJson("[[[]], [[]")).toBe("[[[]], [[]]]");
78
- });
79
- test("should handle closing bracket after object in array", () => {
80
- expect(fixJson("[[{}], [{")).toBe("[[{}], [{}]]");
81
- });
82
- test("should handle trailing comma", () => {
83
- expect(fixJson("[1, ")).toBe("[1]");
84
- });
85
- test("should handle closing array", () => {
86
- expect(fixJson("[[], 123")).toBe("[[], 123]");
87
- });
88
- });
89
- describe("object", () => {
90
- test("should handle keys without values", () => {
91
- expect(fixJson('{"key":')).toBe("{}");
92
- });
93
- test("should handle closing brace after number in object", () => {
94
- expect(fixJson('{"a": {"b": 1}, "c": {"d": 2')).toBe('{"a": {"b": 1}, "c": {"d": 2}}');
95
- });
96
- test("should handle closing brace after string in object", () => {
97
- expect(fixJson('{"a": {"b": "1"}, "c": {"d": 2')).toBe('{"a": {"b": "1"}, "c": {"d": 2}}');
98
- });
99
- test("should handle closing brace after literal in object", () => {
100
- expect(fixJson('{"a": {"b": false}, "c": {"d": 2')).toBe('{"a": {"b": false}, "c": {"d": 2}}');
101
- });
102
- test("should handle closing brace after array in object", () => {
103
- expect(fixJson('{"a": {"b": []}, "c": {"d": 2')).toBe('{"a": {"b": []}, "c": {"d": 2}}');
104
- });
105
- test("should handle closing brace after object in object", () => {
106
- expect(fixJson('{"a": {"b": {}}, "c": {"d": 2')).toBe('{"a": {"b": {}}, "c": {"d": 2}}');
107
- });
108
- test("should handle partial keys (first key)", () => {
109
- expect(fixJson('{"ke')).toBe("{}");
110
- });
111
- test("should handle partial keys (second key)", () => {
112
- expect(fixJson('{"k1": 1, "k2')).toBe('{"k1": 1}');
113
- });
114
- test("should handle partial keys with colon (second key)", () => {
115
- expect(fixJson('{"k1": 1, "k2":')).toBe('{"k1": 1}');
116
- });
117
- test("should handle trailing whitespaces", () => {
118
- expect(fixJson('{"key": "value" ')).toBe('{"key": "value"}');
119
- });
120
- });
121
- describe("nesting", () => {
122
- test("should handle nested arrays with numbers", () => {
123
- expect(fixJson("[1, [2, 3, [")).toBe("[1, [2, 3, []]]");
124
- });
125
- test("should handle nested arrays with literals", () => {
126
- expect(fixJson("[false, [true, [")).toBe("[false, [true, []]]");
127
- });
128
- test("should handle nested objects", () => {
129
- expect(fixJson('{"key": {"subKey":')).toBe('{"key": {}}');
130
- });
131
- test("should handle nested objects with numbers", () => {
132
- expect(fixJson('{"key": 123, "key2": {"subKey":')).toBe('{"key": 123, "key2": {}}');
133
- });
134
- test("should handle nested objects with literals", () => {
135
- expect(fixJson('{"key": null, "key2": {"subKey":')).toBe('{"key": null, "key2": {}}');
136
- });
137
- test("should handle arrays within objects", () => {
138
- expect(fixJson('{"key": [1, 2, {')).toBe('{"key": [1, 2, {}]}');
139
- });
140
- test("should handle objects within arrays", () => {
141
- expect(fixJson('[1, 2, {"key": "value",')).toBe('[1, 2, {"key": "value"}]');
142
- });
143
- test("should handle nested arrays and objects", () => {
144
- expect(fixJson('{"a": {"b": ["c", {"d": "e",')).toBe('{"a": {"b": ["c", {"d": "e"}]}}');
145
- });
146
- test("should handle deeply nested structures", () => {
147
- expect(fixJson('{"a": {"b": {"c": {"d":')).toBe('{"a": {"b": {"c": {}}}}');
148
- });
149
- test("should handle potential nested arrays or objects", () => {
150
- expect(fixJson('{"a": 1, "b": [')).toBe('{"a": 1, "b": []}');
151
- expect(fixJson('{"a": 1, "b": {')).toBe('{"a": 1, "b": {}}');
152
- expect(fixJson('{"a": 1, "b": "')).toBe('{"a": 1, "b": ""}');
153
- });
154
- });
155
- describe("regression", () => {
156
- test("should handle complex nesting 1", () => {
157
- expect(fixJson([
158
- "{",
159
- ' "a": [',
160
- " {",
161
- ' "a1": "v1",',
162
- ' "a2": "v2",',
163
- ` "a3": "v3"`,
164
- " }",
165
- " ],",
166
- ' "b": [',
167
- " {",
168
- ' "b1": "n',
169
- ].join("\n"))).toBe([
170
- "{",
171
- ' "a": [',
172
- " {",
173
- ' "a1": "v1",',
174
- ' "a2": "v2",',
175
- ` "a3": "v3"`,
176
- " }",
177
- " ],",
178
- ' "b": [',
179
- " {",
180
- ' "b1": "n"}]}',
181
- ].join("\n"));
182
- });
1
+ import assert from "node:assert";
2
+ import { test, describe } from "vitest";
3
+ import { fixJson } from "./fixJson.js";
4
+ test("should handle empty input", () => {
5
+ assert.strictEqual(fixJson(""), "");
6
+ });
7
+ describe("literals", () => {
8
+ test("should handle incomplete null", () => {
9
+ assert.strictEqual(fixJson("nul"), "null");
10
+ });
11
+ test("should handle incomplete true", () => {
12
+ assert.strictEqual(fixJson("t"), "true");
13
+ });
14
+ test("should handle incomplete false", () => {
15
+ assert.strictEqual(fixJson("fals"), "false");
16
+ });
17
+ });
18
+ describe("number", () => {
19
+ test("should handle incomplete numbers", () => {
20
+ assert.strictEqual(fixJson("12."), "12");
21
+ });
22
+ test("should handle numbers with dot", () => {
23
+ assert.strictEqual(fixJson("12.2"), "12.2");
24
+ });
25
+ test("should handle negative numbers", () => {
26
+ assert.strictEqual(fixJson("-12"), "-12");
27
+ });
28
+ test("should handle incomplete negative numbers", () => {
29
+ assert.strictEqual(fixJson("-"), "");
30
+ });
31
+ test("should handle e-notation numbers", () => {
32
+ assert.strictEqual(fixJson("2.5e"), "2.5");
33
+ assert.strictEqual(fixJson("2.5e-"), "2.5");
34
+ assert.strictEqual(fixJson("2.5e3"), "2.5e3");
35
+ assert.strictEqual(fixJson("-2.5e3"), "-2.5e3");
36
+ });
37
+ test("should handle uppercase e-notation numbers", () => {
38
+ assert.strictEqual(fixJson("2.5E"), "2.5");
39
+ assert.strictEqual(fixJson("2.5E-"), "2.5");
40
+ assert.strictEqual(fixJson("2.5E3"), "2.5E3");
41
+ assert.strictEqual(fixJson("-2.5E3"), "-2.5E3");
42
+ });
43
+ test("should handle incomplete numbers", () => {
44
+ assert.strictEqual(fixJson("12.e"), "12");
45
+ assert.strictEqual(fixJson("12.34e"), "12.34");
46
+ assert.strictEqual(fixJson("5e"), "5");
47
+ });
48
+ });
49
+ describe("string", () => {
50
+ test("should handle incomplete strings", () => {
51
+ assert.strictEqual(fixJson('"abc'), '"abc"');
52
+ });
53
+ test("should handle escape sequences", () => {
54
+ assert.strictEqual(fixJson('"value with \\"quoted\\" text and \\\\ escape'), '"value with \\"quoted\\" text and \\\\ escape"');
55
+ });
56
+ test("should handle incomplete escape sequences", () => {
57
+ assert.strictEqual(fixJson('"value with \\'), '"value with "');
58
+ });
59
+ test("should handle unicode characters", () => {
60
+ assert.strictEqual(fixJson('"value with unicode \u003C"'), '"value with unicode \u003C"');
61
+ });
62
+ });
63
+ describe("array", () => {
64
+ test("should handle incomplete array", () => {
65
+ assert.strictEqual(fixJson("["), "[]");
66
+ });
67
+ test("should handle closing bracket after number in array", () => {
68
+ assert.strictEqual(fixJson("[[1], [2"), "[[1], [2]]");
69
+ });
70
+ test("should handle closing bracket after string in array", () => {
71
+ assert.strictEqual(fixJson(`[["1"], ["2`), `[["1"], ["2"]]`);
72
+ });
73
+ test("should handle closing bracket after literal in array", () => {
74
+ assert.strictEqual(fixJson("[[false], [nu"), "[[false], [null]]");
75
+ });
76
+ test("should handle closing bracket after array in array", () => {
77
+ assert.strictEqual(fixJson("[[[]], [[]"), "[[[]], [[]]]");
78
+ });
79
+ test("should handle closing bracket after object in array", () => {
80
+ assert.strictEqual(fixJson("[[{}], [{"), "[[{}], [{}]]");
81
+ });
82
+ test("should handle trailing comma", () => {
83
+ assert.strictEqual(fixJson("[1, "), "[1]");
84
+ });
85
+ test("should handle closing array", () => {
86
+ assert.strictEqual(fixJson("[[], 123"), "[[], 123]");
87
+ });
88
+ });
89
+ describe("object", () => {
90
+ test("should handle keys without values", () => {
91
+ assert.strictEqual(fixJson('{"key":'), "{}");
92
+ });
93
+ test("should handle closing brace after number in object", () => {
94
+ assert.strictEqual(fixJson('{"a": {"b": 1}, "c": {"d": 2'), '{"a": {"b": 1}, "c": {"d": 2}}');
95
+ });
96
+ test("should handle closing brace after string in object", () => {
97
+ assert.strictEqual(fixJson('{"a": {"b": "1"}, "c": {"d": 2'), '{"a": {"b": "1"}, "c": {"d": 2}}');
98
+ });
99
+ test("should handle closing brace after literal in object", () => {
100
+ assert.strictEqual(fixJson('{"a": {"b": false}, "c": {"d": 2'), '{"a": {"b": false}, "c": {"d": 2}}');
101
+ });
102
+ test("should handle closing brace after array in object", () => {
103
+ assert.strictEqual(fixJson('{"a": {"b": []}, "c": {"d": 2'), '{"a": {"b": []}, "c": {"d": 2}}');
104
+ });
105
+ test("should handle closing brace after object in object", () => {
106
+ assert.strictEqual(fixJson('{"a": {"b": {}}, "c": {"d": 2'), '{"a": {"b": {}}, "c": {"d": 2}}');
107
+ });
108
+ test("should handle partial keys (first key)", () => {
109
+ assert.strictEqual(fixJson('{"ke'), "{}");
110
+ });
111
+ test("should handle partial keys (second key)", () => {
112
+ assert.strictEqual(fixJson('{"k1": 1, "k2'), '{"k1": 1}');
113
+ });
114
+ test("should handle partial keys with colon (second key)", () => {
115
+ assert.strictEqual(fixJson('{"k1": 1, "k2":'), '{"k1": 1}');
116
+ });
117
+ test("should handle trailing whitespaces", () => {
118
+ assert.strictEqual(fixJson('{"key": "value" '), '{"key": "value"}');
119
+ });
120
+ });
121
+ describe("nesting", () => {
122
+ test("should handle nested arrays with numbers", () => {
123
+ assert.strictEqual(fixJson("[1, [2, 3, ["), "[1, [2, 3, []]]");
124
+ });
125
+ test("should handle nested arrays with literals", () => {
126
+ assert.strictEqual(fixJson("[false, [true, ["), "[false, [true, []]]");
127
+ });
128
+ test("should handle nested objects", () => {
129
+ assert.strictEqual(fixJson('{"key": {"subKey":'), '{"key": {}}');
130
+ });
131
+ test("should handle nested objects with numbers", () => {
132
+ assert.strictEqual(fixJson('{"key": 123, "key2": {"subKey":'), '{"key": 123, "key2": {}}');
133
+ });
134
+ test("should handle nested objects with literals", () => {
135
+ assert.strictEqual(fixJson('{"key": null, "key2": {"subKey":'), '{"key": null, "key2": {}}');
136
+ });
137
+ test("should handle arrays within objects", () => {
138
+ assert.strictEqual(fixJson('{"key": [1, 2, {'), '{"key": [1, 2, {}]}');
139
+ });
140
+ test("should handle objects within arrays", () => {
141
+ assert.strictEqual(fixJson('[1, 2, {"key": "value",'), '[1, 2, {"key": "value"}]');
142
+ });
143
+ test("should handle nested arrays and objects", () => {
144
+ assert.strictEqual(fixJson('{"a": {"b": ["c", {"d": "e",'), '{"a": {"b": ["c", {"d": "e"}]}}');
145
+ });
146
+ test("should handle deeply nested structures", () => {
147
+ assert.strictEqual(fixJson('{"a": {"b": {"c": {"d":'), '{"a": {"b": {"c": {}}}}');
148
+ });
149
+ test("should handle potential nested arrays or objects", () => {
150
+ assert.strictEqual(fixJson('{"a": 1, "b": ['), '{"a": 1, "b": []}');
151
+ assert.strictEqual(fixJson('{"a": 1, "b": {'), '{"a": 1, "b": {}}');
152
+ assert.strictEqual(fixJson('{"a": 1, "b": "'), '{"a": 1, "b": ""}');
153
+ });
154
+ });
155
+ describe("regression", () => {
156
+ test("should handle complex nesting 1", () => {
157
+ assert.strictEqual(fixJson([
158
+ "{",
159
+ ' "a": [',
160
+ " {",
161
+ ' "a1": "v1",',
162
+ ' "a2": "v2",',
163
+ ` "a3": "v3"`,
164
+ " }",
165
+ " ],",
166
+ ' "b": [',
167
+ " {",
168
+ ' "b1": "n',
169
+ ].join("\n")), [
170
+ "{",
171
+ ' "a": [',
172
+ " {",
173
+ ' "a1": "v1",',
174
+ ' "a2": "v2",',
175
+ ` "a3": "v3"`,
176
+ " }",
177
+ " ],",
178
+ ' "b": [',
179
+ " {",
180
+ ' "b1": "n"}]}',
181
+ ].join("\n"));
183
182
  });
184
183
  });
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStructure = void 0;
4
4
  const executeCall_js_1 = require("../executeCall.cjs");
5
+ const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
5
6
  const StructureValidationError_js_1 = require("./StructureValidationError.cjs");
6
7
  function generateStructure(model, structureDefinition, prompt, options) {
7
8
  // Note: PROMPT must not be a function.
8
9
  const expandedPrompt = typeof prompt === "function"
9
10
  ? prompt(structureDefinition)
10
11
  : prompt;
11
- return (0, executeCall_js_1.executeCall)({
12
+ return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeCall_js_1.executeCall)({
12
13
  functionType: "structure-generation",
13
14
  input: expandedPrompt,
14
15
  model,
@@ -32,6 +33,6 @@ function generateStructure(model, structureDefinition, prompt, options) {
32
33
  usage: result.usage,
33
34
  };
34
35
  },
35
- });
36
+ }));
36
37
  }
37
38
  exports.generateStructure = generateStructure;
@@ -1,5 +1,5 @@
1
1
  import { FunctionOptions } from "../../core/FunctionOptions.js";
2
2
  import { StructureDefinition } from "../../core/structure/StructureDefinition.js";
3
- import { ModelFunctionPromise } from "../executeCall.js";
3
+ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
4
4
  import { StructureGenerationModel, StructureGenerationModelSettings } from "./StructureGenerationModel.js";
5
5
  export declare function generateStructure<STRUCTURE, PROMPT, NAME extends string, SETTINGS extends StructureGenerationModelSettings>(model: StructureGenerationModel<PROMPT, SETTINGS>, structureDefinition: StructureDefinition<NAME, STRUCTURE>, prompt: PROMPT | ((structureDefinition: StructureDefinition<NAME, STRUCTURE>) => PROMPT), options?: FunctionOptions): ModelFunctionPromise<STRUCTURE>;
@@ -1,11 +1,12 @@
1
1
  import { executeCall } from "../executeCall.js";
2
+ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
2
3
  import { StructureValidationError } from "./StructureValidationError.js";
3
4
  export function generateStructure(model, structureDefinition, prompt, options) {
4
5
  // Note: PROMPT must not be a function.
5
6
  const expandedPrompt = typeof prompt === "function"
6
7
  ? prompt(structureDefinition)
7
8
  : prompt;
8
- return executeCall({
9
+ return new ModelFunctionPromise(executeCall({
9
10
  functionType: "structure-generation",
10
11
  input: expandedPrompt,
11
12
  model,
@@ -29,5 +30,5 @@ export function generateStructure(model, structureDefinition, prompt, options) {
29
30
  usage: result.usage,
30
31
  };
31
32
  },
32
- });
33
+ }));
33
34
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStructureOrText = void 0;
4
4
  const executeCall_js_1 = require("../executeCall.cjs");
5
+ const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
5
6
  const NoSuchStructureError_js_1 = require("./NoSuchStructureError.cjs");
6
7
  const StructureValidationError_js_1 = require("./StructureValidationError.cjs");
7
8
  function generateStructureOrText(model, structureDefinitions, prompt, options) {
@@ -9,7 +10,7 @@ function generateStructureOrText(model, structureDefinitions, prompt, options) {
9
10
  const expandedPrompt = typeof prompt === "function"
10
11
  ? prompt(structureDefinitions)
11
12
  : prompt;
12
- return (0, executeCall_js_1.executeCall)({
13
+ return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeCall_js_1.executeCall)({
13
14
  functionType: "structure-or-text-generation",
14
15
  input: expandedPrompt,
15
16
  model,
@@ -48,6 +49,6 @@ function generateStructureOrText(model, structureDefinitions, prompt, options) {
48
49
  usage: result.usage,
49
50
  };
50
51
  },
51
- });
52
+ }));
52
53
  }
53
54
  exports.generateStructureOrText = generateStructureOrText;
@@ -1,6 +1,6 @@
1
1
  import { FunctionOptions } from "../../core/FunctionOptions.js";
2
2
  import { StructureDefinition } from "../../core/structure/StructureDefinition.js";
3
- import { ModelFunctionPromise } from "../executeCall.js";
3
+ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
4
4
  import { StructureOrTextGenerationModel, StructureOrTextGenerationModelSettings } from "./StructureOrTextGenerationModel.js";
5
5
  type StructureDefinitionArray<T extends StructureDefinition<any, any>[]> = T;
6
6
  type ToStructureDefinitionMap<T extends StructureDefinitionArray<StructureDefinition<any, any>[]>> = {
@@ -1,4 +1,5 @@
1
1
  import { executeCall } from "../executeCall.js";
2
+ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
2
3
  import { NoSuchStructureError } from "./NoSuchStructureError.js";
3
4
  import { StructureValidationError } from "./StructureValidationError.js";
4
5
  export function generateStructureOrText(model, structureDefinitions, prompt, options) {
@@ -6,7 +7,7 @@ export function generateStructureOrText(model, structureDefinitions, prompt, opt
6
7
  const expandedPrompt = typeof prompt === "function"
7
8
  ? prompt(structureDefinitions)
8
9
  : prompt;
9
- return executeCall({
10
+ return new ModelFunctionPromise(executeCall({
10
11
  functionType: "structure-or-text-generation",
11
12
  input: expandedPrompt,
12
13
  model,
@@ -45,5 +46,5 @@ export function generateStructureOrText(model, structureDefinitions, prompt, opt
45
46
  usage: result.usage,
46
47
  };
47
48
  },
48
- });
49
+ }));
49
50
  }
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.streamStructure = void 0;
7
- const deep_equal_1 = __importDefault(require("deep-equal"));
8
4
  const nanoid_1 = require("nanoid");
9
5
  const FunctionEventSource_js_1 = require("../../core/FunctionEventSource.cjs");
10
6
  const GlobalFunctionLogging_js_1 = require("../../core/GlobalFunctionLogging.cjs");
@@ -13,6 +9,7 @@ const AbortError_js_1 = require("../../core/api/AbortError.cjs");
13
9
  const getFunctionCallLogger_js_1 = require("../../core/getFunctionCallLogger.cjs");
14
10
  const getRun_js_1 = require("../../core/getRun.cjs");
15
11
  const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
12
+ const isDeepEqualData_js_1 = require("../../util/isDeepEqualData.cjs");
16
13
  const runSafe_js_1 = require("../../util/runSafe.cjs");
17
14
  const AsyncIterableResultPromise_js_1 = require("../AsyncIterableResultPromise.cjs");
18
15
  function streamStructure(model, structureDefinition, prompt, options) {
@@ -91,9 +88,7 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
91
88
  const latestFullDelta = event.fullDelta;
92
89
  const latestStructure = event.valueDelta;
93
90
  // only send a new part into the stream when the partial structure has changed:
94
- if (!(0, deep_equal_1.default)(lastStructure, latestStructure, {
95
- strict: true,
96
- })) {
91
+ if (!(0, isDeepEqualData_js_1.isDeepEqualData)(lastStructure, latestStructure)) {
97
92
  lastFullDelta = latestFullDelta;
98
93
  lastStructure = latestStructure;
99
94
  yield {
@@ -1,4 +1,3 @@
1
- import deepEqual from "deep-equal";
2
1
  import { nanoid as createId } from "nanoid";
3
2
  import { FunctionEventSource } from "../../core/FunctionEventSource.js";
4
3
  import { getGlobalFunctionLogging } from "../../core/GlobalFunctionLogging.js";
@@ -7,6 +6,7 @@ import { AbortError } from "../../core/api/AbortError.js";
7
6
  import { getFunctionCallLogger } from "../../core/getFunctionCallLogger.js";
8
7
  import { getRun } from "../../core/getRun.js";
9
8
  import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
9
+ import { isDeepEqualData } from "../../util/isDeepEqualData.js";
10
10
  import { runSafe } from "../../util/runSafe.js";
11
11
  import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
12
12
  export function streamStructure(model, structureDefinition, prompt, options) {
@@ -84,9 +84,7 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
84
84
  const latestFullDelta = event.fullDelta;
85
85
  const latestStructure = event.valueDelta;
86
86
  // only send a new part into the stream when the partial structure has changed:
87
- if (!deepEqual(lastStructure, latestStructure, {
88
- strict: true,
89
- })) {
87
+ if (!isDeepEqualData(lastStructure, latestStructure)) {
90
88
  lastFullDelta = latestFullDelta;
91
89
  lastStructure = latestStructure;
92
90
  yield {
@@ -1,5 +1,5 @@
1
1
  import { InstructionPrompt } from "./InstructionPrompt.js";
2
- import { PromptFormat } from "./PromptFormat.js";
2
+ import { TextGenerationPromptFormat } from "./TextGenerationPromptFormat.js";
3
3
  /**
4
4
  * Formats an instruction prompt as an Alpaca prompt.
5
5
  *
@@ -8,4 +8,4 @@ import { PromptFormat } from "./PromptFormat.js";
8
8
  *
9
9
  * @see https://github.com/tatsu-lab/stanford_alpaca#data-release
10
10
  */
11
- export declare function mapInstructionPromptToAlpacaFormat(): PromptFormat<InstructionPrompt, string>;
11
+ export declare function mapInstructionPromptToAlpacaFormat(): TextGenerationPromptFormat<InstructionPrompt, string>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapChatPromptToLlama2Format = exports.mapInstructionPromptToLlama2Format = void 0;
4
- const validateChatPrompt_js_1 = require("./chat/validateChatPrompt.cjs");
4
+ const validateChatPrompt_js_1 = require("./validateChatPrompt.cjs");
5
5
  // see https://github.com/facebookresearch/llama/blob/6c7fe276574e78057f917549435a2554000a876d/llama/generation.py#L44
6
6
  const BEGIN_SEGMENT = "<s>";
7
7
  const END_SEGMENT = "</s>\n";
@@ -0,0 +1,13 @@
1
+ import { ChatPrompt } from "./ChatPrompt.js";
2
+ import { InstructionPrompt } from "./InstructionPrompt.js";
3
+ import { TextGenerationPromptFormat } from "./TextGenerationPromptFormat.js";
4
+ /**
5
+ * Formats an instruction prompt as a Llama 2 prompt.
6
+ *
7
+ * @see https://www.philschmid.de/llama-2#how-to-prompt-llama-2-chat
8
+ */
9
+ export declare function mapInstructionPromptToLlama2Format(): TextGenerationPromptFormat<InstructionPrompt, string>;
10
+ /**
11
+ * Formats a chat prompt as a Llama 2 prompt.
12
+ */
13
+ export declare function mapChatPromptToLlama2Format(): TextGenerationPromptFormat<ChatPrompt, string>;
@@ -1,4 +1,4 @@
1
- import { validateChatPrompt } from "./chat/validateChatPrompt.js";
1
+ import { validateChatPrompt } from "./validateChatPrompt.js";
2
2
  // see https://github.com/facebookresearch/llama/blob/6c7fe276574e78057f917549435a2554000a876d/llama/generation.py#L44
3
3
  const BEGIN_SEGMENT = "<s>";
4
4
  const END_SEGMENT = "</s>\n";
@@ -1,14 +1,14 @@
1
- import { FunctionOptions } from "../core/FunctionOptions.js";
2
- import { TextGenerationModel, TextGenerationModelSettings } from "../model-function/generate-text/TextGenerationModel.js";
3
- import { PromptFormat } from "./PromptFormat.js";
1
+ import { FunctionOptions } from "../../core/FunctionOptions.js";
2
+ import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerationModel.js";
3
+ import { TextGenerationPromptFormat } from "./TextGenerationPromptFormat.js";
4
4
  export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, SETTINGS extends TextGenerationModelSettings, MODEL extends TextGenerationModel<MODEL_PROMPT, SETTINGS>> implements TextGenerationModel<PROMPT, SETTINGS> {
5
5
  readonly model: MODEL;
6
- readonly promptFormat: PromptFormat<PROMPT, MODEL_PROMPT>;
6
+ readonly promptFormat: TextGenerationPromptFormat<PROMPT, MODEL_PROMPT>;
7
7
  constructor({ model, promptFormat, }: {
8
8
  model: MODEL;
9
- promptFormat: PromptFormat<PROMPT, MODEL_PROMPT>;
9
+ promptFormat: TextGenerationPromptFormat<PROMPT, MODEL_PROMPT>;
10
10
  });
11
- get modelInformation(): import("../index.js").ModelInformation;
11
+ get modelInformation(): import("../ModelInformation.js").ModelInformation;
12
12
  get settings(): SETTINGS;
13
13
  get tokenizer(): MODEL["tokenizer"];
14
14
  get contextWindowSize(): MODEL["contextWindowSize"];
@@ -23,6 +23,6 @@ export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, SETTI
23
23
  } | undefined;
24
24
  }>;
25
25
  get settingsForEvent(): Partial<SETTINGS>;
26
- withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, PROMPT>): PromptFormatTextGenerationModel<INPUT_PROMPT, PROMPT, SETTINGS, this>;
26
+ withPromptFormat<INPUT_PROMPT>(promptFormat: TextGenerationPromptFormat<INPUT_PROMPT, PROMPT>): PromptFormatTextGenerationModel<INPUT_PROMPT, PROMPT, SETTINGS, this>;
27
27
  withSettings(additionalSettings: Partial<SETTINGS>): this;
28
28
  }