@inductiv/node-red-openai-api 0.4.0 → 0.5.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.
- package/README.md +4 -12
- package/lib.js +211 -102
- package/locales/de-DE/node.json +2 -1
- package/locales/en-US/node.json +2 -1
- package/locales/zh-CN/node.json +2 -1
- package/node.js +6 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,18 +9,10 @@
|
|
|
9
9
|
|
|
10
10
|
_@inductiv/node-red-openai-api_ offers a versatile and configurable Node-RED node, designed specifically for seamless integration with OpenAI's advanced platform services. It empowers you to effortlessly connect and orchestrate various OpenAI functionalities, leveraging the full power of Node-RED's sophisticated application nodes. Whether you're aiming to enhance your workflows with cutting-edge AI capabilities or create innovative applications, this node serves as your gateway to harnessing the latest in AI technology from OpenAI, all within the intuitive and flexible environment of Node-RED.
|
|
11
11
|
|
|
12
|
-
## New in Version 0.
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
- You no longer need to manually retrieve files in your flow using extra nodes (function, read file, etc.). The `upload file` function now accepts your desired file's absolute path as the `msg.payload.file` value.
|
|
17
|
-
- See the following updated examples (located in the `examples` directory) for more:
|
|
18
|
-
- Files
|
|
19
|
-
- Audio
|
|
20
|
-
- Images
|
|
21
|
-
- Assistants
|
|
22
|
-
- Reliability improvements.
|
|
23
|
-
- Now has full OpenAI Node.js package spec parity.
|
|
12
|
+
## New in Version 0.5.0
|
|
13
|
+
|
|
14
|
+
- Chat completion streaming responses are now returned in the `msg.payload` object, consistent with other
|
|
15
|
+
endpont response structures.
|
|
24
16
|
- Bug fixes.
|
|
25
17
|
|
|
26
18
|
## Key Features
|
package/lib.js
CHANGED
|
@@ -9,30 +9,43 @@ let OpenaiApi = (function () {
|
|
|
9
9
|
let node = parameters._node;
|
|
10
10
|
delete parameters._node;
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const clientParams = {
|
|
13
13
|
apiKey: parameters.apiKey,
|
|
14
14
|
baseURL: parameters.apiBase,
|
|
15
15
|
organization: parameters.organization,
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const openai = new OpenAI(clientParams);
|
|
17
19
|
const response = await openai.chat.completions.create({
|
|
18
20
|
...parameters.payload,
|
|
19
21
|
});
|
|
20
22
|
|
|
21
23
|
if (parameters.payload.stream) {
|
|
24
|
+
node.status({
|
|
25
|
+
fill: "green",
|
|
26
|
+
shape: "dot",
|
|
27
|
+
text: "OpenaiApi.status.streaming",
|
|
28
|
+
});
|
|
22
29
|
for await (const chunk of response) {
|
|
23
|
-
|
|
30
|
+
if (typeof chunk === "object") {
|
|
31
|
+
let payload = { payload: chunk };
|
|
32
|
+
node.send(payload);
|
|
33
|
+
}
|
|
24
34
|
}
|
|
25
|
-
|
|
35
|
+
node.status({});
|
|
26
36
|
} else {
|
|
27
37
|
return response;
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
async createImage(parameters) {
|
|
32
|
-
const
|
|
42
|
+
const clientParams = {
|
|
33
43
|
apiKey: parameters.apiKey,
|
|
44
|
+
baseURL: parameters.apiBase,
|
|
34
45
|
organization: parameters.organization,
|
|
35
|
-
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const openai = new OpenAI(clientParams);
|
|
36
49
|
const response = await openai.images.generate({
|
|
37
50
|
...parameters.payload,
|
|
38
51
|
});
|
|
@@ -41,10 +54,12 @@ let OpenaiApi = (function () {
|
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
async createImageEdit(parameters) {
|
|
44
|
-
const
|
|
57
|
+
const clientParams = {
|
|
45
58
|
apiKey: parameters.apiKey,
|
|
59
|
+
baseURL: parameters.apiBase,
|
|
46
60
|
organization: parameters.organization,
|
|
47
|
-
}
|
|
61
|
+
};
|
|
62
|
+
const openai = new OpenAI(clientParams);
|
|
48
63
|
|
|
49
64
|
parameters.payload.image = fs.createReadStream(parameters.payload.image);
|
|
50
65
|
if (parameters.payload.mask) {
|
|
@@ -59,10 +74,12 @@ let OpenaiApi = (function () {
|
|
|
59
74
|
}
|
|
60
75
|
|
|
61
76
|
async createImageVariation(parameters) {
|
|
62
|
-
const
|
|
77
|
+
const clientParams = {
|
|
63
78
|
apiKey: parameters.apiKey,
|
|
79
|
+
baseURL: parameters.apiBase,
|
|
64
80
|
organization: parameters.organization,
|
|
65
|
-
}
|
|
81
|
+
};
|
|
82
|
+
const openai = new OpenAI(clientParams);
|
|
66
83
|
|
|
67
84
|
parameters.payload.image = fs.createReadStream(parameters.payload.image);
|
|
68
85
|
const response = await openai.images.createVariation({
|
|
@@ -73,10 +90,12 @@ let OpenaiApi = (function () {
|
|
|
73
90
|
}
|
|
74
91
|
|
|
75
92
|
async createEmbedding(parameters) {
|
|
76
|
-
const
|
|
93
|
+
const clientParams = {
|
|
77
94
|
apiKey: parameters.apiKey,
|
|
95
|
+
baseURL: parameters.apiBase,
|
|
78
96
|
organization: parameters.organization,
|
|
79
|
-
}
|
|
97
|
+
};
|
|
98
|
+
const openai = new OpenAI(clientParams);
|
|
80
99
|
|
|
81
100
|
const response = await openai.embeddings.create({
|
|
82
101
|
...parameters.payload,
|
|
@@ -86,10 +105,12 @@ let OpenaiApi = (function () {
|
|
|
86
105
|
}
|
|
87
106
|
|
|
88
107
|
async createSpeech(parameters) {
|
|
89
|
-
const
|
|
108
|
+
const clientParams = {
|
|
90
109
|
apiKey: parameters.apiKey,
|
|
110
|
+
baseURL: parameters.apiBase,
|
|
91
111
|
organization: parameters.organization,
|
|
92
|
-
}
|
|
112
|
+
};
|
|
113
|
+
const openai = new OpenAI(clientParams);
|
|
93
114
|
|
|
94
115
|
const audio = await openai.audio.speech.create({ ...parameters.payload });
|
|
95
116
|
const response = Buffer.from(await audio.arrayBuffer());
|
|
@@ -98,10 +119,12 @@ let OpenaiApi = (function () {
|
|
|
98
119
|
}
|
|
99
120
|
|
|
100
121
|
async createTranscription(parameters) {
|
|
101
|
-
const
|
|
122
|
+
const clientParams = {
|
|
102
123
|
apiKey: parameters.apiKey,
|
|
124
|
+
baseURL: parameters.apiBase,
|
|
103
125
|
organization: parameters.organization,
|
|
104
|
-
}
|
|
126
|
+
};
|
|
127
|
+
const openai = new OpenAI(clientParams);
|
|
105
128
|
|
|
106
129
|
parameters.payload.file = fs.createReadStream(parameters.payload.file);
|
|
107
130
|
|
|
@@ -113,10 +136,12 @@ let OpenaiApi = (function () {
|
|
|
113
136
|
}
|
|
114
137
|
|
|
115
138
|
async createTranslation(parameters) {
|
|
116
|
-
const
|
|
139
|
+
const clientParams = {
|
|
117
140
|
apiKey: parameters.apiKey,
|
|
141
|
+
baseURL: parameters.apiBase,
|
|
118
142
|
organization: parameters.organization,
|
|
119
|
-
}
|
|
143
|
+
};
|
|
144
|
+
const openai = new OpenAI(clientParams);
|
|
120
145
|
|
|
121
146
|
parameters.payload.file = fs.createReadStream(parameters.payload.file);
|
|
122
147
|
const response = await openai.audio.translations.create({
|
|
@@ -127,10 +152,12 @@ let OpenaiApi = (function () {
|
|
|
127
152
|
}
|
|
128
153
|
|
|
129
154
|
async listFiles(parameters) {
|
|
130
|
-
const
|
|
155
|
+
const clientParams = {
|
|
131
156
|
apiKey: parameters.apiKey,
|
|
157
|
+
baseURL: parameters.apiBase,
|
|
132
158
|
organization: parameters.organization,
|
|
133
|
-
}
|
|
159
|
+
};
|
|
160
|
+
const openai = new OpenAI(clientParams);
|
|
134
161
|
|
|
135
162
|
const list = await openai.files.list({
|
|
136
163
|
...parameters.payload,
|
|
@@ -145,10 +172,12 @@ let OpenaiApi = (function () {
|
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
async createFile(parameters) {
|
|
148
|
-
const
|
|
175
|
+
const clientParams = {
|
|
149
176
|
apiKey: parameters.apiKey,
|
|
177
|
+
baseURL: parameters.apiBase,
|
|
150
178
|
organization: parameters.organization,
|
|
151
|
-
}
|
|
179
|
+
};
|
|
180
|
+
const openai = new OpenAI(clientParams);
|
|
152
181
|
|
|
153
182
|
parameters.payload.file = fs.createReadStream(parameters.payload.file);
|
|
154
183
|
const response = await openai.files.create({
|
|
@@ -158,10 +187,12 @@ let OpenaiApi = (function () {
|
|
|
158
187
|
return response;
|
|
159
188
|
}
|
|
160
189
|
async deleteFile(parameters) {
|
|
161
|
-
const
|
|
190
|
+
const clientParams = {
|
|
162
191
|
apiKey: parameters.apiKey,
|
|
192
|
+
baseURL: parameters.apiBase,
|
|
163
193
|
organization: parameters.organization,
|
|
164
|
-
}
|
|
194
|
+
};
|
|
195
|
+
const openai = new OpenAI(clientParams);
|
|
165
196
|
|
|
166
197
|
const response = await openai.files.del({
|
|
167
198
|
...parameters.payload,
|
|
@@ -170,10 +201,12 @@ let OpenaiApi = (function () {
|
|
|
170
201
|
return response;
|
|
171
202
|
}
|
|
172
203
|
async retrieveFile(parameters) {
|
|
173
|
-
const
|
|
204
|
+
const clientParams = {
|
|
174
205
|
apiKey: parameters.apiKey,
|
|
206
|
+
baseURL: parameters.apiBase,
|
|
175
207
|
organization: parameters.organization,
|
|
176
|
-
}
|
|
208
|
+
};
|
|
209
|
+
const openai = new OpenAI(clientParams);
|
|
177
210
|
|
|
178
211
|
const file_id = parameters.payload.file_id;
|
|
179
212
|
delete parameters.payload.file_id;
|
|
@@ -185,10 +218,12 @@ let OpenaiApi = (function () {
|
|
|
185
218
|
return response;
|
|
186
219
|
}
|
|
187
220
|
async downloadFile(parameters) {
|
|
188
|
-
const
|
|
221
|
+
const clientParams = {
|
|
189
222
|
apiKey: parameters.apiKey,
|
|
223
|
+
baseURL: parameters.apiBase,
|
|
190
224
|
organization: parameters.organization,
|
|
191
|
-
}
|
|
225
|
+
};
|
|
226
|
+
const openai = new OpenAI(clientParams);
|
|
192
227
|
|
|
193
228
|
const file_id = parameters.payload.file_id;
|
|
194
229
|
delete parameters.payload.file_id;
|
|
@@ -200,10 +235,12 @@ let OpenaiApi = (function () {
|
|
|
200
235
|
return response;
|
|
201
236
|
}
|
|
202
237
|
async createFineTuningJob(parameters) {
|
|
203
|
-
const
|
|
238
|
+
const clientParams = {
|
|
204
239
|
apiKey: parameters.apiKey,
|
|
240
|
+
baseURL: parameters.apiBase,
|
|
205
241
|
organization: parameters.organization,
|
|
206
|
-
}
|
|
242
|
+
};
|
|
243
|
+
const openai = new OpenAI(clientParams);
|
|
207
244
|
|
|
208
245
|
const response = await openai.fineTuning.jobs.create({
|
|
209
246
|
...parameters.payload,
|
|
@@ -212,10 +249,12 @@ let OpenaiApi = (function () {
|
|
|
212
249
|
return response;
|
|
213
250
|
}
|
|
214
251
|
async listPaginatedFineTuningJobs(parameters) {
|
|
215
|
-
const
|
|
252
|
+
const clientParams = {
|
|
216
253
|
apiKey: parameters.apiKey,
|
|
254
|
+
baseURL: parameters.apiBase,
|
|
217
255
|
organization: parameters.organization,
|
|
218
|
-
}
|
|
256
|
+
};
|
|
257
|
+
const openai = new OpenAI(clientParams);
|
|
219
258
|
|
|
220
259
|
const list = await openai.fineTuning.jobs.list({
|
|
221
260
|
...parameters.payload,
|
|
@@ -229,10 +268,12 @@ let OpenaiApi = (function () {
|
|
|
229
268
|
return response;
|
|
230
269
|
}
|
|
231
270
|
async retrieveFineTuningJob(parameters) {
|
|
232
|
-
const
|
|
271
|
+
const clientParams = {
|
|
233
272
|
apiKey: parameters.apiKey,
|
|
273
|
+
baseURL: parameters.apiBase,
|
|
234
274
|
organization: parameters.organization,
|
|
235
|
-
}
|
|
275
|
+
};
|
|
276
|
+
const openai = new OpenAI(clientParams);
|
|
236
277
|
|
|
237
278
|
const response = await openai.fineTuning.jobs.retrieve(
|
|
238
279
|
parameters.payload.fine_tuning_job_id,
|
|
@@ -241,10 +282,12 @@ let OpenaiApi = (function () {
|
|
|
241
282
|
return response;
|
|
242
283
|
}
|
|
243
284
|
async listFineTuningEvents(parameters) {
|
|
244
|
-
const
|
|
285
|
+
const clientParams = {
|
|
245
286
|
apiKey: parameters.apiKey,
|
|
287
|
+
baseURL: parameters.apiBase,
|
|
246
288
|
organization: parameters.organization,
|
|
247
|
-
}
|
|
289
|
+
};
|
|
290
|
+
const openai = new OpenAI(clientParams);
|
|
248
291
|
|
|
249
292
|
let response = [];
|
|
250
293
|
const list = await openai.fineTuning.jobs.listEvents(
|
|
@@ -256,10 +299,12 @@ let OpenaiApi = (function () {
|
|
|
256
299
|
return response;
|
|
257
300
|
}
|
|
258
301
|
async cancelFineTuningJob(parameters) {
|
|
259
|
-
const
|
|
302
|
+
const clientParams = {
|
|
260
303
|
apiKey: parameters.apiKey,
|
|
304
|
+
baseURL: parameters.apiBase,
|
|
261
305
|
organization: parameters.organization,
|
|
262
|
-
}
|
|
306
|
+
};
|
|
307
|
+
const openai = new OpenAI(clientParams);
|
|
263
308
|
|
|
264
309
|
const response = await openai.fineTuning.jobs.cancel(
|
|
265
310
|
parameters.payload.fine_tuning_job_id,
|
|
@@ -268,20 +313,24 @@ let OpenaiApi = (function () {
|
|
|
268
313
|
return response;
|
|
269
314
|
}
|
|
270
315
|
async listModels(parameters) {
|
|
271
|
-
const
|
|
316
|
+
const clientParams = {
|
|
272
317
|
apiKey: parameters.apiKey,
|
|
318
|
+
baseURL: parameters.apiBase,
|
|
273
319
|
organization: parameters.organization,
|
|
274
|
-
}
|
|
320
|
+
};
|
|
321
|
+
const openai = new OpenAI(clientParams);
|
|
275
322
|
|
|
276
323
|
const response = await openai.models.list();
|
|
277
324
|
|
|
278
325
|
return response.body;
|
|
279
326
|
}
|
|
280
327
|
async retrieveModel(parameters) {
|
|
281
|
-
const
|
|
328
|
+
const clientParams = {
|
|
282
329
|
apiKey: parameters.apiKey,
|
|
330
|
+
baseURL: parameters.apiBase,
|
|
283
331
|
organization: parameters.organization,
|
|
284
|
-
}
|
|
332
|
+
};
|
|
333
|
+
const openai = new OpenAI(clientParams);
|
|
285
334
|
|
|
286
335
|
const model = parameters.payload.model;
|
|
287
336
|
const response = await openai.models.retrieve(model);
|
|
@@ -289,10 +338,12 @@ let OpenaiApi = (function () {
|
|
|
289
338
|
return response;
|
|
290
339
|
}
|
|
291
340
|
async deleteModel(parameters) {
|
|
292
|
-
const
|
|
341
|
+
const clientParams = {
|
|
293
342
|
apiKey: parameters.apiKey,
|
|
343
|
+
baseURL: parameters.apiBase,
|
|
294
344
|
organization: parameters.organization,
|
|
295
|
-
}
|
|
345
|
+
};
|
|
346
|
+
const openai = new OpenAI(clientParams);
|
|
296
347
|
|
|
297
348
|
const model = parameters.payload.model;
|
|
298
349
|
const response = await openai.models.del(model);
|
|
@@ -300,19 +351,23 @@ let OpenaiApi = (function () {
|
|
|
300
351
|
return response;
|
|
301
352
|
}
|
|
302
353
|
async createModeration(parameters) {
|
|
303
|
-
const
|
|
354
|
+
const clientParams = {
|
|
304
355
|
apiKey: parameters.apiKey,
|
|
356
|
+
baseURL: parameters.apiBase,
|
|
305
357
|
organization: parameters.organization,
|
|
306
|
-
}
|
|
358
|
+
};
|
|
359
|
+
const openai = new OpenAI(clientParams);
|
|
307
360
|
|
|
308
361
|
const response = await openai.moderations.create(parameters.payload);
|
|
309
362
|
return response;
|
|
310
363
|
}
|
|
311
364
|
async listAssistants(parameters) {
|
|
312
|
-
const
|
|
365
|
+
const clientParams = {
|
|
313
366
|
apiKey: parameters.apiKey,
|
|
367
|
+
baseURL: parameters.apiBase,
|
|
314
368
|
organization: parameters.organization,
|
|
315
|
-
}
|
|
369
|
+
};
|
|
370
|
+
const openai = new OpenAI(clientParams);
|
|
316
371
|
|
|
317
372
|
const response = await openai.beta.assistants.list({
|
|
318
373
|
...parameters.payload,
|
|
@@ -321,10 +376,12 @@ let OpenaiApi = (function () {
|
|
|
321
376
|
return response.body;
|
|
322
377
|
}
|
|
323
378
|
async createAssistant(parameters) {
|
|
324
|
-
const
|
|
379
|
+
const clientParams = {
|
|
325
380
|
apiKey: parameters.apiKey,
|
|
381
|
+
baseURL: parameters.apiBase,
|
|
326
382
|
organization: parameters.organization,
|
|
327
|
-
}
|
|
383
|
+
};
|
|
384
|
+
const openai = new OpenAI(clientParams);
|
|
328
385
|
|
|
329
386
|
const response = await openai.beta.assistants.create({
|
|
330
387
|
...parameters.payload,
|
|
@@ -333,10 +390,12 @@ let OpenaiApi = (function () {
|
|
|
333
390
|
return response;
|
|
334
391
|
}
|
|
335
392
|
async getAssistant(parameters) {
|
|
336
|
-
const
|
|
393
|
+
const clientParams = {
|
|
337
394
|
apiKey: parameters.apiKey,
|
|
395
|
+
baseURL: parameters.apiBase,
|
|
338
396
|
organization: parameters.organization,
|
|
339
|
-
}
|
|
397
|
+
};
|
|
398
|
+
const openai = new OpenAI(clientParams);
|
|
340
399
|
|
|
341
400
|
const id = parameters.payload.assistant_id;
|
|
342
401
|
const response = await openai.beta.assistants.retrieve(id);
|
|
@@ -344,10 +403,12 @@ let OpenaiApi = (function () {
|
|
|
344
403
|
return response;
|
|
345
404
|
}
|
|
346
405
|
async modifyAssistant(parameters) {
|
|
347
|
-
const
|
|
406
|
+
const clientParams = {
|
|
348
407
|
apiKey: parameters.apiKey,
|
|
408
|
+
baseURL: parameters.apiBase,
|
|
349
409
|
organization: parameters.organization,
|
|
350
|
-
}
|
|
410
|
+
};
|
|
411
|
+
const openai = new OpenAI(clientParams);
|
|
351
412
|
|
|
352
413
|
const id = parameters.payload.assistant_id;
|
|
353
414
|
delete parameters.payload.assistant_id;
|
|
@@ -359,10 +420,12 @@ let OpenaiApi = (function () {
|
|
|
359
420
|
return response;
|
|
360
421
|
}
|
|
361
422
|
async deleteAssistant(parameters) {
|
|
362
|
-
const
|
|
423
|
+
const clientParams = {
|
|
363
424
|
apiKey: parameters.apiKey,
|
|
425
|
+
baseURL: parameters.apiBase,
|
|
364
426
|
organization: parameters.organization,
|
|
365
|
-
}
|
|
427
|
+
};
|
|
428
|
+
const openai = new OpenAI(clientParams);
|
|
366
429
|
|
|
367
430
|
const id = parameters.payload.assistant_id;
|
|
368
431
|
const response = await openai.beta.assistants.del(id);
|
|
@@ -370,10 +433,12 @@ let OpenaiApi = (function () {
|
|
|
370
433
|
return response;
|
|
371
434
|
}
|
|
372
435
|
async createThread(parameters) {
|
|
373
|
-
const
|
|
436
|
+
const clientParams = {
|
|
374
437
|
apiKey: parameters.apiKey,
|
|
438
|
+
baseURL: parameters.apiBase,
|
|
375
439
|
organization: parameters.organization,
|
|
376
|
-
}
|
|
440
|
+
};
|
|
441
|
+
const openai = new OpenAI(clientParams);
|
|
377
442
|
|
|
378
443
|
const response = await openai.beta.threads.create({
|
|
379
444
|
...parameters.payload,
|
|
@@ -382,10 +447,12 @@ let OpenaiApi = (function () {
|
|
|
382
447
|
return response;
|
|
383
448
|
}
|
|
384
449
|
async getThread(parameters) {
|
|
385
|
-
const
|
|
450
|
+
const clientParams = {
|
|
386
451
|
apiKey: parameters.apiKey,
|
|
452
|
+
baseURL: parameters.apiBase,
|
|
387
453
|
organization: parameters.organization,
|
|
388
|
-
}
|
|
454
|
+
};
|
|
455
|
+
const openai = new OpenAI(clientParams);
|
|
389
456
|
|
|
390
457
|
const id = parameters.payload.thread_id;
|
|
391
458
|
const response = await openai.beta.threads.retrieve(id);
|
|
@@ -393,10 +460,12 @@ let OpenaiApi = (function () {
|
|
|
393
460
|
return response;
|
|
394
461
|
}
|
|
395
462
|
async modifyThread(parameters) {
|
|
396
|
-
const
|
|
463
|
+
const clientParams = {
|
|
397
464
|
apiKey: parameters.apiKey,
|
|
465
|
+
baseURL: parameters.apiBase,
|
|
398
466
|
organization: parameters.organization,
|
|
399
|
-
}
|
|
467
|
+
};
|
|
468
|
+
const openai = new OpenAI(clientParams);
|
|
400
469
|
|
|
401
470
|
const id = parameters.payload.thread_id;
|
|
402
471
|
delete parameters.payload.thread_id;
|
|
@@ -408,10 +477,12 @@ let OpenaiApi = (function () {
|
|
|
408
477
|
return response;
|
|
409
478
|
}
|
|
410
479
|
async deleteThread(parameters) {
|
|
411
|
-
const
|
|
480
|
+
const clientParams = {
|
|
412
481
|
apiKey: parameters.apiKey,
|
|
482
|
+
baseURL: parameters.apiBase,
|
|
413
483
|
organization: parameters.organization,
|
|
414
|
-
}
|
|
484
|
+
};
|
|
485
|
+
const openai = new OpenAI(clientParams);
|
|
415
486
|
|
|
416
487
|
const id = parameters.payload.thread_id;
|
|
417
488
|
const response = await openai.beta.threads.del(id);
|
|
@@ -419,10 +490,12 @@ let OpenaiApi = (function () {
|
|
|
419
490
|
return response;
|
|
420
491
|
}
|
|
421
492
|
async listMessages(parameters) {
|
|
422
|
-
const
|
|
493
|
+
const clientParams = {
|
|
423
494
|
apiKey: parameters.apiKey,
|
|
495
|
+
baseURL: parameters.apiBase,
|
|
424
496
|
organization: parameters.organization,
|
|
425
|
-
}
|
|
497
|
+
};
|
|
498
|
+
const openai = new OpenAI(clientParams);
|
|
426
499
|
|
|
427
500
|
const id = parameters.payload.thread_id;
|
|
428
501
|
const response = await openai.beta.threads.messages.list(id);
|
|
@@ -430,10 +503,12 @@ let OpenaiApi = (function () {
|
|
|
430
503
|
return response.body;
|
|
431
504
|
}
|
|
432
505
|
async createMessage(parameters) {
|
|
433
|
-
const
|
|
506
|
+
const clientParams = {
|
|
434
507
|
apiKey: parameters.apiKey,
|
|
508
|
+
baseURL: parameters.apiBase,
|
|
435
509
|
organization: parameters.organization,
|
|
436
|
-
}
|
|
510
|
+
};
|
|
511
|
+
const openai = new OpenAI(clientParams);
|
|
437
512
|
|
|
438
513
|
const thread_id = parameters.payload.thread_id;
|
|
439
514
|
delete parameters.payload.thread_id;
|
|
@@ -445,10 +520,12 @@ let OpenaiApi = (function () {
|
|
|
445
520
|
return response;
|
|
446
521
|
}
|
|
447
522
|
async getMessage(parameters) {
|
|
448
|
-
const
|
|
523
|
+
const clientParams = {
|
|
449
524
|
apiKey: parameters.apiKey,
|
|
525
|
+
baseURL: parameters.apiBase,
|
|
450
526
|
organization: parameters.organization,
|
|
451
|
-
}
|
|
527
|
+
};
|
|
528
|
+
const openai = new OpenAI(clientParams);
|
|
452
529
|
|
|
453
530
|
const thread_id = parameters.payload.thread_id;
|
|
454
531
|
const message_id = parameters.payload.message_id;
|
|
@@ -461,10 +538,12 @@ let OpenaiApi = (function () {
|
|
|
461
538
|
return response;
|
|
462
539
|
}
|
|
463
540
|
async modifyMessage(parameters) {
|
|
464
|
-
const
|
|
541
|
+
const clientParams = {
|
|
465
542
|
apiKey: parameters.apiKey,
|
|
543
|
+
baseURL: parameters.apiBase,
|
|
466
544
|
organization: parameters.organization,
|
|
467
|
-
}
|
|
545
|
+
};
|
|
546
|
+
const openai = new OpenAI(clientParams);
|
|
468
547
|
|
|
469
548
|
const thread_id = parameters.payload.thread_id;
|
|
470
549
|
const message_id = parameters.payload.message_id;
|
|
@@ -482,10 +561,12 @@ let OpenaiApi = (function () {
|
|
|
482
561
|
return response;
|
|
483
562
|
}
|
|
484
563
|
async createThreadAndRun(parameters) {
|
|
485
|
-
const
|
|
564
|
+
const clientParams = {
|
|
486
565
|
apiKey: parameters.apiKey,
|
|
566
|
+
baseURL: parameters.apiBase,
|
|
487
567
|
organization: parameters.organization,
|
|
488
|
-
}
|
|
568
|
+
};
|
|
569
|
+
const openai = new OpenAI(clientParams);
|
|
489
570
|
|
|
490
571
|
const response = await openai.beta.threads.createAndRun({
|
|
491
572
|
...parameters.payload,
|
|
@@ -494,10 +575,12 @@ let OpenaiApi = (function () {
|
|
|
494
575
|
return response;
|
|
495
576
|
}
|
|
496
577
|
async listRuns(parameters) {
|
|
497
|
-
const
|
|
578
|
+
const clientParams = {
|
|
498
579
|
apiKey: parameters.apiKey,
|
|
580
|
+
baseURL: parameters.apiBase,
|
|
499
581
|
organization: parameters.organization,
|
|
500
|
-
}
|
|
582
|
+
};
|
|
583
|
+
const openai = new OpenAI(clientParams);
|
|
501
584
|
|
|
502
585
|
const thred_id = parameters.payload.thread_id;
|
|
503
586
|
delete parameters.payload.thread_id;
|
|
@@ -509,10 +592,12 @@ let OpenaiApi = (function () {
|
|
|
509
592
|
return response.body;
|
|
510
593
|
}
|
|
511
594
|
async createRun(parameters) {
|
|
512
|
-
const
|
|
595
|
+
const clientParams = {
|
|
513
596
|
apiKey: parameters.apiKey,
|
|
597
|
+
baseURL: parameters.apiBase,
|
|
514
598
|
organization: parameters.organization,
|
|
515
|
-
}
|
|
599
|
+
};
|
|
600
|
+
const openai = new OpenAI(clientParams);
|
|
516
601
|
|
|
517
602
|
const thread_id = parameters.payload.thread_id;
|
|
518
603
|
delete parameters.payload.thread_id;
|
|
@@ -524,10 +609,12 @@ let OpenaiApi = (function () {
|
|
|
524
609
|
return response;
|
|
525
610
|
}
|
|
526
611
|
async getRun(parameters) {
|
|
527
|
-
const
|
|
612
|
+
const clientParams = {
|
|
528
613
|
apiKey: parameters.apiKey,
|
|
614
|
+
baseURL: parameters.apiBase,
|
|
529
615
|
organization: parameters.organization,
|
|
530
|
-
}
|
|
616
|
+
};
|
|
617
|
+
const openai = new OpenAI(clientParams);
|
|
531
618
|
|
|
532
619
|
const thread_id = parameters.payload.thread_id;
|
|
533
620
|
const run_id = parameters.payload.run_id;
|
|
@@ -542,10 +629,12 @@ let OpenaiApi = (function () {
|
|
|
542
629
|
return response;
|
|
543
630
|
}
|
|
544
631
|
async modifyRun(parameters) {
|
|
545
|
-
const
|
|
632
|
+
const clientParams = {
|
|
546
633
|
apiKey: parameters.apiKey,
|
|
634
|
+
baseURL: parameters.apiBase,
|
|
547
635
|
organization: parameters.organization,
|
|
548
|
-
}
|
|
636
|
+
};
|
|
637
|
+
const openai = new OpenAI(clientParams);
|
|
549
638
|
|
|
550
639
|
const thread_id = parameters.payload.thread_id;
|
|
551
640
|
const run_id = parameters.payload.run_id;
|
|
@@ -563,10 +652,12 @@ let OpenaiApi = (function () {
|
|
|
563
652
|
return response;
|
|
564
653
|
}
|
|
565
654
|
async submitToolOuputsToRun(parameters) {
|
|
566
|
-
const
|
|
655
|
+
const clientParams = {
|
|
567
656
|
apiKey: parameters.apiKey,
|
|
657
|
+
baseURL: parameters.apiBase,
|
|
568
658
|
organization: parameters.organization,
|
|
569
|
-
}
|
|
659
|
+
};
|
|
660
|
+
const openai = new OpenAI(clientParams);
|
|
570
661
|
|
|
571
662
|
const thread_id = parameters.payload.thread_id;
|
|
572
663
|
const run_id = parameters.payload.run_id;
|
|
@@ -584,10 +675,12 @@ let OpenaiApi = (function () {
|
|
|
584
675
|
return response;
|
|
585
676
|
}
|
|
586
677
|
async cancelRun(parameters) {
|
|
587
|
-
const
|
|
678
|
+
const clientParams = {
|
|
588
679
|
apiKey: parameters.apiKey,
|
|
680
|
+
baseURL: parameters.apiBase,
|
|
589
681
|
organization: parameters.organization,
|
|
590
|
-
}
|
|
682
|
+
};
|
|
683
|
+
const openai = new OpenAI(clientParams);
|
|
591
684
|
|
|
592
685
|
const thread_id = parameters.payload.thread_id;
|
|
593
686
|
const run_id = parameters.payload.run_id;
|
|
@@ -605,10 +698,12 @@ let OpenaiApi = (function () {
|
|
|
605
698
|
return response;
|
|
606
699
|
}
|
|
607
700
|
async listRunSteps(parameters) {
|
|
608
|
-
const
|
|
701
|
+
const clientParams = {
|
|
609
702
|
apiKey: parameters.apiKey,
|
|
703
|
+
baseURL: parameters.apiBase,
|
|
610
704
|
organization: parameters.organization,
|
|
611
|
-
}
|
|
705
|
+
};
|
|
706
|
+
const openai = new OpenAI(clientParams);
|
|
612
707
|
|
|
613
708
|
const thread_id = parameters.payload.thread_id;
|
|
614
709
|
const run_id = parameters.payload.run_id;
|
|
@@ -626,10 +721,12 @@ let OpenaiApi = (function () {
|
|
|
626
721
|
return response.body;
|
|
627
722
|
}
|
|
628
723
|
async getRunStep(parameters) {
|
|
629
|
-
const
|
|
724
|
+
const clientParams = {
|
|
630
725
|
apiKey: parameters.apiKey,
|
|
726
|
+
baseURL: parameters.apiBase,
|
|
631
727
|
organization: parameters.organization,
|
|
632
|
-
}
|
|
728
|
+
};
|
|
729
|
+
const openai = new OpenAI(clientParams);
|
|
633
730
|
|
|
634
731
|
const thread_id = parameters.payload.thread_id;
|
|
635
732
|
const run_id = parameters.payload.run_id;
|
|
@@ -644,10 +741,12 @@ let OpenaiApi = (function () {
|
|
|
644
741
|
return response;
|
|
645
742
|
}
|
|
646
743
|
async listAssistantFiles(parameters) {
|
|
647
|
-
const
|
|
744
|
+
const clientParams = {
|
|
648
745
|
apiKey: parameters.apiKey,
|
|
746
|
+
baseURL: parameters.apiBase,
|
|
649
747
|
organization: parameters.organization,
|
|
650
|
-
}
|
|
748
|
+
};
|
|
749
|
+
const openai = new OpenAI(clientParams);
|
|
651
750
|
|
|
652
751
|
const assistant_id = parameters.payload.assistant_id;
|
|
653
752
|
delete parameters.payload.assistant_id;
|
|
@@ -659,10 +758,12 @@ let OpenaiApi = (function () {
|
|
|
659
758
|
return response.body;
|
|
660
759
|
}
|
|
661
760
|
async createAssistantFile(parameters) {
|
|
662
|
-
const
|
|
761
|
+
const clientParams = {
|
|
663
762
|
apiKey: parameters.apiKey,
|
|
763
|
+
baseURL: parameters.apiBase,
|
|
664
764
|
organization: parameters.organization,
|
|
665
|
-
}
|
|
765
|
+
};
|
|
766
|
+
const openai = new OpenAI(clientParams);
|
|
666
767
|
|
|
667
768
|
const assistant_id = parameters.payload.assistant_id;
|
|
668
769
|
delete parameters.payload.assistant_id;
|
|
@@ -674,10 +775,12 @@ let OpenaiApi = (function () {
|
|
|
674
775
|
return response;
|
|
675
776
|
}
|
|
676
777
|
async getAssistantFile(parameters) {
|
|
677
|
-
const
|
|
778
|
+
const clientParams = {
|
|
678
779
|
apiKey: parameters.apiKey,
|
|
780
|
+
baseURL: parameters.apiBase,
|
|
679
781
|
organization: parameters.organization,
|
|
680
|
-
}
|
|
782
|
+
};
|
|
783
|
+
const openai = new OpenAI(clientParams);
|
|
681
784
|
|
|
682
785
|
const assistant_id = parameters.payload.assistant_id;
|
|
683
786
|
const file_id = parameters.payload.file_id;
|
|
@@ -695,10 +798,12 @@ let OpenaiApi = (function () {
|
|
|
695
798
|
return response;
|
|
696
799
|
}
|
|
697
800
|
async deleteAssistantFile(parameters) {
|
|
698
|
-
const
|
|
801
|
+
const clientParams = {
|
|
699
802
|
apiKey: parameters.apiKey,
|
|
803
|
+
baseURL: parameters.apiBase,
|
|
700
804
|
organization: parameters.organization,
|
|
701
|
-
}
|
|
805
|
+
};
|
|
806
|
+
const openai = new OpenAI(clientParams);
|
|
702
807
|
|
|
703
808
|
const assistant_id = parameters.payload.assistant_id;
|
|
704
809
|
const file_id = parameters.payload.file_id;
|
|
@@ -716,10 +821,12 @@ let OpenaiApi = (function () {
|
|
|
716
821
|
return response;
|
|
717
822
|
}
|
|
718
823
|
async listMessageFiles(parameters) {
|
|
719
|
-
const
|
|
824
|
+
const clientParams = {
|
|
720
825
|
apiKey: parameters.apiKey,
|
|
826
|
+
baseURL: parameters.apiBase,
|
|
721
827
|
organization: parameters.organization,
|
|
722
|
-
}
|
|
828
|
+
};
|
|
829
|
+
const openai = new OpenAI(clientParams);
|
|
723
830
|
|
|
724
831
|
const thread_id = parameters.payload.thread_id;
|
|
725
832
|
const message_id = parameters.payload.message_id;
|
|
@@ -737,10 +844,12 @@ let OpenaiApi = (function () {
|
|
|
737
844
|
return response;
|
|
738
845
|
}
|
|
739
846
|
async getMessageFile(parameters) {
|
|
740
|
-
const
|
|
847
|
+
const clientParams = {
|
|
741
848
|
apiKey: parameters.apiKey,
|
|
849
|
+
baseURL: parameters.apiBase,
|
|
742
850
|
organization: parameters.organization,
|
|
743
|
-
}
|
|
851
|
+
};
|
|
852
|
+
const openai = new OpenAI(clientParams);
|
|
744
853
|
|
|
745
854
|
const thread_id = parameters.payload.thread_id;
|
|
746
855
|
const message_id = parameters.payload.message_id;
|
package/locales/de-DE/node.json
CHANGED
package/locales/en-US/node.json
CHANGED
package/locales/zh-CN/node.json
CHANGED
package/node.js
CHANGED
|
@@ -33,10 +33,12 @@ module.exports = function (RED) {
|
|
|
33
33
|
|
|
34
34
|
client[functionName](serviceParametersObject)
|
|
35
35
|
.then((payload) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
if (payload !== undefined) {
|
|
37
|
+
// Update `msg.payload` with the payload from the API response, then send resonse to client.
|
|
38
|
+
msg.payload = payload;
|
|
39
|
+
node.send(msg);
|
|
40
|
+
node.status({});
|
|
41
|
+
}
|
|
40
42
|
})
|
|
41
43
|
.catch(function (error) {
|
|
42
44
|
node.status({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inductiv/node-red-openai-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Go beyond ChatGPT and DALL·E 3: this Node-RED node seamlessly integrates a range of OpenAI services, including Assistants, Threads, Vision, and Audio, enabling feature-rich enhancement of your AI workflows with any OpenAI REST API-compatible solution.",
|
|
5
5
|
"main": "node.js",
|
|
6
6
|
"engines": {
|