@inductiv/node-red-openai-api 0.3.9 → 0.4.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.
@@ -6,6 +6,7 @@
6
6
  "method": "Method",
7
7
  "host": "Host",
8
8
  "header": "Auth Header",
9
+ "organizationId": "Org Id",
9
10
  "apiKey": "API Key",
10
11
  "isQuery": "isQuery"
11
12
  },
@@ -48,7 +49,7 @@
48
49
  "createTranslation": "create translation",
49
50
  "listFiles": "list files",
50
51
  "purpose": "purpose",
51
- "createFile": "create file",
52
+ "uploadFile": "upload file",
52
53
  "deleteFile": "delete file",
53
54
  "file_id": "file_id",
54
55
  "retrieveFile": "retrieve file",
@@ -49,7 +49,7 @@
49
49
  "createTranslation": "create translation",
50
50
  "listFiles": "list files",
51
51
  "purpose": "purpose",
52
- "createFile": "create file",
52
+ "uploadFile": "upload file",
53
53
  "deleteFile": "delete file",
54
54
  "file_id": "file_id",
55
55
  "retrieveFile": "retrieve file",
@@ -6,6 +6,7 @@
6
6
  "method": "Method",
7
7
  "host": "Host",
8
8
  "header": "Auth Header",
9
+ "organizationId": "Org Id",
9
10
  "apiKey": "API Key",
10
11
  "isQuery": "isQuery"
11
12
  },
@@ -48,7 +49,7 @@
48
49
  "createTranslation": "create translation",
49
50
  "listFiles": "list files",
50
51
  "purpose": "purpose",
51
- "createFile": "create file",
52
+ "uploadFile": "upload file",
52
53
  "deleteFile": "delete file",
53
54
  "file_id": "file_id",
54
55
  "retrieveFile": "retrieve file",
@@ -6,6 +6,7 @@
6
6
  "method": "Method",
7
7
  "host": "Host",
8
8
  "header": "Auth Header",
9
+ "organizationId": "Org Id",
9
10
  "apiKey": "API Key",
10
11
  "isQuery": "isQuery"
11
12
  },
@@ -48,7 +49,7 @@
48
49
  "createTranslation": "create translation",
49
50
  "listFiles": "list files",
50
51
  "purpose": "purpose",
51
- "createFile": "create file",
52
+ "uploadFile": "upload file",
52
53
  "deleteFile": "delete file",
53
54
  "file_id": "file_id",
54
55
  "retrieveFile": "retrieve file",
package/node.html CHANGED
@@ -148,7 +148,7 @@
148
148
  ></option>
149
149
  <option
150
150
  value="createFile"
151
- data-i18n="OpenaiApi.parameters.createFile"
151
+ data-i18n="OpenaiApi.parameters.uploadFile"
152
152
  ></option>
153
153
  <option
154
154
  value="deleteFile"
@@ -771,8 +771,7 @@
771
771
  <span class="property-type">file</span>
772
772
  </dt>
773
773
  <dd>
774
- The audio file object (not file name) to transcribe, in one of these
775
- formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
774
+ Absolute path to the file that's being transcribed, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
776
775
  </dd>
777
776
  <dt>
778
777
  model
@@ -847,8 +846,7 @@
847
846
  <span class="property-type">file</span>
848
847
  </dt>
849
848
  <dd>
850
- The audio file object (not file name) translate, in one of these
851
- formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
849
+ Absolute path to the file that's being translated, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
852
850
  </dd>
853
851
  <dt>
854
852
  model
@@ -1200,6 +1198,101 @@
1200
1198
  </dl>
1201
1199
  </section>
1202
1200
 
1201
+ <section>
1202
+ <h1 style="font-weight: bold;">📁 Files</h1>
1203
+ <a
1204
+ href="https://platform.openai.com/docs/api-reference/files"
1205
+ target="_blank"
1206
+ >Official Documentation
1207
+ <i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1208
+ ></a>
1209
+ <h2>List Files</h2>
1210
+ <p>Returns a list of files that belong to the user's organization.</p>
1211
+ <dl class="message-properties">
1212
+ <h2>msg.payload Properties</h2>
1213
+
1214
+ <dt class="optional">
1215
+ purpose
1216
+ <a
1217
+ href="https://platform.openai.com/docs/api-reference/files/list#files-list-purpose"
1218
+ target="_blank"
1219
+ ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1220
+ ></a>
1221
+ <span class="property-type">string</span>
1222
+ </dt>
1223
+ <dd>Only return files with the given purpose.</dd>
1224
+ </dl>
1225
+
1226
+ <h2>Upload File</h2>
1227
+ <dl class="message-properties">
1228
+ <h2>msg.payload Properties</h2>
1229
+
1230
+ <dt>
1231
+ file
1232
+ <a
1233
+ href="https://platform.openai.com/docs/api-reference/files/create#files-create-file"
1234
+ target="_blank"
1235
+ ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1236
+ ></a>
1237
+ <span class="property-type">file</span>
1238
+ </dt>
1239
+ <dd>Absolute path to the file that's being uploaded.</dd>
1240
+ <dt>
1241
+ purpose
1242
+ <a
1243
+ href="https://platform.openai.com/docs/api-reference/files/create#files-create-purpose"
1244
+ target="_blank"
1245
+ ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1246
+ ></a>
1247
+ <span class="property-type">string</span>
1248
+ </dt>
1249
+ <dd>The intended purpose of the uploaded file.</dd>
1250
+ </dl>
1251
+
1252
+ <h2>Delete File</h2>
1253
+ <p>Delete a file.</p>
1254
+ <dl class="message-properties">
1255
+ <h2>msg.payload Properties</h2>
1256
+
1257
+ <dt>file_id <span class="property-type">string</span></dt>
1258
+ <dd>The ID of the file to use for this request.</dd>
1259
+ </dl>
1260
+
1261
+ <h2>Retrieve File</h2>
1262
+ <p>Returns information about a specific file.</p>
1263
+ <dl class="message-properties">
1264
+ <h2>msg.payload Properties</h2>
1265
+
1266
+ <dt>
1267
+ file_id
1268
+ <a
1269
+ href="https://platform.openai.com/docs/api-reference/files/delete#files-delete-file_id"
1270
+ target="_blank"
1271
+ ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1272
+ ></a>
1273
+ <span class="property-type">string</span>
1274
+ </dt>
1275
+ <dd>The ID of the file to use for this request.</dd>
1276
+ </dl>
1277
+
1278
+ <h2>Retrieve File Content</h2>
1279
+ <p>Returns the contents of the specified file.</p>
1280
+ <dl class="message-properties">
1281
+ <h2>msg.payload Properties</h2>
1282
+
1283
+ <dt>
1284
+ file_id
1285
+ <a
1286
+ href="https://platform.openai.com/docs/api-reference/files/retrieve-contents#files-retrieve-contents-file_id"
1287
+ target="_blank"
1288
+ ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1289
+ ></a>
1290
+ <span class="property-type">string</span>
1291
+ </dt>
1292
+ <dd>The ID of the file to use for this request.</dd>
1293
+ </dl>
1294
+ </section>
1295
+
1203
1296
  <section>
1204
1297
  <h1 style="font-weight: bold;">🔧 Fine-tuning</h1>
1205
1298
  <a
@@ -1373,101 +1466,6 @@
1373
1466
  </dl>
1374
1467
  </section>
1375
1468
 
1376
- <section>
1377
- <h1 style="font-weight: bold;">📁 Files</h1>
1378
- <a
1379
- href="https://platform.openai.com/docs/api-reference/files"
1380
- target="_blank"
1381
- >Official Documentation
1382
- <i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1383
- ></a>
1384
- <h2>List Files</h2>
1385
- <p>Returns a list of files that belong to the user's organization.</p>
1386
- <dl class="message-properties">
1387
- <h2>msg.payload Properties</h2>
1388
-
1389
- <dt class="optional">
1390
- purpose
1391
- <a
1392
- href="https://platform.openai.com/docs/api-reference/files/list#files-list-purpose"
1393
- target="_blank"
1394
- ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1395
- ></a>
1396
- <span class="property-type">string</span>
1397
- </dt>
1398
- <dd>Only return files with the given purpose.</dd>
1399
- </dl>
1400
-
1401
- <h2>Upload File</h2>
1402
- <dl class="message-properties">
1403
- <h2>msg.payload Properties</h2>
1404
-
1405
- <dt>
1406
- file
1407
- <a
1408
- href="https://platform.openai.com/docs/api-reference/files/create#files-create-file"
1409
- target="_blank"
1410
- ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1411
- ></a>
1412
- <span class="property-type">file</span>
1413
- </dt>
1414
- <dd>The File object (not file name) to be uploaded.</dd>
1415
- <dt>
1416
- purpose
1417
- <a
1418
- href="https://platform.openai.com/docs/api-reference/files/create#files-create-purpose"
1419
- target="_blank"
1420
- ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1421
- ></a>
1422
- <span class="property-type">string</span>
1423
- </dt>
1424
- <dd>The intended purpose of the uploaded file.</dd>
1425
- </dl>
1426
-
1427
- <h2>Delete File</h2>
1428
- <p>Delete a file.</p>
1429
- <dl class="message-properties">
1430
- <h2>msg.payload Properties</h2>
1431
-
1432
- <dt>file_id <span class="property-type">string</span></dt>
1433
- <dd>The ID of the file to use for this request.</dd>
1434
- </dl>
1435
-
1436
- <h2>Retrieve File</h2>
1437
- <p>Returns information about a specific file.</p>
1438
- <dl class="message-properties">
1439
- <h2>msg.payload Properties</h2>
1440
-
1441
- <dt>
1442
- file_id
1443
- <a
1444
- href="https://platform.openai.com/docs/api-reference/files/delete#files-delete-file_id"
1445
- target="_blank"
1446
- ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1447
- ></a>
1448
- <span class="property-type">string</span>
1449
- </dt>
1450
- <dd>The ID of the file to use for this request.</dd>
1451
- </dl>
1452
-
1453
- <h2>Retrieve File Content</h2>
1454
- <p>Returns the contents of the specified file.</p>
1455
- <dl class="message-properties">
1456
- <h2>msg.payload Properties</h2>
1457
-
1458
- <dt>
1459
- file_id
1460
- <a
1461
- href="https://platform.openai.com/docs/api-reference/files/retrieve-contents#files-retrieve-contents-file_id"
1462
- target="_blank"
1463
- ><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
1464
- ></a>
1465
- <span class="property-type">string</span>
1466
- </dt>
1467
- <dd>The ID of the file to use for this request.</dd>
1468
- </dl>
1469
- </section>
1470
-
1471
1469
  <section>
1472
1470
  <h1 style="font-weight: bold;">🖼️ Images</h1>
1473
1471
  <a
package/node.js CHANGED
@@ -1,113 +1,76 @@
1
- 'use strict';
2
- const lib = require('./lib.js');
1
+ "use strict";
2
+ const lib = require("./lib.js");
3
3
 
4
4
  module.exports = function (RED) {
5
- class OpenaiApiNode {
6
- constructor(config) {
7
- RED.nodes.createNode(this, config);
8
- this.service = RED.nodes.getNode(config.service);
9
- this.method = config.method;
5
+ class OpenaiApiNode {
6
+ constructor(config) {
7
+ RED.nodes.createNode(this, config);
8
+ this.service = RED.nodes.getNode(config.service);
9
+ this.method = config.method;
10
10
 
11
- let node = this;
11
+ let node = this;
12
12
 
13
- node.on('input', function (msg) {
14
- let errorFlag = false;
15
- let client = new lib.OpenaiApi();
16
- if (!errorFlag && this.service) {
17
- client.setApiBase(this.service.apiBase);
18
- client.setOrganizationIdHeader(this.service.organizationId);
19
- }
13
+ node.on("input", function (msg) {
14
+ let client = new lib.OpenaiApi();
20
15
 
21
- if (!errorFlag && this.service && this.service.credentials && this.service.credentials.secureApiKeyValue) {
22
- if (this.service.secureApiKeyIsQuery) {
23
- client.setApiKey(this.service.credentials.secureApiKeyValue,
24
- this.service.secureApiKeyHeaderOrQueryName, true);
25
- } else {
26
- client.setApiKey(this.service.credentials.secureApiKeyValue,
27
- this.service.secureApiKeyHeaderOrQueryName, false);
28
- }
29
- }
16
+ const serviceName = node.method; // Set the service name to call.
17
+ let serviceParametersObject = {
18
+ organization: node.service.organizationId,
19
+ apiBase: node.service.apiBase,
20
+ apiKey: node.service.credentials.secureApiKeyValue || "",
21
+ _node: node,
22
+ payload: { ...msg.payload },
23
+ };
30
24
 
31
- if (!errorFlag){
32
- client.setNodeRef(node);
33
- }
25
+ // Dynamically call the function based on the service name
26
+ const functionName = `${serviceName}`;
27
+ if (typeof client[functionName] === "function") {
28
+ node.status({
29
+ fill: "blue",
30
+ shape: "dot",
31
+ text: "OpenaiApi.status.requesting",
32
+ });
34
33
 
35
- if (!errorFlag) {
36
- client.body = msg.payload;
37
- }
38
-
39
- let result;
40
-
41
- if (!errorFlag) {
42
- const serviceName = node.method; // Specify the service you want to process
43
- let serviceParametersObject = {};
44
-
45
- // Dynamically call the function based on the service name
46
- const functionName = `${serviceName}`;
47
- if (typeof client[functionName] === 'function') {
48
- serviceParametersObject.body = msg.payload || {};
49
- result = client[functionName](serviceParametersObject);
50
- } else {
51
- console.error(`Function ${functionName} does not exist on client.`);
52
- }
53
- }
54
-
55
- if (!errorFlag && result === undefined) {
56
- node.error('Method is not specified.', msg);
57
- errorFlag = true;
58
- }
59
-
60
- let setData = function (msg, response) {
61
- if (response) {
62
- if (response.status) {
63
- msg.statusCode = response.status;
64
- }
65
- if (response.headers) {
66
- msg.headers = response.headers;
67
- }
68
- if (response.config && response.config.url) {
69
- msg.responseUrl = response.config.url;
70
- }
71
- if (response.data) {
72
- msg.payload = response.data;
73
- }
74
- }
75
- return msg;
76
- };
77
-
78
- if (!errorFlag) {
79
- node.status({ fill: 'blue', shape: 'dot', text: 'OpenaiApi.status.requesting' });
80
- result.then(function (response) {
81
- node.send(setData(msg, response));
82
- node.status({});
83
- }).catch(function (error) {
84
- let message = error.message;
85
- let errorData = error.response || {}; // Fallback to an empty object if response is not available
86
- node.error(message, setData(msg, errorData));
87
- node.status({ fill: 'red', shape: 'ring', text: 'node-red:common.status.error' });
88
- });
89
- }
34
+ client[functionName](serviceParametersObject)
35
+ .then((payload) => {
36
+ // Update `msg.payload` with the payload from the API response.
37
+ msg.payload = payload;
38
+ node.send(msg);
39
+ node.status({});
40
+ })
41
+ .catch(function (error) {
42
+ node.status({
43
+ fill: "red",
44
+ shape: "ring",
45
+ text: "node-red:common.status.error",
46
+ });
47
+ let errorMessage = error.message;
48
+ node.error(errorMessage, { payload: {} });
90
49
  });
50
+ } else {
51
+ console.error(`Function ${functionName} does not exist on client.`);
91
52
  }
53
+ });
92
54
  }
55
+ }
93
56
 
94
- RED.nodes.registerType('OpenAI API', OpenaiApiNode);
95
- class ServiceHostNode {
96
- constructor(n) {
97
- RED.nodes.createNode(this, n);
57
+ RED.nodes.registerType("OpenAI API", OpenaiApiNode);
58
+ class ServiceHostNode {
59
+ constructor(n) {
60
+ RED.nodes.createNode(this, n);
98
61
 
99
- this.secureApiKeyValue = n.secureApiKeyValue;
100
- this.apiBase = n.apiBase;
101
- this.secureApiKeyHeaderOrQueryName = n.secureApiKeyHeaderOrQueryName;
102
- this.secureApiKeyIsQuery = n.secureApiKeyIsQuery;
103
- this.organizationId = n.organizationId;
104
- }
62
+ this.secureApiKeyValue = n.secureApiKeyValue;
63
+ this.apiBase = n.apiBase;
64
+ this.secureApiKeyHeaderOrQueryName = n.secureApiKeyHeaderOrQueryName;
65
+ this.secureApiKeyIsQuery = n.secureApiKeyIsQuery;
66
+ this.organizationId = n.organizationId;
105
67
  }
68
+ }
106
69
 
107
- RED.nodes.registerType('Service Host', ServiceHostNode, {
108
- credentials: {
109
- secureApiKeyValue: { type: 'password' },
110
- temp: { type: 'text' }
111
- }
112
- });
70
+ RED.nodes.registerType("Service Host", ServiceHostNode, {
71
+ credentials: {
72
+ secureApiKeyValue: { type: "password" },
73
+ temp: { type: "text" },
74
+ },
75
+ });
113
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inductiv/node-red-openai-api",
3
- "version": "0.3.9",
3
+ "version": "0.4.1",
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": {
@@ -27,8 +27,7 @@
27
27
  "ai"
28
28
  ],
29
29
  "dependencies": {
30
- "axios": "^1.6.0",
31
- "form-data": "^4.0.0"
30
+ "openai": "^4.26.1"
32
31
  },
33
32
  "devDependencies": {
34
33
  "eslint": "^8.54.0",