@langchain/openai 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/azure/chat_models.cjs +48 -0
- package/dist/azure/chat_models.d.ts +17 -0
- package/dist/azure/chat_models.js +44 -0
- package/dist/azure/llms.cjs +45 -0
- package/dist/azure/llms.d.ts +16 -0
- package/dist/azure/llms.js +41 -0
- package/dist/embeddings.cjs +2 -2
- package/dist/embeddings.js +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/llms.cjs +3 -3
- package/dist/llms.js +1 -1
- package/dist/tests/chat_models-extended.int.test.d.ts +1 -0
- package/dist/tests/chat_models-extended.int.test.js +194 -0
- package/dist/tests/chat_models-vision.int.test.d.ts +1 -0
- package/dist/tests/chat_models-vision.int.test.js +51 -0
- package/dist/tests/chat_models.int.test.d.ts +1 -0
- package/dist/tests/chat_models.int.test.js +627 -0
- package/dist/tests/legacy.int.test.d.ts +1 -0
- package/dist/tests/legacy.int.test.js +115 -0
- package/dist/tests/llms.int.test.d.ts +1 -0
- package/dist/tests/llms.int.test.js +257 -0
- package/package.json +2 -2
- package/dist/utils/chunk.cjs +0 -11
- package/dist/utils/chunk.d.ts +0 -1
- package/dist/utils/chunk.js +0 -7
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { expect, test } from "@jest/globals";
|
|
2
|
+
import { CallbackManager } from "@langchain/core/callbacks/manager";
|
|
3
|
+
import { OpenAIChat } from "../legacy.js";
|
|
4
|
+
test("Test OpenAI", async () => {
|
|
5
|
+
const model = new OpenAIChat({ modelName: "gpt-3.5-turbo", maxTokens: 10 });
|
|
6
|
+
const res = await model.call("Print hello world");
|
|
7
|
+
console.log({ res });
|
|
8
|
+
});
|
|
9
|
+
test("Test OpenAI with prefix messages", async () => {
|
|
10
|
+
const model = new OpenAIChat({
|
|
11
|
+
prefixMessages: [
|
|
12
|
+
{ role: "user", content: "My name is John" },
|
|
13
|
+
{ role: "assistant", content: "Hi there" },
|
|
14
|
+
],
|
|
15
|
+
maxTokens: 10,
|
|
16
|
+
});
|
|
17
|
+
const res = await model.call("What is my name");
|
|
18
|
+
console.log({ res });
|
|
19
|
+
});
|
|
20
|
+
test("Test OpenAI in streaming mode", async () => {
|
|
21
|
+
let nrNewTokens = 0;
|
|
22
|
+
let streamedCompletion = "";
|
|
23
|
+
const model = new OpenAIChat({
|
|
24
|
+
maxTokens: 10,
|
|
25
|
+
modelName: "gpt-3.5-turbo",
|
|
26
|
+
streaming: true,
|
|
27
|
+
callbackManager: CallbackManager.fromHandlers({
|
|
28
|
+
async handleLLMNewToken(token) {
|
|
29
|
+
nrNewTokens += 1;
|
|
30
|
+
streamedCompletion += token;
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
const res = await model.call("Print hello world");
|
|
35
|
+
console.log({ res });
|
|
36
|
+
expect(nrNewTokens > 0).toBe(true);
|
|
37
|
+
expect(res).toBe(streamedCompletion);
|
|
38
|
+
}, 30000);
|
|
39
|
+
test("Test OpenAI with stop", async () => {
|
|
40
|
+
const model = new OpenAIChat({ maxTokens: 5 });
|
|
41
|
+
const res = await model.call("Print hello world", ["world"]);
|
|
42
|
+
console.log({ res });
|
|
43
|
+
});
|
|
44
|
+
test("Test OpenAI with stop in object", async () => {
|
|
45
|
+
const model = new OpenAIChat({ maxTokens: 5 });
|
|
46
|
+
const res = await model.call("Print hello world", { stop: ["world"] });
|
|
47
|
+
console.log({ res });
|
|
48
|
+
});
|
|
49
|
+
test("Test OpenAI with timeout in call options", async () => {
|
|
50
|
+
const model = new OpenAIChat({ maxTokens: 5 });
|
|
51
|
+
await expect(() => model.call("Print hello world", {
|
|
52
|
+
timeout: 10,
|
|
53
|
+
})).rejects.toThrow();
|
|
54
|
+
}, 5000);
|
|
55
|
+
test("Test OpenAI with timeout in call options and node adapter", async () => {
|
|
56
|
+
const model = new OpenAIChat({ maxTokens: 5 });
|
|
57
|
+
await expect(() => model.call("Print hello world", {
|
|
58
|
+
timeout: 10,
|
|
59
|
+
})).rejects.toThrow();
|
|
60
|
+
}, 5000);
|
|
61
|
+
test("Test OpenAI with signal in call options", async () => {
|
|
62
|
+
const model = new OpenAIChat({ maxTokens: 5 });
|
|
63
|
+
const controller = new AbortController();
|
|
64
|
+
await expect(() => {
|
|
65
|
+
const ret = model.call("Print hello world", {
|
|
66
|
+
signal: controller.signal,
|
|
67
|
+
});
|
|
68
|
+
controller.abort();
|
|
69
|
+
return ret;
|
|
70
|
+
}).rejects.toThrow();
|
|
71
|
+
}, 5000);
|
|
72
|
+
test("Test OpenAI with signal in call options and node adapter", async () => {
|
|
73
|
+
const model = new OpenAIChat({ maxTokens: 5 });
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
await expect(() => {
|
|
76
|
+
const ret = model.call("Print hello world", {
|
|
77
|
+
signal: controller.signal,
|
|
78
|
+
});
|
|
79
|
+
controller.abort();
|
|
80
|
+
return ret;
|
|
81
|
+
}).rejects.toThrow();
|
|
82
|
+
}, 5000);
|
|
83
|
+
test("Test OpenAIChat stream method", async () => {
|
|
84
|
+
const model = new OpenAIChat({ maxTokens: 50, modelName: "gpt-3.5-turbo" });
|
|
85
|
+
const stream = await model.stream("Print hello world.");
|
|
86
|
+
const chunks = [];
|
|
87
|
+
for await (const chunk of stream) {
|
|
88
|
+
chunks.push(chunk);
|
|
89
|
+
console.log(chunks);
|
|
90
|
+
}
|
|
91
|
+
expect(chunks.length).toBeGreaterThan(1);
|
|
92
|
+
});
|
|
93
|
+
test("Test OpenAIChat stream method with abort", async () => {
|
|
94
|
+
await expect(async () => {
|
|
95
|
+
const model = new OpenAIChat({ maxTokens: 50, modelName: "gpt-3.5-turbo" });
|
|
96
|
+
const stream = await model.stream("How is your day going? Be extremely verbose.", {
|
|
97
|
+
signal: AbortSignal.timeout(1000),
|
|
98
|
+
});
|
|
99
|
+
for await (const chunk of stream) {
|
|
100
|
+
console.log(chunk);
|
|
101
|
+
}
|
|
102
|
+
}).rejects.toThrow();
|
|
103
|
+
});
|
|
104
|
+
test("Test OpenAIChat stream method with early break", async () => {
|
|
105
|
+
const model = new OpenAIChat({ maxTokens: 50, modelName: "gpt-3.5-turbo" });
|
|
106
|
+
const stream = await model.stream("How is your day going? Be extremely verbose.");
|
|
107
|
+
let i = 0;
|
|
108
|
+
for await (const chunk of stream) {
|
|
109
|
+
console.log(chunk);
|
|
110
|
+
i += 1;
|
|
111
|
+
if (i > 5) {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { StringPromptValue } from "@langchain/core/prompt_values";
|
|
3
|
+
import { CallbackManager } from "@langchain/core/callbacks/manager";
|
|
4
|
+
import { OpenAIChat } from "../legacy.js";
|
|
5
|
+
import { OpenAI } from "../llms.js";
|
|
6
|
+
test("Test OpenAI", async () => {
|
|
7
|
+
const model = new OpenAI({
|
|
8
|
+
maxTokens: 5,
|
|
9
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
10
|
+
});
|
|
11
|
+
const res = await model.call("Print hello world");
|
|
12
|
+
console.log({ res });
|
|
13
|
+
});
|
|
14
|
+
test("Test OpenAI with stop", async () => {
|
|
15
|
+
const model = new OpenAI({
|
|
16
|
+
maxTokens: 5,
|
|
17
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
18
|
+
});
|
|
19
|
+
const res = await model.call("Print hello world", ["world"]);
|
|
20
|
+
console.log({ res });
|
|
21
|
+
});
|
|
22
|
+
test("Test OpenAI with stop in object", async () => {
|
|
23
|
+
const model = new OpenAI({
|
|
24
|
+
maxTokens: 5,
|
|
25
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
26
|
+
});
|
|
27
|
+
const res = await model.call("Print hello world", { stop: ["world"] });
|
|
28
|
+
console.log({ res });
|
|
29
|
+
});
|
|
30
|
+
test("Test OpenAI with timeout in call options", async () => {
|
|
31
|
+
const model = new OpenAI({
|
|
32
|
+
maxTokens: 5,
|
|
33
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
34
|
+
});
|
|
35
|
+
await expect(() => model.call("Print hello world", {
|
|
36
|
+
timeout: 10,
|
|
37
|
+
})).rejects.toThrow();
|
|
38
|
+
}, 5000);
|
|
39
|
+
test("Test OpenAI with timeout in call options and node adapter", async () => {
|
|
40
|
+
const model = new OpenAI({
|
|
41
|
+
maxTokens: 5,
|
|
42
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
43
|
+
});
|
|
44
|
+
await expect(() => model.call("Print hello world", {
|
|
45
|
+
timeout: 10,
|
|
46
|
+
})).rejects.toThrow();
|
|
47
|
+
}, 5000);
|
|
48
|
+
test("Test OpenAI with signal in call options", async () => {
|
|
49
|
+
const model = new OpenAI({
|
|
50
|
+
maxTokens: 5,
|
|
51
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
52
|
+
});
|
|
53
|
+
const controller = new AbortController();
|
|
54
|
+
await expect(() => {
|
|
55
|
+
const ret = model.call("Print hello world", {
|
|
56
|
+
signal: controller.signal,
|
|
57
|
+
});
|
|
58
|
+
controller.abort();
|
|
59
|
+
return ret;
|
|
60
|
+
}).rejects.toThrow();
|
|
61
|
+
}, 5000);
|
|
62
|
+
test("Test OpenAI with signal in call options and node adapter", async () => {
|
|
63
|
+
const model = new OpenAI({
|
|
64
|
+
maxTokens: 5,
|
|
65
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
66
|
+
});
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
await expect(() => {
|
|
69
|
+
const ret = model.call("Print hello world", {
|
|
70
|
+
signal: controller.signal,
|
|
71
|
+
});
|
|
72
|
+
controller.abort();
|
|
73
|
+
return ret;
|
|
74
|
+
}).rejects.toThrow();
|
|
75
|
+
}, 5000);
|
|
76
|
+
test("Test OpenAI with concurrency == 1", async () => {
|
|
77
|
+
const model = new OpenAI({
|
|
78
|
+
maxTokens: 5,
|
|
79
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
80
|
+
maxConcurrency: 1,
|
|
81
|
+
});
|
|
82
|
+
const res = await Promise.all([
|
|
83
|
+
model.call("Print hello world"),
|
|
84
|
+
model.call("Print hello world"),
|
|
85
|
+
]);
|
|
86
|
+
console.log({ res });
|
|
87
|
+
});
|
|
88
|
+
test("Test OpenAI with maxTokens -1", async () => {
|
|
89
|
+
const model = new OpenAI({
|
|
90
|
+
maxTokens: -1,
|
|
91
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
92
|
+
});
|
|
93
|
+
const res = await model.call("Print hello world", ["world"]);
|
|
94
|
+
console.log({ res });
|
|
95
|
+
});
|
|
96
|
+
test("Test OpenAI with chat model returns OpenAIChat", async () => {
|
|
97
|
+
const model = new OpenAI({ modelName: "gpt-3.5-turbo" });
|
|
98
|
+
expect(model).toBeInstanceOf(OpenAIChat);
|
|
99
|
+
const res = await model.call("Print hello world");
|
|
100
|
+
console.log({ res });
|
|
101
|
+
expect(typeof res).toBe("string");
|
|
102
|
+
});
|
|
103
|
+
test("Test OpenAI with instruct model returns OpenAI", async () => {
|
|
104
|
+
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
105
|
+
expect(model).toBeInstanceOf(OpenAI);
|
|
106
|
+
const res = await model.call("Print hello world");
|
|
107
|
+
console.log({ res });
|
|
108
|
+
expect(typeof res).toBe("string");
|
|
109
|
+
});
|
|
110
|
+
test("Test OpenAI with versioned instruct model returns OpenAI", async () => {
|
|
111
|
+
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct-0914" });
|
|
112
|
+
expect(model).toBeInstanceOf(OpenAI);
|
|
113
|
+
const res = await model.call("Print hello world");
|
|
114
|
+
console.log({ res });
|
|
115
|
+
expect(typeof res).toBe("string");
|
|
116
|
+
});
|
|
117
|
+
test("Test ChatOpenAI tokenUsage", async () => {
|
|
118
|
+
let tokenUsage = {
|
|
119
|
+
completionTokens: 0,
|
|
120
|
+
promptTokens: 0,
|
|
121
|
+
totalTokens: 0,
|
|
122
|
+
};
|
|
123
|
+
const model = new OpenAI({
|
|
124
|
+
maxTokens: 5,
|
|
125
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
126
|
+
callbackManager: CallbackManager.fromHandlers({
|
|
127
|
+
async handleLLMEnd(output) {
|
|
128
|
+
tokenUsage = output.llmOutput?.tokenUsage;
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
const res = await model.call("Hello");
|
|
133
|
+
console.log({ res });
|
|
134
|
+
expect(tokenUsage.promptTokens).toBe(1);
|
|
135
|
+
});
|
|
136
|
+
test("Test OpenAI in streaming mode", async () => {
|
|
137
|
+
let nrNewTokens = 0;
|
|
138
|
+
let streamedCompletion = "";
|
|
139
|
+
const model = new OpenAI({
|
|
140
|
+
maxTokens: 5,
|
|
141
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
142
|
+
streaming: true,
|
|
143
|
+
callbacks: CallbackManager.fromHandlers({
|
|
144
|
+
async handleLLMNewToken(token) {
|
|
145
|
+
nrNewTokens += 1;
|
|
146
|
+
streamedCompletion += token;
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
});
|
|
150
|
+
const res = await model.call("Print hello world");
|
|
151
|
+
console.log({ res });
|
|
152
|
+
expect(nrNewTokens > 0).toBe(true);
|
|
153
|
+
expect(res).toBe(streamedCompletion);
|
|
154
|
+
});
|
|
155
|
+
test("Test OpenAI in streaming mode with multiple prompts", async () => {
|
|
156
|
+
let nrNewTokens = 0;
|
|
157
|
+
const completions = [
|
|
158
|
+
["", ""],
|
|
159
|
+
["", ""],
|
|
160
|
+
];
|
|
161
|
+
const model = new OpenAI({
|
|
162
|
+
maxTokens: 5,
|
|
163
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
164
|
+
streaming: true,
|
|
165
|
+
n: 2,
|
|
166
|
+
callbacks: CallbackManager.fromHandlers({
|
|
167
|
+
async handleLLMNewToken(token, idx) {
|
|
168
|
+
nrNewTokens += 1;
|
|
169
|
+
completions[idx.prompt][idx.completion] += token;
|
|
170
|
+
},
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
const res = await model.generate(["Print hello world", "print hello sea"]);
|
|
174
|
+
console.log(res.generations, res.generations.map((g) => g[0].generationInfo));
|
|
175
|
+
expect(nrNewTokens > 0).toBe(true);
|
|
176
|
+
expect(res.generations.length).toBe(2);
|
|
177
|
+
expect(res.generations.map((g) => g.map((gg) => gg.text))).toEqual(completions);
|
|
178
|
+
});
|
|
179
|
+
test("Test OpenAIChat in streaming mode with multiple prompts", async () => {
|
|
180
|
+
let nrNewTokens = 0;
|
|
181
|
+
const completions = [[""], [""]];
|
|
182
|
+
const model = new OpenAI({
|
|
183
|
+
maxTokens: 5,
|
|
184
|
+
modelName: "gpt-3.5-turbo",
|
|
185
|
+
streaming: true,
|
|
186
|
+
n: 1,
|
|
187
|
+
callbacks: CallbackManager.fromHandlers({
|
|
188
|
+
async handleLLMNewToken(token, idx) {
|
|
189
|
+
nrNewTokens += 1;
|
|
190
|
+
completions[idx.prompt][idx.completion] += token;
|
|
191
|
+
},
|
|
192
|
+
}),
|
|
193
|
+
});
|
|
194
|
+
const res = await model.generate(["Print hello world", "print hello sea"]);
|
|
195
|
+
console.log(res.generations, res.generations.map((g) => g[0].generationInfo));
|
|
196
|
+
expect(nrNewTokens > 0).toBe(true);
|
|
197
|
+
expect(res.generations.length).toBe(2);
|
|
198
|
+
expect(res.generations.map((g) => g.map((gg) => gg.text))).toEqual(completions);
|
|
199
|
+
});
|
|
200
|
+
test("Test OpenAI prompt value", async () => {
|
|
201
|
+
const model = new OpenAI({
|
|
202
|
+
maxTokens: 5,
|
|
203
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
204
|
+
});
|
|
205
|
+
const res = await model.generatePrompt([
|
|
206
|
+
new StringPromptValue("Print hello world"),
|
|
207
|
+
]);
|
|
208
|
+
expect(res.generations.length).toBe(1);
|
|
209
|
+
for (const generation of res.generations) {
|
|
210
|
+
expect(generation.length).toBe(1);
|
|
211
|
+
for (const g of generation) {
|
|
212
|
+
console.log(g.text);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
console.log({ res });
|
|
216
|
+
});
|
|
217
|
+
test("Test OpenAI stream method", async () => {
|
|
218
|
+
const model = new OpenAI({
|
|
219
|
+
maxTokens: 50,
|
|
220
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
221
|
+
});
|
|
222
|
+
const stream = await model.stream("Print hello world.");
|
|
223
|
+
const chunks = [];
|
|
224
|
+
for await (const chunk of stream) {
|
|
225
|
+
chunks.push(chunk);
|
|
226
|
+
}
|
|
227
|
+
expect(chunks.length).toBeGreaterThan(1);
|
|
228
|
+
});
|
|
229
|
+
test("Test OpenAI stream method with abort", async () => {
|
|
230
|
+
await expect(async () => {
|
|
231
|
+
const model = new OpenAI({
|
|
232
|
+
maxTokens: 250,
|
|
233
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
234
|
+
});
|
|
235
|
+
const stream = await model.stream("How is your day going? Be extremely verbose.", {
|
|
236
|
+
signal: AbortSignal.timeout(1000),
|
|
237
|
+
});
|
|
238
|
+
for await (const chunk of stream) {
|
|
239
|
+
console.log(chunk);
|
|
240
|
+
}
|
|
241
|
+
}).rejects.toThrow();
|
|
242
|
+
});
|
|
243
|
+
test("Test OpenAI stream method with early break", async () => {
|
|
244
|
+
const model = new OpenAI({
|
|
245
|
+
maxTokens: 50,
|
|
246
|
+
modelName: "gpt-3.5-turbo-instruct",
|
|
247
|
+
});
|
|
248
|
+
const stream = await model.stream("How is your day going? Be extremely verbose.");
|
|
249
|
+
let i = 0;
|
|
250
|
+
for await (const chunk of stream) {
|
|
251
|
+
console.log(chunk);
|
|
252
|
+
i += 1;
|
|
253
|
+
if (i > 5) {
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/openai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "OpenAI integrations for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
|
|
26
26
|
"clean": "rimraf .turbo/ dist/ && NODE_OPTIONS=--max-old-space-size=4096 node scripts/create-entrypoints.js pre",
|
|
27
27
|
"prepack": "yarn build",
|
|
28
|
-
"release": "release-it --only-version --config .release-it.json",
|
|
29
28
|
"test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
|
|
30
29
|
"test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
31
30
|
"test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
31
|
+
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
|
|
32
32
|
"format": "prettier --write \"src\"",
|
|
33
33
|
"format:check": "prettier --check \"src\""
|
|
34
34
|
},
|
package/dist/utils/chunk.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.chunkArray = void 0;
|
|
4
|
-
const chunkArray = (arr, chunkSize) => arr.reduce((chunks, elem, index) => {
|
|
5
|
-
const chunkIndex = Math.floor(index / chunkSize);
|
|
6
|
-
const chunk = chunks[chunkIndex] || [];
|
|
7
|
-
// eslint-disable-next-line no-param-reassign
|
|
8
|
-
chunks[chunkIndex] = chunk.concat([elem]);
|
|
9
|
-
return chunks;
|
|
10
|
-
}, []);
|
|
11
|
-
exports.chunkArray = chunkArray;
|
package/dist/utils/chunk.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const chunkArray: <T>(arr: T[], chunkSize: number) => T[][];
|
package/dist/utils/chunk.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const chunkArray = (arr, chunkSize) => arr.reduce((chunks, elem, index) => {
|
|
2
|
-
const chunkIndex = Math.floor(index / chunkSize);
|
|
3
|
-
const chunk = chunks[chunkIndex] || [];
|
|
4
|
-
// eslint-disable-next-line no-param-reassign
|
|
5
|
-
chunks[chunkIndex] = chunk.concat([elem]);
|
|
6
|
-
return chunks;
|
|
7
|
-
}, []);
|