@inductiv/node-red-openai-api 0.3.7 → 0.3.9

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 CHANGED
@@ -9,6 +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.3.9
13
+
14
+ - Support for new OpenAI embedding models
15
+ - text-embedding-3-small
16
+ - text-embedding-3-large
17
+ - Updated node documentation
18
+
12
19
  ## Key Features
13
20
 
14
21
  - **Seamless Integration**: Directly connect with OpenAI services without the hassle of complex coding or setup.
package/lib.js CHANGED
@@ -22,6 +22,11 @@ var OpenaiApi = (function () {
22
22
  setApiBase(apiBase) {
23
23
  this.domain = apiBase;
24
24
  }
25
+
26
+ setOrganizationIdHeader(organizationId) {
27
+ this.organizationId = organizationId;
28
+ }
29
+
25
30
  setAuthHeaders(headerParams) {
26
31
  var headers = headerParams ? headerParams : {};
27
32
  if (!this.apiKey.isQuery && this.apiKey.headerOrQueryName) {
@@ -30,18 +35,22 @@ var OpenaiApi = (function () {
30
35
  return headers;
31
36
  }
32
37
 
33
- setNodeRef(node){
38
+ setNodeRef(node) {
34
39
  this.node = node;
35
40
  }
36
41
 
37
- getFromEndpoint(path, parameters, expectedQueryParams, customHeaders) {
42
+ getFromEndpoint(path, parameters, expectedQueryParams, customHeaders = {}) {
38
43
  return new Promise((resolve, reject) => {
39
44
  var domain = this.domain;
40
- var queryParameters = {},
41
- baseHeaders = {};
45
+ var organizationId = this.organizationId;
46
+ var queryParameters = {};
47
+ var baseHeaders = {};
42
48
 
43
49
  baseHeaders = this.setAuthHeaders(headers);
44
50
  baseHeaders["Accept"] = "application/json";
51
+ if (organizationId) {
52
+ customHeaders["OpenAI-Organization"] = organizationId;
53
+ }
45
54
 
46
55
  var headers = {
47
56
  ...baseHeaders,
@@ -78,26 +87,32 @@ var OpenaiApi = (function () {
78
87
  });
79
88
  });
80
89
  }
90
+
81
91
  postToEndpoint(
82
92
  path,
83
93
  parameters,
84
94
  expectedQueryParams,
85
95
  contentType,
86
96
  filePath,
87
- customHeaders,
97
+ customHeaders = {},
88
98
  ) {
89
99
  return new Promise((resolve, reject) => {
90
100
  const _path = require("path");
91
101
 
92
102
  parameters = parameters || {};
93
103
  var domain = this.domain;
104
+ var organizationId = this.organizationId;
94
105
  var queryParameters = {},
95
106
  baseHeaders = {},
96
107
  data;
97
108
 
98
- baseHeaders = this.setAuthHeaders({});
109
+ baseHeaders = this.setAuthHeaders(baseHeaders);
99
110
  baseHeaders["Accept"] = "application/json";
100
111
 
112
+ if (organizationId) {
113
+ customHeaders["OpenAI-Organization"] = organizationId;
114
+ }
115
+
101
116
  var headers = {
102
117
  ...baseHeaders,
103
118
  ...customHeaders,
@@ -153,26 +168,29 @@ var OpenaiApi = (function () {
153
168
  headers: headers,
154
169
  params: queryParameters,
155
170
  data: data,
156
- responseType: data.stream === true ? "stream" : "json"
171
+ responseType: data.stream === true ? "stream" : "json",
157
172
  };
158
173
 
159
174
  axios(config)
160
175
  .then((response) => {
161
176
  if (config.responseType === "stream") {
162
177
  // Handle the stream response
163
- response.data.on('data', (chunk) => {
164
- // Convert chunk from Uint8Array to string
165
- const chunkAsString = new TextDecoder().decode(chunk);
166
-
167
- // Emit converted data chunks as Node-RED messages
168
- this.node.send({ payload: chunkAsString });
169
- }).on('end', () => {
170
- // Handle the end of the stream
171
- resolve({ payload: "Stream ended" });
172
- }).on('error', (err) => {
173
- // Handle any errors
174
- reject(err);
175
- });
178
+ response.data
179
+ .on("data", (chunk) => {
180
+ // Convert chunk from Uint8Array to string
181
+ const chunkAsString = new TextDecoder().decode(chunk);
182
+
183
+ // Emit converted data chunks as Node-RED messages
184
+ this.node.send({ payload: chunkAsString });
185
+ })
186
+ .on("end", () => {
187
+ // Handle the end of the stream
188
+ resolve({ payload: "Stream ended" });
189
+ })
190
+ .on("error", (err) => {
191
+ // Handle any errors
192
+ reject(err);
193
+ });
176
194
  } else {
177
195
  // Handle non-stream response (e.g., JSON)
178
196
  resolve(response);
@@ -184,16 +202,26 @@ var OpenaiApi = (function () {
184
202
  });
185
203
  }
186
204
 
187
- deleteFromEndpoint(path, parameters, expectedQueryParams, customHeaders) {
205
+ deleteFromEndpoint(
206
+ path,
207
+ parameters,
208
+ expectedQueryParams,
209
+ customHeaders = {},
210
+ ) {
188
211
  return new Promise((resolve, reject) => {
189
212
  parameters = parameters || {};
190
213
  var domain = this.domain;
214
+ var organizationId = this.organizationId;
191
215
  var queryParameters = {},
192
216
  baseHeaders = {};
193
217
 
194
218
  baseHeaders = this.setAuthHeaders(headers);
195
219
  baseHeaders["Accept"] = "application/json";
196
220
 
221
+ if (organizationId) {
222
+ customHeaders["OpenAI-Organization"] = organizationId;
223
+ }
224
+
197
225
  var headers = {
198
226
  ...baseHeaders,
199
227
  ...customHeaders,
@@ -229,6 +257,7 @@ var OpenaiApi = (function () {
229
257
  });
230
258
  });
231
259
  }
260
+
232
261
  createChatCompletion(parameters) {
233
262
  const response = this.postToEndpoint("/chat/completions", parameters);
234
263
  return response;
@@ -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
  },