@inductiv/node-red-openai-api 0.4.1 → 0.6.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 +13 -25
- package/lib.js +60 -53
- package/locales/de-DE/node.json +2 -1
- package/locales/en-US/node.json +4 -2
- package/locales/zh-CN/node.json +2 -1
- package/node.html +25 -2
- package/node.js +21 -8
- package/package.json +1 -1
- package/.eslintrc.json +0 -12
- package/.prettierrc +0 -4
package/README.md
CHANGED
|
@@ -9,19 +9,13 @@
|
|
|
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
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- Audio
|
|
20
|
-
- Images
|
|
21
|
-
- Assistants
|
|
22
|
-
- Reliability improvements.
|
|
23
|
-
- Now has full OpenAI Node.js package spec parity.
|
|
24
|
-
- Bug fixes.
|
|
12
|
+
## New in Version 0.6.0
|
|
13
|
+
|
|
14
|
+
- The node now has a customizable input type field in the editor dialog.
|
|
15
|
+
- You can now configure your API call payload using either a `msg`, `flow`, or `global` property setting. This brings even greater contextual control to your AI requests.
|
|
16
|
+
- **Note:** Existing implementations default to `msg.payload` and _should_ continue to work as implemented using previous versions of this node.
|
|
17
|
+
|
|
18
|
+
Please report any issues [here on Github](https://github.com/allanbunch/node-red-openai-api/issues).
|
|
25
19
|
|
|
26
20
|
## Key Features
|
|
27
21
|
|
|
@@ -100,21 +94,15 @@ I very much appreciate community input and invite everyone to shape the future o
|
|
|
100
94
|
|
|
101
95
|
### Engage in Various Discussions
|
|
102
96
|
|
|
103
|
-
- **Announcements**: Stay updated with the latest project news.
|
|
104
|
-
- **General**: Share thoughts or seek advice on broader topics.
|
|
105
|
-
- **Ideas**: Propose new features or improvements.
|
|
106
|
-
- **Polls**: Participate in polls to influence project decisions.
|
|
107
|
-
- **Q&A**: Get answers to your questions and share your expertise.
|
|
108
|
-
- **Show and Tell**: Showcase your creative implementations and inspire others.
|
|
97
|
+
- **[Announcements](https://github.com/allanbunch/node-red-openai-api/discussions/categories/announcements)**: Stay updated with the latest project news.
|
|
98
|
+
- **[General](https://github.com/allanbunch/node-red-openai-api/discussions/categories/general)**: Share thoughts or seek advice on broader topics.
|
|
99
|
+
- **[Ideas](https://github.com/allanbunch/node-red-openai-api/discussions/categories/ideas)**: Propose new features or improvements.
|
|
100
|
+
- **[Polls](https://github.com/allanbunch/node-red-openai-api/discussions/categories/polls)**: Participate in polls to influence project decisions.
|
|
101
|
+
- **[Q&A](https://github.com/allanbunch/node-red-openai-api/discussions/categories/q-a)**: Get answers to your questions and share your expertise.
|
|
102
|
+
- **[Show and Tell](https://github.com/allanbunch/node-red-openai-api/discussions/categories/show-and-tell)**: Showcase your creative implementations and inspire others.
|
|
109
103
|
|
|
110
104
|
Join the conversation [here](https://github.com/allanbunch/node-red-openai-api/discussions) and let's build a vibrant and collaborative community together!
|
|
111
105
|
|
|
112
106
|
## License
|
|
113
107
|
|
|
114
108
|
[MIT](./LICENSE)
|
|
115
|
-
|
|
116
|
-
## Acknowledgements
|
|
117
|
-
|
|
118
|
-
- [node-red-nodegen](https://github.com/node-red/node-red-nodegen)
|
|
119
|
-
- For boilerplate code generation, though the auto-generated code has been largely refactored.
|
|
120
|
-
- **Note:** This package uses `axios` in place of node-red-nodegen's `request` default.
|
package/lib.js
CHANGED
|
@@ -13,7 +13,7 @@ let OpenaiApi = (function () {
|
|
|
13
13
|
apiKey: parameters.apiKey,
|
|
14
14
|
baseURL: parameters.apiBase,
|
|
15
15
|
organization: parameters.organization,
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
const openai = new OpenAI(clientParams);
|
|
19
19
|
const response = await openai.chat.completions.create({
|
|
@@ -21,22 +21,29 @@ let OpenaiApi = (function () {
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
if (parameters.payload.stream) {
|
|
24
|
+
node.status({
|
|
25
|
+
fill: "green",
|
|
26
|
+
shape: "dot",
|
|
27
|
+
text: "OpenaiApi.status.streaming",
|
|
28
|
+
});
|
|
24
29
|
for await (const chunk of response) {
|
|
25
|
-
|
|
30
|
+
if (typeof chunk === "object") {
|
|
31
|
+
let payload = { payload: chunk };
|
|
32
|
+
node.send(payload);
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
|
-
|
|
35
|
+
node.status({});
|
|
28
36
|
} else {
|
|
29
37
|
return response;
|
|
30
38
|
}
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
async createImage(parameters) {
|
|
34
|
-
|
|
35
42
|
const clientParams = {
|
|
36
43
|
apiKey: parameters.apiKey,
|
|
37
44
|
baseURL: parameters.apiBase,
|
|
38
45
|
organization: parameters.organization,
|
|
39
|
-
}
|
|
46
|
+
};
|
|
40
47
|
|
|
41
48
|
const openai = new OpenAI(clientParams);
|
|
42
49
|
const response = await openai.images.generate({
|
|
@@ -51,7 +58,7 @@ let OpenaiApi = (function () {
|
|
|
51
58
|
apiKey: parameters.apiKey,
|
|
52
59
|
baseURL: parameters.apiBase,
|
|
53
60
|
organization: parameters.organization,
|
|
54
|
-
}
|
|
61
|
+
};
|
|
55
62
|
const openai = new OpenAI(clientParams);
|
|
56
63
|
|
|
57
64
|
parameters.payload.image = fs.createReadStream(parameters.payload.image);
|
|
@@ -71,7 +78,7 @@ let OpenaiApi = (function () {
|
|
|
71
78
|
apiKey: parameters.apiKey,
|
|
72
79
|
baseURL: parameters.apiBase,
|
|
73
80
|
organization: parameters.organization,
|
|
74
|
-
}
|
|
81
|
+
};
|
|
75
82
|
const openai = new OpenAI(clientParams);
|
|
76
83
|
|
|
77
84
|
parameters.payload.image = fs.createReadStream(parameters.payload.image);
|
|
@@ -87,7 +94,7 @@ let OpenaiApi = (function () {
|
|
|
87
94
|
apiKey: parameters.apiKey,
|
|
88
95
|
baseURL: parameters.apiBase,
|
|
89
96
|
organization: parameters.organization,
|
|
90
|
-
}
|
|
97
|
+
};
|
|
91
98
|
const openai = new OpenAI(clientParams);
|
|
92
99
|
|
|
93
100
|
const response = await openai.embeddings.create({
|
|
@@ -102,7 +109,7 @@ let OpenaiApi = (function () {
|
|
|
102
109
|
apiKey: parameters.apiKey,
|
|
103
110
|
baseURL: parameters.apiBase,
|
|
104
111
|
organization: parameters.organization,
|
|
105
|
-
}
|
|
112
|
+
};
|
|
106
113
|
const openai = new OpenAI(clientParams);
|
|
107
114
|
|
|
108
115
|
const audio = await openai.audio.speech.create({ ...parameters.payload });
|
|
@@ -116,7 +123,7 @@ let OpenaiApi = (function () {
|
|
|
116
123
|
apiKey: parameters.apiKey,
|
|
117
124
|
baseURL: parameters.apiBase,
|
|
118
125
|
organization: parameters.organization,
|
|
119
|
-
}
|
|
126
|
+
};
|
|
120
127
|
const openai = new OpenAI(clientParams);
|
|
121
128
|
|
|
122
129
|
parameters.payload.file = fs.createReadStream(parameters.payload.file);
|
|
@@ -133,7 +140,7 @@ let OpenaiApi = (function () {
|
|
|
133
140
|
apiKey: parameters.apiKey,
|
|
134
141
|
baseURL: parameters.apiBase,
|
|
135
142
|
organization: parameters.organization,
|
|
136
|
-
}
|
|
143
|
+
};
|
|
137
144
|
const openai = new OpenAI(clientParams);
|
|
138
145
|
|
|
139
146
|
parameters.payload.file = fs.createReadStream(parameters.payload.file);
|
|
@@ -149,7 +156,7 @@ let OpenaiApi = (function () {
|
|
|
149
156
|
apiKey: parameters.apiKey,
|
|
150
157
|
baseURL: parameters.apiBase,
|
|
151
158
|
organization: parameters.organization,
|
|
152
|
-
}
|
|
159
|
+
};
|
|
153
160
|
const openai = new OpenAI(clientParams);
|
|
154
161
|
|
|
155
162
|
const list = await openai.files.list({
|
|
@@ -169,7 +176,7 @@ let OpenaiApi = (function () {
|
|
|
169
176
|
apiKey: parameters.apiKey,
|
|
170
177
|
baseURL: parameters.apiBase,
|
|
171
178
|
organization: parameters.organization,
|
|
172
|
-
}
|
|
179
|
+
};
|
|
173
180
|
const openai = new OpenAI(clientParams);
|
|
174
181
|
|
|
175
182
|
parameters.payload.file = fs.createReadStream(parameters.payload.file);
|
|
@@ -184,7 +191,7 @@ let OpenaiApi = (function () {
|
|
|
184
191
|
apiKey: parameters.apiKey,
|
|
185
192
|
baseURL: parameters.apiBase,
|
|
186
193
|
organization: parameters.organization,
|
|
187
|
-
}
|
|
194
|
+
};
|
|
188
195
|
const openai = new OpenAI(clientParams);
|
|
189
196
|
|
|
190
197
|
const response = await openai.files.del({
|
|
@@ -198,7 +205,7 @@ let OpenaiApi = (function () {
|
|
|
198
205
|
apiKey: parameters.apiKey,
|
|
199
206
|
baseURL: parameters.apiBase,
|
|
200
207
|
organization: parameters.organization,
|
|
201
|
-
}
|
|
208
|
+
};
|
|
202
209
|
const openai = new OpenAI(clientParams);
|
|
203
210
|
|
|
204
211
|
const file_id = parameters.payload.file_id;
|
|
@@ -215,7 +222,7 @@ let OpenaiApi = (function () {
|
|
|
215
222
|
apiKey: parameters.apiKey,
|
|
216
223
|
baseURL: parameters.apiBase,
|
|
217
224
|
organization: parameters.organization,
|
|
218
|
-
}
|
|
225
|
+
};
|
|
219
226
|
const openai = new OpenAI(clientParams);
|
|
220
227
|
|
|
221
228
|
const file_id = parameters.payload.file_id;
|
|
@@ -232,7 +239,7 @@ let OpenaiApi = (function () {
|
|
|
232
239
|
apiKey: parameters.apiKey,
|
|
233
240
|
baseURL: parameters.apiBase,
|
|
234
241
|
organization: parameters.organization,
|
|
235
|
-
}
|
|
242
|
+
};
|
|
236
243
|
const openai = new OpenAI(clientParams);
|
|
237
244
|
|
|
238
245
|
const response = await openai.fineTuning.jobs.create({
|
|
@@ -246,7 +253,7 @@ let OpenaiApi = (function () {
|
|
|
246
253
|
apiKey: parameters.apiKey,
|
|
247
254
|
baseURL: parameters.apiBase,
|
|
248
255
|
organization: parameters.organization,
|
|
249
|
-
}
|
|
256
|
+
};
|
|
250
257
|
const openai = new OpenAI(clientParams);
|
|
251
258
|
|
|
252
259
|
const list = await openai.fineTuning.jobs.list({
|
|
@@ -265,7 +272,7 @@ let OpenaiApi = (function () {
|
|
|
265
272
|
apiKey: parameters.apiKey,
|
|
266
273
|
baseURL: parameters.apiBase,
|
|
267
274
|
organization: parameters.organization,
|
|
268
|
-
}
|
|
275
|
+
};
|
|
269
276
|
const openai = new OpenAI(clientParams);
|
|
270
277
|
|
|
271
278
|
const response = await openai.fineTuning.jobs.retrieve(
|
|
@@ -279,7 +286,7 @@ let OpenaiApi = (function () {
|
|
|
279
286
|
apiKey: parameters.apiKey,
|
|
280
287
|
baseURL: parameters.apiBase,
|
|
281
288
|
organization: parameters.organization,
|
|
282
|
-
}
|
|
289
|
+
};
|
|
283
290
|
const openai = new OpenAI(clientParams);
|
|
284
291
|
|
|
285
292
|
let response = [];
|
|
@@ -296,7 +303,7 @@ let OpenaiApi = (function () {
|
|
|
296
303
|
apiKey: parameters.apiKey,
|
|
297
304
|
baseURL: parameters.apiBase,
|
|
298
305
|
organization: parameters.organization,
|
|
299
|
-
}
|
|
306
|
+
};
|
|
300
307
|
const openai = new OpenAI(clientParams);
|
|
301
308
|
|
|
302
309
|
const response = await openai.fineTuning.jobs.cancel(
|
|
@@ -310,7 +317,7 @@ let OpenaiApi = (function () {
|
|
|
310
317
|
apiKey: parameters.apiKey,
|
|
311
318
|
baseURL: parameters.apiBase,
|
|
312
319
|
organization: parameters.organization,
|
|
313
|
-
}
|
|
320
|
+
};
|
|
314
321
|
const openai = new OpenAI(clientParams);
|
|
315
322
|
|
|
316
323
|
const response = await openai.models.list();
|
|
@@ -322,7 +329,7 @@ let OpenaiApi = (function () {
|
|
|
322
329
|
apiKey: parameters.apiKey,
|
|
323
330
|
baseURL: parameters.apiBase,
|
|
324
331
|
organization: parameters.organization,
|
|
325
|
-
}
|
|
332
|
+
};
|
|
326
333
|
const openai = new OpenAI(clientParams);
|
|
327
334
|
|
|
328
335
|
const model = parameters.payload.model;
|
|
@@ -335,7 +342,7 @@ let OpenaiApi = (function () {
|
|
|
335
342
|
apiKey: parameters.apiKey,
|
|
336
343
|
baseURL: parameters.apiBase,
|
|
337
344
|
organization: parameters.organization,
|
|
338
|
-
}
|
|
345
|
+
};
|
|
339
346
|
const openai = new OpenAI(clientParams);
|
|
340
347
|
|
|
341
348
|
const model = parameters.payload.model;
|
|
@@ -348,7 +355,7 @@ let OpenaiApi = (function () {
|
|
|
348
355
|
apiKey: parameters.apiKey,
|
|
349
356
|
baseURL: parameters.apiBase,
|
|
350
357
|
organization: parameters.organization,
|
|
351
|
-
}
|
|
358
|
+
};
|
|
352
359
|
const openai = new OpenAI(clientParams);
|
|
353
360
|
|
|
354
361
|
const response = await openai.moderations.create(parameters.payload);
|
|
@@ -359,7 +366,7 @@ let OpenaiApi = (function () {
|
|
|
359
366
|
apiKey: parameters.apiKey,
|
|
360
367
|
baseURL: parameters.apiBase,
|
|
361
368
|
organization: parameters.organization,
|
|
362
|
-
}
|
|
369
|
+
};
|
|
363
370
|
const openai = new OpenAI(clientParams);
|
|
364
371
|
|
|
365
372
|
const response = await openai.beta.assistants.list({
|
|
@@ -373,7 +380,7 @@ let OpenaiApi = (function () {
|
|
|
373
380
|
apiKey: parameters.apiKey,
|
|
374
381
|
baseURL: parameters.apiBase,
|
|
375
382
|
organization: parameters.organization,
|
|
376
|
-
}
|
|
383
|
+
};
|
|
377
384
|
const openai = new OpenAI(clientParams);
|
|
378
385
|
|
|
379
386
|
const response = await openai.beta.assistants.create({
|
|
@@ -387,7 +394,7 @@ let OpenaiApi = (function () {
|
|
|
387
394
|
apiKey: parameters.apiKey,
|
|
388
395
|
baseURL: parameters.apiBase,
|
|
389
396
|
organization: parameters.organization,
|
|
390
|
-
}
|
|
397
|
+
};
|
|
391
398
|
const openai = new OpenAI(clientParams);
|
|
392
399
|
|
|
393
400
|
const id = parameters.payload.assistant_id;
|
|
@@ -400,7 +407,7 @@ let OpenaiApi = (function () {
|
|
|
400
407
|
apiKey: parameters.apiKey,
|
|
401
408
|
baseURL: parameters.apiBase,
|
|
402
409
|
organization: parameters.organization,
|
|
403
|
-
}
|
|
410
|
+
};
|
|
404
411
|
const openai = new OpenAI(clientParams);
|
|
405
412
|
|
|
406
413
|
const id = parameters.payload.assistant_id;
|
|
@@ -417,7 +424,7 @@ let OpenaiApi = (function () {
|
|
|
417
424
|
apiKey: parameters.apiKey,
|
|
418
425
|
baseURL: parameters.apiBase,
|
|
419
426
|
organization: parameters.organization,
|
|
420
|
-
}
|
|
427
|
+
};
|
|
421
428
|
const openai = new OpenAI(clientParams);
|
|
422
429
|
|
|
423
430
|
const id = parameters.payload.assistant_id;
|
|
@@ -430,7 +437,7 @@ let OpenaiApi = (function () {
|
|
|
430
437
|
apiKey: parameters.apiKey,
|
|
431
438
|
baseURL: parameters.apiBase,
|
|
432
439
|
organization: parameters.organization,
|
|
433
|
-
}
|
|
440
|
+
};
|
|
434
441
|
const openai = new OpenAI(clientParams);
|
|
435
442
|
|
|
436
443
|
const response = await openai.beta.threads.create({
|
|
@@ -444,7 +451,7 @@ let OpenaiApi = (function () {
|
|
|
444
451
|
apiKey: parameters.apiKey,
|
|
445
452
|
baseURL: parameters.apiBase,
|
|
446
453
|
organization: parameters.organization,
|
|
447
|
-
}
|
|
454
|
+
};
|
|
448
455
|
const openai = new OpenAI(clientParams);
|
|
449
456
|
|
|
450
457
|
const id = parameters.payload.thread_id;
|
|
@@ -457,7 +464,7 @@ let OpenaiApi = (function () {
|
|
|
457
464
|
apiKey: parameters.apiKey,
|
|
458
465
|
baseURL: parameters.apiBase,
|
|
459
466
|
organization: parameters.organization,
|
|
460
|
-
}
|
|
467
|
+
};
|
|
461
468
|
const openai = new OpenAI(clientParams);
|
|
462
469
|
|
|
463
470
|
const id = parameters.payload.thread_id;
|
|
@@ -474,7 +481,7 @@ let OpenaiApi = (function () {
|
|
|
474
481
|
apiKey: parameters.apiKey,
|
|
475
482
|
baseURL: parameters.apiBase,
|
|
476
483
|
organization: parameters.organization,
|
|
477
|
-
}
|
|
484
|
+
};
|
|
478
485
|
const openai = new OpenAI(clientParams);
|
|
479
486
|
|
|
480
487
|
const id = parameters.payload.thread_id;
|
|
@@ -487,7 +494,7 @@ let OpenaiApi = (function () {
|
|
|
487
494
|
apiKey: parameters.apiKey,
|
|
488
495
|
baseURL: parameters.apiBase,
|
|
489
496
|
organization: parameters.organization,
|
|
490
|
-
}
|
|
497
|
+
};
|
|
491
498
|
const openai = new OpenAI(clientParams);
|
|
492
499
|
|
|
493
500
|
const id = parameters.payload.thread_id;
|
|
@@ -500,7 +507,7 @@ let OpenaiApi = (function () {
|
|
|
500
507
|
apiKey: parameters.apiKey,
|
|
501
508
|
baseURL: parameters.apiBase,
|
|
502
509
|
organization: parameters.organization,
|
|
503
|
-
}
|
|
510
|
+
};
|
|
504
511
|
const openai = new OpenAI(clientParams);
|
|
505
512
|
|
|
506
513
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -517,7 +524,7 @@ let OpenaiApi = (function () {
|
|
|
517
524
|
apiKey: parameters.apiKey,
|
|
518
525
|
baseURL: parameters.apiBase,
|
|
519
526
|
organization: parameters.organization,
|
|
520
|
-
}
|
|
527
|
+
};
|
|
521
528
|
const openai = new OpenAI(clientParams);
|
|
522
529
|
|
|
523
530
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -535,7 +542,7 @@ let OpenaiApi = (function () {
|
|
|
535
542
|
apiKey: parameters.apiKey,
|
|
536
543
|
baseURL: parameters.apiBase,
|
|
537
544
|
organization: parameters.organization,
|
|
538
|
-
}
|
|
545
|
+
};
|
|
539
546
|
const openai = new OpenAI(clientParams);
|
|
540
547
|
|
|
541
548
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -558,7 +565,7 @@ let OpenaiApi = (function () {
|
|
|
558
565
|
apiKey: parameters.apiKey,
|
|
559
566
|
baseURL: parameters.apiBase,
|
|
560
567
|
organization: parameters.organization,
|
|
561
|
-
}
|
|
568
|
+
};
|
|
562
569
|
const openai = new OpenAI(clientParams);
|
|
563
570
|
|
|
564
571
|
const response = await openai.beta.threads.createAndRun({
|
|
@@ -572,7 +579,7 @@ let OpenaiApi = (function () {
|
|
|
572
579
|
apiKey: parameters.apiKey,
|
|
573
580
|
baseURL: parameters.apiBase,
|
|
574
581
|
organization: parameters.organization,
|
|
575
|
-
}
|
|
582
|
+
};
|
|
576
583
|
const openai = new OpenAI(clientParams);
|
|
577
584
|
|
|
578
585
|
const thred_id = parameters.payload.thread_id;
|
|
@@ -589,7 +596,7 @@ let OpenaiApi = (function () {
|
|
|
589
596
|
apiKey: parameters.apiKey,
|
|
590
597
|
baseURL: parameters.apiBase,
|
|
591
598
|
organization: parameters.organization,
|
|
592
|
-
}
|
|
599
|
+
};
|
|
593
600
|
const openai = new OpenAI(clientParams);
|
|
594
601
|
|
|
595
602
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -606,7 +613,7 @@ let OpenaiApi = (function () {
|
|
|
606
613
|
apiKey: parameters.apiKey,
|
|
607
614
|
baseURL: parameters.apiBase,
|
|
608
615
|
organization: parameters.organization,
|
|
609
|
-
}
|
|
616
|
+
};
|
|
610
617
|
const openai = new OpenAI(clientParams);
|
|
611
618
|
|
|
612
619
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -626,7 +633,7 @@ let OpenaiApi = (function () {
|
|
|
626
633
|
apiKey: parameters.apiKey,
|
|
627
634
|
baseURL: parameters.apiBase,
|
|
628
635
|
organization: parameters.organization,
|
|
629
|
-
}
|
|
636
|
+
};
|
|
630
637
|
const openai = new OpenAI(clientParams);
|
|
631
638
|
|
|
632
639
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -649,7 +656,7 @@ let OpenaiApi = (function () {
|
|
|
649
656
|
apiKey: parameters.apiKey,
|
|
650
657
|
baseURL: parameters.apiBase,
|
|
651
658
|
organization: parameters.organization,
|
|
652
|
-
}
|
|
659
|
+
};
|
|
653
660
|
const openai = new OpenAI(clientParams);
|
|
654
661
|
|
|
655
662
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -672,7 +679,7 @@ let OpenaiApi = (function () {
|
|
|
672
679
|
apiKey: parameters.apiKey,
|
|
673
680
|
baseURL: parameters.apiBase,
|
|
674
681
|
organization: parameters.organization,
|
|
675
|
-
}
|
|
682
|
+
};
|
|
676
683
|
const openai = new OpenAI(clientParams);
|
|
677
684
|
|
|
678
685
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -695,7 +702,7 @@ let OpenaiApi = (function () {
|
|
|
695
702
|
apiKey: parameters.apiKey,
|
|
696
703
|
baseURL: parameters.apiBase,
|
|
697
704
|
organization: parameters.organization,
|
|
698
|
-
}
|
|
705
|
+
};
|
|
699
706
|
const openai = new OpenAI(clientParams);
|
|
700
707
|
|
|
701
708
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -718,7 +725,7 @@ let OpenaiApi = (function () {
|
|
|
718
725
|
apiKey: parameters.apiKey,
|
|
719
726
|
baseURL: parameters.apiBase,
|
|
720
727
|
organization: parameters.organization,
|
|
721
|
-
}
|
|
728
|
+
};
|
|
722
729
|
const openai = new OpenAI(clientParams);
|
|
723
730
|
|
|
724
731
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -738,7 +745,7 @@ let OpenaiApi = (function () {
|
|
|
738
745
|
apiKey: parameters.apiKey,
|
|
739
746
|
baseURL: parameters.apiBase,
|
|
740
747
|
organization: parameters.organization,
|
|
741
|
-
}
|
|
748
|
+
};
|
|
742
749
|
const openai = new OpenAI(clientParams);
|
|
743
750
|
|
|
744
751
|
const assistant_id = parameters.payload.assistant_id;
|
|
@@ -755,7 +762,7 @@ let OpenaiApi = (function () {
|
|
|
755
762
|
apiKey: parameters.apiKey,
|
|
756
763
|
baseURL: parameters.apiBase,
|
|
757
764
|
organization: parameters.organization,
|
|
758
|
-
}
|
|
765
|
+
};
|
|
759
766
|
const openai = new OpenAI(clientParams);
|
|
760
767
|
|
|
761
768
|
const assistant_id = parameters.payload.assistant_id;
|
|
@@ -772,7 +779,7 @@ let OpenaiApi = (function () {
|
|
|
772
779
|
apiKey: parameters.apiKey,
|
|
773
780
|
baseURL: parameters.apiBase,
|
|
774
781
|
organization: parameters.organization,
|
|
775
|
-
}
|
|
782
|
+
};
|
|
776
783
|
const openai = new OpenAI(clientParams);
|
|
777
784
|
|
|
778
785
|
const assistant_id = parameters.payload.assistant_id;
|
|
@@ -795,7 +802,7 @@ let OpenaiApi = (function () {
|
|
|
795
802
|
apiKey: parameters.apiKey,
|
|
796
803
|
baseURL: parameters.apiBase,
|
|
797
804
|
organization: parameters.organization,
|
|
798
|
-
}
|
|
805
|
+
};
|
|
799
806
|
const openai = new OpenAI(clientParams);
|
|
800
807
|
|
|
801
808
|
const assistant_id = parameters.payload.assistant_id;
|
|
@@ -818,7 +825,7 @@ let OpenaiApi = (function () {
|
|
|
818
825
|
apiKey: parameters.apiKey,
|
|
819
826
|
baseURL: parameters.apiBase,
|
|
820
827
|
organization: parameters.organization,
|
|
821
|
-
}
|
|
828
|
+
};
|
|
822
829
|
const openai = new OpenAI(clientParams);
|
|
823
830
|
|
|
824
831
|
const thread_id = parameters.payload.thread_id;
|
|
@@ -841,7 +848,7 @@ let OpenaiApi = (function () {
|
|
|
841
848
|
apiKey: parameters.apiKey,
|
|
842
849
|
baseURL: parameters.apiBase,
|
|
843
850
|
organization: parameters.organization,
|
|
844
|
-
}
|
|
851
|
+
};
|
|
845
852
|
const openai = new OpenAI(clientParams);
|
|
846
853
|
|
|
847
854
|
const thread_id = parameters.payload.thread_id;
|
package/locales/de-DE/node.json
CHANGED
package/locales/en-US/node.json
CHANGED
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
"header": "Auth Header",
|
|
9
9
|
"organizationId": "Org Id",
|
|
10
10
|
"apiKey": "API Key",
|
|
11
|
-
"isQuery": "isQuery"
|
|
11
|
+
"isQuery": "isQuery",
|
|
12
|
+
"property": "Property"
|
|
12
13
|
},
|
|
13
14
|
"status": {
|
|
14
|
-
"requesting": "requesting"
|
|
15
|
+
"requesting": "requesting",
|
|
16
|
+
"streaming": "streaming"
|
|
15
17
|
},
|
|
16
18
|
"parameters": {
|
|
17
19
|
"createChatCompletion": "create chat completion",
|
package/locales/zh-CN/node.json
CHANGED
package/node.html
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
color: "#B8B1FB",
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: "" },
|
|
7
|
+
property: { value: "payload", required: true },
|
|
8
|
+
propertyType: { value: "msg" },
|
|
7
9
|
service: { value: "", type: "Service Host", required: true },
|
|
8
10
|
method: { value: "", required: true },
|
|
9
11
|
},
|
|
@@ -22,8 +24,20 @@
|
|
|
22
24
|
var methods = $("#node-input-method").children();
|
|
23
25
|
var firstMethod = methods.first();
|
|
24
26
|
$("#node-input-method").val(firstMethod.val());
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// set the default property type value to "payload"
|
|
30
|
+
if (this.property === undefined) {
|
|
31
|
+
$("#node-input-property").val("payload");
|
|
25
32
|
}
|
|
26
|
-
|
|
33
|
+
|
|
34
|
+
$("#node-input-property").typedInput({
|
|
35
|
+
default: "msg",
|
|
36
|
+
value: "payload",
|
|
37
|
+
types:["msg", "flow", "global"],
|
|
38
|
+
typeField: "#node-input-propertyType"
|
|
39
|
+
})
|
|
40
|
+
}
|
|
27
41
|
});
|
|
28
42
|
</script>
|
|
29
43
|
|
|
@@ -49,6 +63,15 @@
|
|
|
49
63
|
<input type="text" id="node-input-service" />
|
|
50
64
|
</div>
|
|
51
65
|
|
|
66
|
+
<div class="form-row">
|
|
67
|
+
<label for="node-input-property"
|
|
68
|
+
><i class="fa fa-ellipsis-h"></i>
|
|
69
|
+
<span data-i18n="OpenaiApi.label.property"></span
|
|
70
|
+
></label>
|
|
71
|
+
<input type="text" id="node-input-property">
|
|
72
|
+
<input type="hidden" id="node-input-propertyType">
|
|
73
|
+
</div>
|
|
74
|
+
|
|
52
75
|
<div class="form-row">
|
|
53
76
|
<label for="node-input-method"
|
|
54
77
|
><i class="fa fa-tasks"></i>
|
|
@@ -2681,7 +2704,7 @@
|
|
|
2681
2704
|
);
|
|
2682
2705
|
if (!selected.val()) {
|
|
2683
2706
|
$("#node-config-input-secureApiKeyIsQuery").val(false);
|
|
2684
|
-
}
|
|
2707
|
+
};
|
|
2685
2708
|
},
|
|
2686
2709
|
});
|
|
2687
2710
|
</script>
|
package/node.js
CHANGED
|
@@ -5,21 +5,32 @@ module.exports = function (RED) {
|
|
|
5
5
|
class OpenaiApiNode {
|
|
6
6
|
constructor(config) {
|
|
7
7
|
RED.nodes.createNode(this, config);
|
|
8
|
-
this.service = RED.nodes.getNode(config.service);
|
|
9
|
-
this.method = config.method;
|
|
10
8
|
|
|
11
9
|
let node = this;
|
|
10
|
+
node.service = RED.nodes.getNode(config.service);
|
|
11
|
+
node.config = config;
|
|
12
12
|
|
|
13
13
|
node.on("input", function (msg) {
|
|
14
14
|
let client = new lib.OpenaiApi();
|
|
15
|
+
let payload;
|
|
15
16
|
|
|
16
|
-
const
|
|
17
|
+
const propertyType = node.config.propertyType || "msg";
|
|
18
|
+
const propertyPath = node.config.property || "payload";
|
|
19
|
+
|
|
20
|
+
if (propertyType === "msg") {
|
|
21
|
+
payload = RED.util.getMessageProperty(msg, propertyPath);
|
|
22
|
+
} else {
|
|
23
|
+
// For flow and global contexts
|
|
24
|
+
payload = node.context()[propertyType].get(propertyPath);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const serviceName = node.config.method; // Set the service name to call.
|
|
17
28
|
let serviceParametersObject = {
|
|
18
29
|
organization: node.service.organizationId,
|
|
19
30
|
apiBase: node.service.apiBase,
|
|
20
31
|
apiKey: node.service.credentials.secureApiKeyValue || "",
|
|
21
32
|
_node: node,
|
|
22
|
-
payload:
|
|
33
|
+
payload: payload,
|
|
23
34
|
};
|
|
24
35
|
|
|
25
36
|
// Dynamically call the function based on the service name
|
|
@@ -33,10 +44,12 @@ module.exports = function (RED) {
|
|
|
33
44
|
|
|
34
45
|
client[functionName](serviceParametersObject)
|
|
35
46
|
.then((payload) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
if (payload !== undefined) {
|
|
48
|
+
// Update `msg.payload` with the payload from the API response, then send resonse to client.
|
|
49
|
+
msg.payload = payload;
|
|
50
|
+
node.send(msg);
|
|
51
|
+
node.status({});
|
|
52
|
+
}
|
|
40
53
|
})
|
|
41
54
|
.catch(function (error) {
|
|
42
55
|
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.6.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": {
|
package/.eslintrc.json
DELETED
package/.prettierrc
DELETED