@inductiv/node-red-openai-api 0.6.0 → 0.8.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 +3 -5
- package/lib.js +241 -460
- package/node.html +139 -4
- package/node.js +10 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,11 +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.
|
|
12
|
+
## New in Version 0.8.0
|
|
13
13
|
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
- **Note:** Existing implementations default to `msg.payload` and _should_ continue to work as implemented using previous versions of this node.
|
|
14
|
+
- **Bug Fix**: Fixed an issue introduced in v. 0.7.0 that caused the `createChatCompletion` endpoint to return duplicate messages.
|
|
15
|
+
- **Enhancement**: Bumped the OpenAI API package dependency to version 4.36.0. Updated the node's documentation accordingly.
|
|
17
16
|
|
|
18
17
|
Please report any issues [here on Github](https://github.com/allanbunch/node-red-openai-api/issues).
|
|
19
18
|
|
|
@@ -55,7 +54,6 @@ This package's configuration node is now named "Service Host" to serve as a more
|
|
|
55
54
|
- [Installation](#installation)
|
|
56
55
|
- [Usage](#usage)
|
|
57
56
|
- [License](#license)
|
|
58
|
-
- [Acknowledgements](#acknowledgements)
|
|
59
57
|
|
|
60
58
|
## Installation
|
|
61
59
|
|
package/lib.js
CHANGED
|
@@ -5,22 +5,24 @@ let OpenaiApi = (function () {
|
|
|
5
5
|
const OpenAI = require("openai").OpenAI;
|
|
6
6
|
|
|
7
7
|
class OpenaiApi {
|
|
8
|
+
constructor(apiKey, baseURL, organization) {
|
|
9
|
+
this.clientParams = {
|
|
10
|
+
apiKey: apiKey,
|
|
11
|
+
baseURL: baseURL,
|
|
12
|
+
organization: organization
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
async createChatCompletion(parameters) {
|
|
9
17
|
let node = parameters._node;
|
|
10
18
|
delete parameters._node;
|
|
11
19
|
|
|
12
|
-
const
|
|
13
|
-
apiKey: parameters.apiKey,
|
|
14
|
-
baseURL: parameters.apiBase,
|
|
15
|
-
organization: parameters.organization,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const openai = new OpenAI(clientParams);
|
|
20
|
+
const openai = new OpenAI(this.clientParams);
|
|
19
21
|
const response = await openai.chat.completions.create({
|
|
20
|
-
...parameters.payload,
|
|
22
|
+
...parameters.msg.payload,
|
|
21
23
|
});
|
|
22
24
|
|
|
23
|
-
if (parameters.payload.stream) {
|
|
25
|
+
if (parameters.msg.payload.stream) {
|
|
24
26
|
node.status({
|
|
25
27
|
fill: "green",
|
|
26
28
|
shape: "dot",
|
|
@@ -28,8 +30,11 @@ let OpenaiApi = (function () {
|
|
|
28
30
|
});
|
|
29
31
|
for await (const chunk of response) {
|
|
30
32
|
if (typeof chunk === "object") {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
let {_msgid, ...newMsg} = parameters.msg;
|
|
35
|
+
newMsg.payload = chunk;
|
|
36
|
+
|
|
37
|
+
node.send(newMsg);
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
node.status({});
|
|
@@ -39,128 +44,99 @@ let OpenaiApi = (function () {
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
async createImage(parameters) {
|
|
42
|
-
const
|
|
43
|
-
apiKey: parameters.apiKey,
|
|
44
|
-
baseURL: parameters.apiBase,
|
|
45
|
-
organization: parameters.organization,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const openai = new OpenAI(clientParams);
|
|
47
|
+
const openai = new OpenAI(this.clientParams);
|
|
49
48
|
const response = await openai.images.generate({
|
|
50
|
-
...parameters.payload,
|
|
49
|
+
...parameters.msg.payload,
|
|
51
50
|
});
|
|
52
51
|
|
|
53
52
|
return response;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
async createImageEdit(parameters) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
parameters.payload.mask = fs.createReadStream(parameters.payload.mask);
|
|
56
|
+
const openai = new OpenAI(this.clientParams);
|
|
57
|
+
|
|
58
|
+
parameters.msg.payload.image = fs.createReadStream(
|
|
59
|
+
parameters.msg.payload.image,
|
|
60
|
+
);
|
|
61
|
+
if (parameters.msg.payload.mask) {
|
|
62
|
+
parameters.msg.payload.mask = fs.createReadStream(
|
|
63
|
+
parameters.msg.payload.mask,
|
|
64
|
+
);
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
const response = await openai.images.edit({
|
|
70
|
-
...parameters.payload,
|
|
68
|
+
...parameters.msg.payload,
|
|
71
69
|
});
|
|
72
70
|
|
|
73
71
|
return response;
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
async createImageVariation(parameters) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const openai = new OpenAI(clientParams);
|
|
83
|
-
|
|
84
|
-
parameters.payload.image = fs.createReadStream(parameters.payload.image);
|
|
75
|
+
const openai = new OpenAI(this.clientParams);
|
|
76
|
+
|
|
77
|
+
parameters.msg.payload.image = fs.createReadStream(
|
|
78
|
+
parameters.msg.payload.image,
|
|
79
|
+
);
|
|
85
80
|
const response = await openai.images.createVariation({
|
|
86
|
-
...parameters.payload,
|
|
81
|
+
...parameters.msg.payload,
|
|
87
82
|
});
|
|
88
83
|
|
|
89
84
|
return response;
|
|
90
85
|
}
|
|
91
86
|
|
|
92
87
|
async createEmbedding(parameters) {
|
|
93
|
-
const
|
|
94
|
-
apiKey: parameters.apiKey,
|
|
95
|
-
baseURL: parameters.apiBase,
|
|
96
|
-
organization: parameters.organization,
|
|
97
|
-
};
|
|
98
|
-
const openai = new OpenAI(clientParams);
|
|
88
|
+
const openai = new OpenAI(this.clientParams);
|
|
99
89
|
|
|
100
90
|
const response = await openai.embeddings.create({
|
|
101
|
-
...parameters.payload,
|
|
91
|
+
...parameters.msg.payload,
|
|
102
92
|
});
|
|
103
93
|
|
|
104
94
|
return response;
|
|
105
95
|
}
|
|
106
96
|
|
|
107
97
|
async createSpeech(parameters) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
};
|
|
113
|
-
const openai = new OpenAI(clientParams);
|
|
114
|
-
|
|
115
|
-
const audio = await openai.audio.speech.create({ ...parameters.payload });
|
|
98
|
+
const openai = new OpenAI(this.clientParams);
|
|
99
|
+
|
|
100
|
+
const audio = await openai.audio.speech.create({
|
|
101
|
+
...parameters.msg.payload,
|
|
102
|
+
});
|
|
116
103
|
const response = Buffer.from(await audio.arrayBuffer());
|
|
117
104
|
|
|
118
105
|
return response;
|
|
119
106
|
}
|
|
120
107
|
|
|
121
108
|
async createTranscription(parameters) {
|
|
122
|
-
const
|
|
123
|
-
apiKey: parameters.apiKey,
|
|
124
|
-
baseURL: parameters.apiBase,
|
|
125
|
-
organization: parameters.organization,
|
|
126
|
-
};
|
|
127
|
-
const openai = new OpenAI(clientParams);
|
|
109
|
+
const openai = new OpenAI(this.clientParams);
|
|
128
110
|
|
|
129
|
-
parameters.payload.file = fs.createReadStream(
|
|
111
|
+
parameters.msg.payload.file = fs.createReadStream(
|
|
112
|
+
parameters.msg.payload.file,
|
|
113
|
+
);
|
|
130
114
|
|
|
131
115
|
const response = await openai.audio.transcriptions.create({
|
|
132
|
-
...parameters.payload,
|
|
116
|
+
...parameters.msg.payload,
|
|
133
117
|
});
|
|
134
118
|
|
|
135
119
|
return response;
|
|
136
120
|
}
|
|
137
121
|
|
|
138
122
|
async createTranslation(parameters) {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const openai = new OpenAI(clientParams);
|
|
145
|
-
|
|
146
|
-
parameters.payload.file = fs.createReadStream(parameters.payload.file);
|
|
123
|
+
const openai = new OpenAI(this.clientParams);
|
|
124
|
+
|
|
125
|
+
parameters.msg.payload.file = fs.createReadStream(
|
|
126
|
+
parameters.msg.payload.file,
|
|
127
|
+
);
|
|
147
128
|
const response = await openai.audio.translations.create({
|
|
148
|
-
...parameters.payload,
|
|
129
|
+
...parameters.msg.payload,
|
|
149
130
|
});
|
|
150
131
|
|
|
151
132
|
return response;
|
|
152
133
|
}
|
|
153
134
|
|
|
154
135
|
async listFiles(parameters) {
|
|
155
|
-
const
|
|
156
|
-
apiKey: parameters.apiKey,
|
|
157
|
-
baseURL: parameters.apiBase,
|
|
158
|
-
organization: parameters.organization,
|
|
159
|
-
};
|
|
160
|
-
const openai = new OpenAI(clientParams);
|
|
136
|
+
const openai = new OpenAI(this.clientParams);
|
|
161
137
|
|
|
162
138
|
const list = await openai.files.list({
|
|
163
|
-
...parameters.payload,
|
|
139
|
+
...parameters.msg.payload,
|
|
164
140
|
});
|
|
165
141
|
|
|
166
142
|
let files = [];
|
|
@@ -172,92 +148,69 @@ let OpenaiApi = (function () {
|
|
|
172
148
|
}
|
|
173
149
|
|
|
174
150
|
async createFile(parameters) {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const openai = new OpenAI(clientParams);
|
|
181
|
-
|
|
182
|
-
parameters.payload.file = fs.createReadStream(parameters.payload.file);
|
|
151
|
+
const openai = new OpenAI(this.clientParams);
|
|
152
|
+
|
|
153
|
+
parameters.msg.payload.file = fs.createReadStream(
|
|
154
|
+
parameters.msg.payload.file,
|
|
155
|
+
);
|
|
183
156
|
const response = await openai.files.create({
|
|
184
|
-
...parameters.payload,
|
|
157
|
+
...parameters.msg.payload,
|
|
185
158
|
});
|
|
186
159
|
|
|
187
160
|
return response;
|
|
188
161
|
}
|
|
162
|
+
|
|
189
163
|
async deleteFile(parameters) {
|
|
190
|
-
const
|
|
191
|
-
apiKey: parameters.apiKey,
|
|
192
|
-
baseURL: parameters.apiBase,
|
|
193
|
-
organization: parameters.organization,
|
|
194
|
-
};
|
|
195
|
-
const openai = new OpenAI(clientParams);
|
|
164
|
+
const openai = new OpenAI(this.clientParams);
|
|
196
165
|
|
|
197
166
|
const response = await openai.files.del({
|
|
198
|
-
...parameters.payload,
|
|
167
|
+
...parameters.msg.payload,
|
|
199
168
|
});
|
|
200
169
|
|
|
201
170
|
return response;
|
|
202
171
|
}
|
|
172
|
+
|
|
203
173
|
async retrieveFile(parameters) {
|
|
204
|
-
const
|
|
205
|
-
apiKey: parameters.apiKey,
|
|
206
|
-
baseURL: parameters.apiBase,
|
|
207
|
-
organization: parameters.organization,
|
|
208
|
-
};
|
|
209
|
-
const openai = new OpenAI(clientParams);
|
|
174
|
+
const openai = new OpenAI(this.clientParams);
|
|
210
175
|
|
|
211
|
-
const file_id = parameters.payload.file_id;
|
|
212
|
-
delete parameters.payload.file_id;
|
|
176
|
+
const file_id = parameters.msg.payload.file_id;
|
|
177
|
+
delete parameters.msg.payload.file_id;
|
|
213
178
|
|
|
214
179
|
const response = await openai.files.retrieve(file_id, {
|
|
215
|
-
...parameters.payload,
|
|
180
|
+
...parameters.msg.payload,
|
|
216
181
|
});
|
|
217
182
|
|
|
218
183
|
return response;
|
|
219
184
|
}
|
|
185
|
+
|
|
220
186
|
async downloadFile(parameters) {
|
|
221
|
-
const
|
|
222
|
-
apiKey: parameters.apiKey,
|
|
223
|
-
baseURL: parameters.apiBase,
|
|
224
|
-
organization: parameters.organization,
|
|
225
|
-
};
|
|
226
|
-
const openai = new OpenAI(clientParams);
|
|
187
|
+
const openai = new OpenAI(this.clientParams);
|
|
227
188
|
|
|
228
|
-
const file_id = parameters.payload.file_id;
|
|
229
|
-
delete parameters.payload.file_id;
|
|
189
|
+
const file_id = parameters.msg.payload.file_id;
|
|
190
|
+
delete parameters.msg.payload.file_id;
|
|
230
191
|
|
|
231
192
|
const response = await openai.files.retrieveContent(file_id, {
|
|
232
|
-
...parameters.payload,
|
|
193
|
+
...parameters.msg.payload,
|
|
233
194
|
});
|
|
234
195
|
|
|
235
196
|
return response;
|
|
236
197
|
}
|
|
198
|
+
|
|
237
199
|
async createFineTuningJob(parameters) {
|
|
238
|
-
const
|
|
239
|
-
apiKey: parameters.apiKey,
|
|
240
|
-
baseURL: parameters.apiBase,
|
|
241
|
-
organization: parameters.organization,
|
|
242
|
-
};
|
|
243
|
-
const openai = new OpenAI(clientParams);
|
|
200
|
+
const openai = new OpenAI(this.clientParams);
|
|
244
201
|
|
|
245
202
|
const response = await openai.fineTuning.jobs.create({
|
|
246
|
-
...parameters.payload,
|
|
203
|
+
...parameters.msg.payload,
|
|
247
204
|
});
|
|
248
205
|
|
|
249
206
|
return response;
|
|
250
207
|
}
|
|
208
|
+
|
|
251
209
|
async listPaginatedFineTuningJobs(parameters) {
|
|
252
|
-
const
|
|
253
|
-
apiKey: parameters.apiKey,
|
|
254
|
-
baseURL: parameters.apiBase,
|
|
255
|
-
organization: parameters.organization,
|
|
256
|
-
};
|
|
257
|
-
const openai = new OpenAI(clientParams);
|
|
210
|
+
const openai = new OpenAI(this.clientParams);
|
|
258
211
|
|
|
259
212
|
const list = await openai.fineTuning.jobs.list({
|
|
260
|
-
...parameters.payload,
|
|
213
|
+
...parameters.msg.payload,
|
|
261
214
|
});
|
|
262
215
|
|
|
263
216
|
let response = [];
|
|
@@ -267,268 +220,176 @@ let OpenaiApi = (function () {
|
|
|
267
220
|
|
|
268
221
|
return response;
|
|
269
222
|
}
|
|
223
|
+
|
|
270
224
|
async retrieveFineTuningJob(parameters) {
|
|
271
|
-
const
|
|
272
|
-
apiKey: parameters.apiKey,
|
|
273
|
-
baseURL: parameters.apiBase,
|
|
274
|
-
organization: parameters.organization,
|
|
275
|
-
};
|
|
276
|
-
const openai = new OpenAI(clientParams);
|
|
225
|
+
const openai = new OpenAI(this.clientParams);
|
|
277
226
|
|
|
278
227
|
const response = await openai.fineTuning.jobs.retrieve(
|
|
279
|
-
parameters.payload.fine_tuning_job_id,
|
|
228
|
+
parameters.msg.payload.fine_tuning_job_id,
|
|
280
229
|
);
|
|
281
230
|
|
|
282
231
|
return response;
|
|
283
232
|
}
|
|
233
|
+
|
|
284
234
|
async listFineTuningEvents(parameters) {
|
|
285
|
-
const
|
|
286
|
-
apiKey: parameters.apiKey,
|
|
287
|
-
baseURL: parameters.apiBase,
|
|
288
|
-
organization: parameters.organization,
|
|
289
|
-
};
|
|
290
|
-
const openai = new OpenAI(clientParams);
|
|
235
|
+
const openai = new OpenAI(this.clientParams);
|
|
291
236
|
|
|
292
237
|
let response = [];
|
|
293
238
|
const list = await openai.fineTuning.jobs.listEvents(
|
|
294
|
-
parameters.payload.fine_tuning_job_id,
|
|
239
|
+
parameters.msg.payload.fine_tuning_job_id,
|
|
295
240
|
);
|
|
296
241
|
for await (const fineTuneEvent of list) {
|
|
297
242
|
response.push(fineTuneEvent);
|
|
298
243
|
}
|
|
299
244
|
return response;
|
|
300
245
|
}
|
|
246
|
+
|
|
301
247
|
async cancelFineTuningJob(parameters) {
|
|
302
|
-
const
|
|
303
|
-
apiKey: parameters.apiKey,
|
|
304
|
-
baseURL: parameters.apiBase,
|
|
305
|
-
organization: parameters.organization,
|
|
306
|
-
};
|
|
307
|
-
const openai = new OpenAI(clientParams);
|
|
248
|
+
const openai = new OpenAI(this.clientParams);
|
|
308
249
|
|
|
309
250
|
const response = await openai.fineTuning.jobs.cancel(
|
|
310
|
-
parameters.payload.fine_tuning_job_id,
|
|
251
|
+
parameters.msg.payload.fine_tuning_job_id,
|
|
311
252
|
);
|
|
312
253
|
|
|
313
254
|
return response;
|
|
314
255
|
}
|
|
315
|
-
async listModels(parameters) {
|
|
316
|
-
const clientParams = {
|
|
317
|
-
apiKey: parameters.apiKey,
|
|
318
|
-
baseURL: parameters.apiBase,
|
|
319
|
-
organization: parameters.organization,
|
|
320
|
-
};
|
|
321
|
-
const openai = new OpenAI(clientParams);
|
|
322
256
|
|
|
257
|
+
async listModels(parameters) {
|
|
258
|
+
const openai = new OpenAI(this.clientParams);
|
|
323
259
|
const response = await openai.models.list();
|
|
324
260
|
|
|
325
261
|
return response.body;
|
|
326
262
|
}
|
|
263
|
+
|
|
327
264
|
async retrieveModel(parameters) {
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
baseURL: parameters.apiBase,
|
|
331
|
-
organization: parameters.organization,
|
|
332
|
-
};
|
|
333
|
-
const openai = new OpenAI(clientParams);
|
|
334
|
-
|
|
335
|
-
const model = parameters.payload.model;
|
|
265
|
+
const openai = new OpenAI(this.clientParams);
|
|
266
|
+
const model = parameters.msg.payload.model;
|
|
336
267
|
const response = await openai.models.retrieve(model);
|
|
337
268
|
|
|
338
269
|
return response;
|
|
339
270
|
}
|
|
271
|
+
|
|
340
272
|
async deleteModel(parameters) {
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
baseURL: parameters.apiBase,
|
|
344
|
-
organization: parameters.organization,
|
|
345
|
-
};
|
|
346
|
-
const openai = new OpenAI(clientParams);
|
|
347
|
-
|
|
348
|
-
const model = parameters.payload.model;
|
|
273
|
+
const openai = new OpenAI(this.clientParams);
|
|
274
|
+
const model = parameters.msg.payload.model;
|
|
349
275
|
const response = await openai.models.del(model);
|
|
350
276
|
|
|
351
277
|
return response;
|
|
352
278
|
}
|
|
353
|
-
async createModeration(parameters) {
|
|
354
|
-
const clientParams = {
|
|
355
|
-
apiKey: parameters.apiKey,
|
|
356
|
-
baseURL: parameters.apiBase,
|
|
357
|
-
organization: parameters.organization,
|
|
358
|
-
};
|
|
359
|
-
const openai = new OpenAI(clientParams);
|
|
360
279
|
|
|
361
|
-
|
|
280
|
+
async createModeration(parameters) {
|
|
281
|
+
const openai = new OpenAI(this.clientParams);
|
|
282
|
+
const response = await openai.moderations.create(parameters.msg.payload);
|
|
362
283
|
return response;
|
|
363
284
|
}
|
|
364
|
-
async listAssistants(parameters) {
|
|
365
|
-
const clientParams = {
|
|
366
|
-
apiKey: parameters.apiKey,
|
|
367
|
-
baseURL: parameters.apiBase,
|
|
368
|
-
organization: parameters.organization,
|
|
369
|
-
};
|
|
370
|
-
const openai = new OpenAI(clientParams);
|
|
371
285
|
|
|
286
|
+
async listAssistants(parameters) {
|
|
287
|
+
const openai = new OpenAI(this.clientParams);
|
|
372
288
|
const response = await openai.beta.assistants.list({
|
|
373
|
-
...parameters.payload,
|
|
289
|
+
...parameters.msg.payload,
|
|
374
290
|
});
|
|
375
291
|
|
|
376
292
|
return response.body;
|
|
377
293
|
}
|
|
378
|
-
async createAssistant(parameters) {
|
|
379
|
-
const clientParams = {
|
|
380
|
-
apiKey: parameters.apiKey,
|
|
381
|
-
baseURL: parameters.apiBase,
|
|
382
|
-
organization: parameters.organization,
|
|
383
|
-
};
|
|
384
|
-
const openai = new OpenAI(clientParams);
|
|
385
294
|
|
|
295
|
+
async createAssistant(parameters) {
|
|
296
|
+
const openai = new OpenAI(this.clientParams);
|
|
386
297
|
const response = await openai.beta.assistants.create({
|
|
387
|
-
...parameters.payload,
|
|
298
|
+
...parameters.msg.payload,
|
|
388
299
|
});
|
|
389
300
|
|
|
390
301
|
return response;
|
|
391
302
|
}
|
|
303
|
+
|
|
392
304
|
async getAssistant(parameters) {
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
baseURL: parameters.apiBase,
|
|
396
|
-
organization: parameters.organization,
|
|
397
|
-
};
|
|
398
|
-
const openai = new OpenAI(clientParams);
|
|
399
|
-
|
|
400
|
-
const id = parameters.payload.assistant_id;
|
|
305
|
+
const openai = new OpenAI(this.clientParams);
|
|
306
|
+
const id = parameters.msg.payload.assistant_id;
|
|
401
307
|
const response = await openai.beta.assistants.retrieve(id);
|
|
402
308
|
|
|
403
309
|
return response;
|
|
404
310
|
}
|
|
405
|
-
async modifyAssistant(parameters) {
|
|
406
|
-
const clientParams = {
|
|
407
|
-
apiKey: parameters.apiKey,
|
|
408
|
-
baseURL: parameters.apiBase,
|
|
409
|
-
organization: parameters.organization,
|
|
410
|
-
};
|
|
411
|
-
const openai = new OpenAI(clientParams);
|
|
412
311
|
|
|
413
|
-
|
|
414
|
-
|
|
312
|
+
async modifyAssistant(parameters) {
|
|
313
|
+
const openai = new OpenAI(this.clientParams);
|
|
314
|
+
const id = parameters.msg.payload.assistant_id;
|
|
315
|
+
delete parameters.msg.payload.assistant_id;
|
|
415
316
|
|
|
416
317
|
const response = await openai.beta.assistants.update(id, {
|
|
417
|
-
...parameters.payload,
|
|
318
|
+
...parameters.msg.payload,
|
|
418
319
|
});
|
|
419
320
|
|
|
420
321
|
return response;
|
|
421
322
|
}
|
|
323
|
+
|
|
422
324
|
async deleteAssistant(parameters) {
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
baseURL: parameters.apiBase,
|
|
426
|
-
organization: parameters.organization,
|
|
427
|
-
};
|
|
428
|
-
const openai = new OpenAI(clientParams);
|
|
429
|
-
|
|
430
|
-
const id = parameters.payload.assistant_id;
|
|
325
|
+
const openai = new OpenAI(this.clientParams);
|
|
326
|
+
const id = parameters.msg.payload.assistant_id;
|
|
431
327
|
const response = await openai.beta.assistants.del(id);
|
|
432
328
|
|
|
433
329
|
return response;
|
|
434
330
|
}
|
|
435
|
-
async createThread(parameters) {
|
|
436
|
-
const clientParams = {
|
|
437
|
-
apiKey: parameters.apiKey,
|
|
438
|
-
baseURL: parameters.apiBase,
|
|
439
|
-
organization: parameters.organization,
|
|
440
|
-
};
|
|
441
|
-
const openai = new OpenAI(clientParams);
|
|
442
331
|
|
|
332
|
+
async createThread(parameters) {
|
|
333
|
+
const openai = new OpenAI(this.clientParams);
|
|
443
334
|
const response = await openai.beta.threads.create({
|
|
444
|
-
...parameters.payload,
|
|
335
|
+
...parameters.msg.payload,
|
|
445
336
|
});
|
|
446
337
|
|
|
447
338
|
return response;
|
|
448
339
|
}
|
|
340
|
+
|
|
449
341
|
async getThread(parameters) {
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
baseURL: parameters.apiBase,
|
|
453
|
-
organization: parameters.organization,
|
|
454
|
-
};
|
|
455
|
-
const openai = new OpenAI(clientParams);
|
|
456
|
-
|
|
457
|
-
const id = parameters.payload.thread_id;
|
|
342
|
+
const openai = new OpenAI(this.clientParams);
|
|
343
|
+
const id = parameters.msg.payload.thread_id;
|
|
458
344
|
const response = await openai.beta.threads.retrieve(id);
|
|
459
345
|
|
|
460
346
|
return response;
|
|
461
347
|
}
|
|
462
|
-
async modifyThread(parameters) {
|
|
463
|
-
const clientParams = {
|
|
464
|
-
apiKey: parameters.apiKey,
|
|
465
|
-
baseURL: parameters.apiBase,
|
|
466
|
-
organization: parameters.organization,
|
|
467
|
-
};
|
|
468
|
-
const openai = new OpenAI(clientParams);
|
|
469
348
|
|
|
470
|
-
|
|
471
|
-
|
|
349
|
+
async modifyThread(parameters) {
|
|
350
|
+
const openai = new OpenAI(this.clientParams);
|
|
351
|
+
const id = parameters.msg.payload.thread_id;
|
|
352
|
+
delete parameters.msg.payload.thread_id;
|
|
472
353
|
|
|
473
354
|
const response = await openai.beta.threads.update(id, {
|
|
474
|
-
...parameters.payload,
|
|
355
|
+
...parameters.msg.payload,
|
|
475
356
|
});
|
|
476
357
|
|
|
477
358
|
return response;
|
|
478
359
|
}
|
|
360
|
+
|
|
479
361
|
async deleteThread(parameters) {
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
baseURL: parameters.apiBase,
|
|
483
|
-
organization: parameters.organization,
|
|
484
|
-
};
|
|
485
|
-
const openai = new OpenAI(clientParams);
|
|
486
|
-
|
|
487
|
-
const id = parameters.payload.thread_id;
|
|
362
|
+
const openai = new OpenAI(this.clientParams);
|
|
363
|
+
const id = parameters.msg.payload.thread_id;
|
|
488
364
|
const response = await openai.beta.threads.del(id);
|
|
489
365
|
|
|
490
366
|
return response;
|
|
491
367
|
}
|
|
368
|
+
|
|
492
369
|
async listMessages(parameters) {
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
baseURL: parameters.apiBase,
|
|
496
|
-
organization: parameters.organization,
|
|
497
|
-
};
|
|
498
|
-
const openai = new OpenAI(clientParams);
|
|
499
|
-
|
|
500
|
-
const id = parameters.payload.thread_id;
|
|
370
|
+
const openai = new OpenAI(this.clientParams);
|
|
371
|
+
const id = parameters.msg.payload.thread_id;
|
|
501
372
|
const response = await openai.beta.threads.messages.list(id);
|
|
502
373
|
|
|
503
374
|
return response.body;
|
|
504
375
|
}
|
|
505
|
-
async createMessage(parameters) {
|
|
506
|
-
const clientParams = {
|
|
507
|
-
apiKey: parameters.apiKey,
|
|
508
|
-
baseURL: parameters.apiBase,
|
|
509
|
-
organization: parameters.organization,
|
|
510
|
-
};
|
|
511
|
-
const openai = new OpenAI(clientParams);
|
|
512
376
|
|
|
513
|
-
|
|
514
|
-
|
|
377
|
+
async createMessage(parameters) {
|
|
378
|
+
const openai = new OpenAI(this.clientParams);
|
|
379
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
380
|
+
delete parameters.msg.payload.thread_id;
|
|
515
381
|
|
|
516
382
|
const response = await openai.beta.threads.messages.create(thread_id, {
|
|
517
|
-
...parameters.payload,
|
|
383
|
+
...parameters.msg.payload,
|
|
518
384
|
});
|
|
519
385
|
|
|
520
386
|
return response;
|
|
521
387
|
}
|
|
522
|
-
async getMessage(parameters) {
|
|
523
|
-
const clientParams = {
|
|
524
|
-
apiKey: parameters.apiKey,
|
|
525
|
-
baseURL: parameters.apiBase,
|
|
526
|
-
organization: parameters.organization,
|
|
527
|
-
};
|
|
528
|
-
const openai = new OpenAI(clientParams);
|
|
529
388
|
|
|
530
|
-
|
|
531
|
-
const
|
|
389
|
+
async getMessage(parameters) {
|
|
390
|
+
const openai = new OpenAI(this.clientParams);
|
|
391
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
392
|
+
const message_id = parameters.msg.payload.message_id;
|
|
532
393
|
|
|
533
394
|
const response = await openai.beta.threads.messages.retrieve(
|
|
534
395
|
thread_id,
|
|
@@ -537,89 +398,64 @@ let OpenaiApi = (function () {
|
|
|
537
398
|
|
|
538
399
|
return response;
|
|
539
400
|
}
|
|
401
|
+
|
|
540
402
|
async modifyMessage(parameters) {
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const openai = new OpenAI(clientParams);
|
|
547
|
-
|
|
548
|
-
const thread_id = parameters.payload.thread_id;
|
|
549
|
-
const message_id = parameters.payload.message_id;
|
|
550
|
-
delete parameters.payload.thread_id;
|
|
551
|
-
delete parameters.payload.message_id;
|
|
403
|
+
const openai = new OpenAI(this.clientParams);
|
|
404
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
405
|
+
const message_id = parameters.msg.payload.message_id;
|
|
406
|
+
delete parameters.msg.payload.thread_id;
|
|
407
|
+
delete parameters.msg.payload.message_id;
|
|
552
408
|
|
|
553
409
|
const response = await openai.beta.threads.messages.update(
|
|
554
410
|
thread_id,
|
|
555
411
|
message_id,
|
|
556
412
|
{
|
|
557
|
-
...parameters.payload,
|
|
413
|
+
...parameters.msg.payload,
|
|
558
414
|
},
|
|
559
415
|
);
|
|
560
416
|
|
|
561
417
|
return response;
|
|
562
418
|
}
|
|
563
|
-
async createThreadAndRun(parameters) {
|
|
564
|
-
const clientParams = {
|
|
565
|
-
apiKey: parameters.apiKey,
|
|
566
|
-
baseURL: parameters.apiBase,
|
|
567
|
-
organization: parameters.organization,
|
|
568
|
-
};
|
|
569
|
-
const openai = new OpenAI(clientParams);
|
|
570
419
|
|
|
420
|
+
async createThreadAndRun(parameters) {
|
|
421
|
+
const openai = new OpenAI(this.clientParams);
|
|
571
422
|
const response = await openai.beta.threads.createAndRun({
|
|
572
|
-
...parameters.payload,
|
|
423
|
+
...parameters.msg.payload,
|
|
573
424
|
});
|
|
574
425
|
|
|
575
426
|
return response;
|
|
576
427
|
}
|
|
577
|
-
async listRuns(parameters) {
|
|
578
|
-
const clientParams = {
|
|
579
|
-
apiKey: parameters.apiKey,
|
|
580
|
-
baseURL: parameters.apiBase,
|
|
581
|
-
organization: parameters.organization,
|
|
582
|
-
};
|
|
583
|
-
const openai = new OpenAI(clientParams);
|
|
584
428
|
|
|
585
|
-
|
|
586
|
-
|
|
429
|
+
async listRuns(parameters) {
|
|
430
|
+
const openai = new OpenAI(this.clientParams);
|
|
431
|
+
const thred_id = parameters.msg.payload.thread_id;
|
|
432
|
+
delete parameters.msg.payload.thread_id;
|
|
587
433
|
|
|
588
434
|
const response = await openai.beta.threads.runs.list(thred_id, {
|
|
589
|
-
...parameters.payload,
|
|
435
|
+
...parameters.msg.payload,
|
|
590
436
|
});
|
|
591
437
|
|
|
592
438
|
return response.body;
|
|
593
439
|
}
|
|
594
|
-
async createRun(parameters) {
|
|
595
|
-
const clientParams = {
|
|
596
|
-
apiKey: parameters.apiKey,
|
|
597
|
-
baseURL: parameters.apiBase,
|
|
598
|
-
organization: parameters.organization,
|
|
599
|
-
};
|
|
600
|
-
const openai = new OpenAI(clientParams);
|
|
601
440
|
|
|
602
|
-
|
|
603
|
-
|
|
441
|
+
async createRun(parameters) {
|
|
442
|
+
const openai = new OpenAI(this.clientParams);
|
|
443
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
444
|
+
delete parameters.msg.payload.thread_id;
|
|
604
445
|
|
|
605
446
|
const response = await openai.beta.threads.runs.create(thread_id, {
|
|
606
|
-
...parameters.payload,
|
|
447
|
+
...parameters.msg.payload,
|
|
607
448
|
});
|
|
608
449
|
|
|
609
450
|
return response;
|
|
610
451
|
}
|
|
452
|
+
|
|
611
453
|
async getRun(parameters) {
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
const openai = new OpenAI(clientParams);
|
|
618
|
-
|
|
619
|
-
const thread_id = parameters.payload.thread_id;
|
|
620
|
-
const run_id = parameters.payload.run_id;
|
|
621
|
-
delete parameters.payload.thread_id;
|
|
622
|
-
delete parameters.payload.run_id;
|
|
454
|
+
const openai = new OpenAI(this.clientParams);
|
|
455
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
456
|
+
const run_id = parameters.msg.payload.run_id;
|
|
457
|
+
delete parameters.msg.payload.thread_id;
|
|
458
|
+
delete parameters.msg.payload.run_id;
|
|
623
459
|
|
|
624
460
|
const response = await openai.beta.threads.runs.retrieve(
|
|
625
461
|
thread_id,
|
|
@@ -628,109 +464,84 @@ let OpenaiApi = (function () {
|
|
|
628
464
|
|
|
629
465
|
return response;
|
|
630
466
|
}
|
|
467
|
+
|
|
631
468
|
async modifyRun(parameters) {
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
const openai = new OpenAI(clientParams);
|
|
638
|
-
|
|
639
|
-
const thread_id = parameters.payload.thread_id;
|
|
640
|
-
const run_id = parameters.payload.run_id;
|
|
641
|
-
delete parameters.payload.thread_id;
|
|
642
|
-
delete parameters.payload.run_id;
|
|
469
|
+
const openai = new OpenAI(this.clientParams);
|
|
470
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
471
|
+
const run_id = parameters.msg.payload.run_id;
|
|
472
|
+
delete parameters.msg.payload.thread_id;
|
|
473
|
+
delete parameters.msg.payload.run_id;
|
|
643
474
|
|
|
644
475
|
const response = await openai.beta.threads.runs.update(
|
|
645
476
|
thread_id,
|
|
646
477
|
run_id,
|
|
647
478
|
{
|
|
648
|
-
...parameters.payload,
|
|
479
|
+
...parameters.msg.payload,
|
|
649
480
|
},
|
|
650
481
|
);
|
|
651
482
|
|
|
652
483
|
return response;
|
|
653
484
|
}
|
|
485
|
+
|
|
654
486
|
async submitToolOuputsToRun(parameters) {
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
const openai = new OpenAI(clientParams);
|
|
661
|
-
|
|
662
|
-
const thread_id = parameters.payload.thread_id;
|
|
663
|
-
const run_id = parameters.payload.run_id;
|
|
664
|
-
delete parameters.payload.thread_id;
|
|
665
|
-
delete parameters.payload.run_id;
|
|
487
|
+
const openai = new OpenAI(this.clientParams);
|
|
488
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
489
|
+
const run_id = parameters.msg.payload.run_id;
|
|
490
|
+
delete parameters.msg.payload.thread_id;
|
|
491
|
+
delete parameters.msg.payload.run_id;
|
|
666
492
|
|
|
667
493
|
const response = await openai.beta.threads.runs.submitToolOutputs(
|
|
668
494
|
thread_id,
|
|
669
495
|
run_id,
|
|
670
496
|
{
|
|
671
|
-
...parameters.payload,
|
|
497
|
+
...parameters.msg.payload,
|
|
672
498
|
},
|
|
673
499
|
);
|
|
674
500
|
|
|
675
501
|
return response;
|
|
676
502
|
}
|
|
503
|
+
|
|
677
504
|
async cancelRun(parameters) {
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
const openai = new OpenAI(clientParams);
|
|
684
|
-
|
|
685
|
-
const thread_id = parameters.payload.thread_id;
|
|
686
|
-
const run_id = parameters.payload.run_id;
|
|
687
|
-
delete parameters.payload.thread_id;
|
|
688
|
-
delete parameters.payload.run_id;
|
|
505
|
+
const openai = new OpenAI(this.clientParams);
|
|
506
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
507
|
+
const run_id = parameters.msg.payload.run_id;
|
|
508
|
+
delete parameters.msg.payload.thread_id;
|
|
509
|
+
delete parameters.msg.payload.run_id;
|
|
689
510
|
|
|
690
511
|
const response = await openai.beta.threads.runs.cancel(
|
|
691
512
|
thread_id,
|
|
692
513
|
run_id,
|
|
693
514
|
{
|
|
694
|
-
...parameters.payload,
|
|
515
|
+
...parameters.msg.payload,
|
|
695
516
|
},
|
|
696
517
|
);
|
|
697
518
|
|
|
698
519
|
return response;
|
|
699
520
|
}
|
|
521
|
+
|
|
700
522
|
async listRunSteps(parameters) {
|
|
701
|
-
const
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
const openai = new OpenAI(clientParams);
|
|
707
|
-
|
|
708
|
-
const thread_id = parameters.payload.thread_id;
|
|
709
|
-
const run_id = parameters.payload.run_id;
|
|
710
|
-
delete parameters.payload.thread_id;
|
|
711
|
-
delete parameters.payload.run_id;
|
|
523
|
+
const openai = new OpenAI(this.clientParams);
|
|
524
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
525
|
+
const run_id = parameters.msg.payload.run_id;
|
|
526
|
+
delete parameters.msg.payload.thread_id;
|
|
527
|
+
delete parameters.msg.payload.run_id;
|
|
712
528
|
|
|
713
529
|
const response = await openai.beta.threads.runs.steps.list(
|
|
714
530
|
thread_id,
|
|
715
531
|
run_id,
|
|
716
532
|
{
|
|
717
|
-
...parameters.payload,
|
|
533
|
+
...parameters.msg.payload,
|
|
718
534
|
},
|
|
719
535
|
);
|
|
720
536
|
|
|
721
537
|
return response.body;
|
|
722
538
|
}
|
|
723
|
-
async getRunStep(parameters) {
|
|
724
|
-
const clientParams = {
|
|
725
|
-
apiKey: parameters.apiKey,
|
|
726
|
-
baseURL: parameters.apiBase,
|
|
727
|
-
organization: parameters.organization,
|
|
728
|
-
};
|
|
729
|
-
const openai = new OpenAI(clientParams);
|
|
730
539
|
|
|
731
|
-
|
|
732
|
-
const
|
|
733
|
-
const
|
|
540
|
+
async getRunStep(parameters) {
|
|
541
|
+
const openai = new OpenAI(this.clientParams);
|
|
542
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
543
|
+
const run_id = parameters.msg.payload.run_id;
|
|
544
|
+
const step_id = parameters.msg.payload.step_id;
|
|
734
545
|
|
|
735
546
|
const response = await openai.beta.threads.runs.steps.retrieve(
|
|
736
547
|
thread_id,
|
|
@@ -740,131 +551,101 @@ let OpenaiApi = (function () {
|
|
|
740
551
|
|
|
741
552
|
return response;
|
|
742
553
|
}
|
|
743
|
-
async listAssistantFiles(parameters) {
|
|
744
|
-
const clientParams = {
|
|
745
|
-
apiKey: parameters.apiKey,
|
|
746
|
-
baseURL: parameters.apiBase,
|
|
747
|
-
organization: parameters.organization,
|
|
748
|
-
};
|
|
749
|
-
const openai = new OpenAI(clientParams);
|
|
750
554
|
|
|
751
|
-
|
|
752
|
-
|
|
555
|
+
async listAssistantFiles(parameters) {
|
|
556
|
+
const openai = new OpenAI(this.clientParams);
|
|
557
|
+
const assistant_id = parameters.msg.payload.assistant_id;
|
|
558
|
+
delete parameters.msg.payload.assistant_id;
|
|
753
559
|
|
|
754
560
|
const response = await openai.beta.assistants.files.list(assistant_id, {
|
|
755
|
-
...parameters.payload,
|
|
561
|
+
...parameters.msg.payload,
|
|
756
562
|
});
|
|
757
563
|
|
|
758
564
|
return response.body;
|
|
759
565
|
}
|
|
760
|
-
async createAssistantFile(parameters) {
|
|
761
|
-
const clientParams = {
|
|
762
|
-
apiKey: parameters.apiKey,
|
|
763
|
-
baseURL: parameters.apiBase,
|
|
764
|
-
organization: parameters.organization,
|
|
765
|
-
};
|
|
766
|
-
const openai = new OpenAI(clientParams);
|
|
767
566
|
|
|
768
|
-
|
|
769
|
-
|
|
567
|
+
async createAssistantFile(parameters) {
|
|
568
|
+
const openai = new OpenAI(this.clientParams);
|
|
569
|
+
const assistant_id = parameters.msg.payload.assistant_id;
|
|
570
|
+
delete parameters.msg.payload.assistant_id;
|
|
770
571
|
|
|
771
572
|
const response = await openai.beta.assistants.files.create(assistant_id, {
|
|
772
|
-
...parameters.payload,
|
|
573
|
+
...parameters.msg.payload,
|
|
773
574
|
});
|
|
774
575
|
|
|
775
576
|
return response;
|
|
776
577
|
}
|
|
578
|
+
|
|
777
579
|
async getAssistantFile(parameters) {
|
|
778
|
-
const
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
const openai = new OpenAI(clientParams);
|
|
784
|
-
|
|
785
|
-
const assistant_id = parameters.payload.assistant_id;
|
|
786
|
-
const file_id = parameters.payload.file_id;
|
|
787
|
-
delete parameters.payload.assistant_id;
|
|
788
|
-
delete parameters.payload.file_id;
|
|
580
|
+
const openai = new OpenAI(this.clientParams);
|
|
581
|
+
const assistant_id = parameters.msg.payload.assistant_id;
|
|
582
|
+
const file_id = parameters.msg.payload.file_id;
|
|
583
|
+
delete parameters.msg.payload.assistant_id;
|
|
584
|
+
delete parameters.msg.payload.file_id;
|
|
789
585
|
|
|
790
586
|
const response = await openai.beta.assistants.files.retrieve(
|
|
791
587
|
assistant_id,
|
|
792
588
|
file_id,
|
|
793
589
|
{
|
|
794
|
-
...parameters.payload,
|
|
590
|
+
...parameters.msg.payload,
|
|
795
591
|
},
|
|
796
592
|
);
|
|
797
593
|
|
|
798
594
|
return response;
|
|
799
595
|
}
|
|
596
|
+
|
|
800
597
|
async deleteAssistantFile(parameters) {
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
const openai = new OpenAI(clientParams);
|
|
807
|
-
|
|
808
|
-
const assistant_id = parameters.payload.assistant_id;
|
|
809
|
-
const file_id = parameters.payload.file_id;
|
|
810
|
-
delete parameters.payload.assistant_id;
|
|
811
|
-
delete parameters.payload.file_id;
|
|
598
|
+
const openai = new OpenAI(this.clientParams);
|
|
599
|
+
const assistant_id = parameters.msg.payload.assistant_id;
|
|
600
|
+
const file_id = parameters.msg.payload.file_id;
|
|
601
|
+
delete parameters.msg.payload.assistant_id;
|
|
602
|
+
delete parameters.msg.payload.file_id;
|
|
812
603
|
|
|
813
604
|
const response = await openai.beta.assistants.files.del(
|
|
814
605
|
assistant_id,
|
|
815
606
|
file_id,
|
|
816
607
|
{
|
|
817
|
-
...parameters.payload,
|
|
608
|
+
...parameters.msg.payload,
|
|
818
609
|
},
|
|
819
610
|
);
|
|
820
611
|
|
|
821
612
|
return response;
|
|
822
613
|
}
|
|
614
|
+
|
|
823
615
|
async listMessageFiles(parameters) {
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
const openai = new OpenAI(clientParams);
|
|
830
|
-
|
|
831
|
-
const thread_id = parameters.payload.thread_id;
|
|
832
|
-
const message_id = parameters.payload.message_id;
|
|
833
|
-
delete parameters.payload.thread_id;
|
|
834
|
-
delete parameters.payload.message_id;
|
|
616
|
+
const openai = new OpenAI(this.clientParams);
|
|
617
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
618
|
+
const message_id = parameters.msg.payload.message_id;
|
|
619
|
+
delete parameters.msg.payload.thread_id;
|
|
620
|
+
delete parameters.msg.payload.message_id;
|
|
835
621
|
|
|
836
622
|
const response = await openai.beta.threads.messages.files.list(
|
|
837
623
|
thread_id,
|
|
838
624
|
message_id,
|
|
839
625
|
{
|
|
840
|
-
...parameters.payload,
|
|
626
|
+
...parameters.msg.payload,
|
|
841
627
|
},
|
|
842
628
|
);
|
|
843
629
|
|
|
844
630
|
return response;
|
|
845
631
|
}
|
|
846
|
-
async getMessageFile(parameters) {
|
|
847
|
-
const clientParams = {
|
|
848
|
-
apiKey: parameters.apiKey,
|
|
849
|
-
baseURL: parameters.apiBase,
|
|
850
|
-
organization: parameters.organization,
|
|
851
|
-
};
|
|
852
|
-
const openai = new OpenAI(clientParams);
|
|
853
632
|
|
|
854
|
-
|
|
855
|
-
const
|
|
856
|
-
const
|
|
633
|
+
async getMessageFile(parameters) {
|
|
634
|
+
const openai = new OpenAI(this.clientParams);
|
|
635
|
+
const thread_id = parameters.msg.payload.thread_id;
|
|
636
|
+
const message_id = parameters.msg.payload.message_id;
|
|
637
|
+
const file_id = parameters.msg.payload.file_id;
|
|
857
638
|
|
|
858
|
-
delete parameters.payload.thread_id;
|
|
859
|
-
delete parameters.payload.message_id;
|
|
860
|
-
delete parameters.payload.file_id;
|
|
639
|
+
delete parameters.msg.payload.thread_id;
|
|
640
|
+
delete parameters.msg.payload.message_id;
|
|
641
|
+
delete parameters.msg.payload.file_id;
|
|
861
642
|
|
|
862
643
|
const response = await openai.beta.threads.messages.files.retrieve(
|
|
863
644
|
thread_id,
|
|
864
645
|
message_id,
|
|
865
646
|
file_id,
|
|
866
647
|
{
|
|
867
|
-
...parameters.payload,
|
|
648
|
+
...parameters.msg.payload,
|
|
868
649
|
},
|
|
869
650
|
);
|
|
870
651
|
|
package/node.html
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<!--TODO: Implement Batch API endpoints: https://github.com/openai/openai-node/blob/6f72e7ad3e4e151c9334f4449d1c3555255c2793/CHANGELOG.md#features-2 -->
|
|
2
|
+
|
|
1
3
|
<script type="text/javascript">
|
|
2
4
|
RED.nodes.registerType("OpenAI API", {
|
|
3
5
|
category: "AI",
|
|
@@ -34,7 +36,7 @@
|
|
|
34
36
|
$("#node-input-property").typedInput({
|
|
35
37
|
default: "msg",
|
|
36
38
|
value: "payload",
|
|
37
|
-
types:["msg", "flow", "global"],
|
|
39
|
+
types: ["msg", "flow", "global"],
|
|
38
40
|
typeField: "#node-input-propertyType"
|
|
39
41
|
})
|
|
40
42
|
}
|
|
@@ -852,6 +854,17 @@
|
|
|
852
854
|
<span class="property-type">number</span>
|
|
853
855
|
</dt>
|
|
854
856
|
<dd>The sampling temperature, between 0 and 1.</dd>
|
|
857
|
+
|
|
858
|
+
<dt class="optional">
|
|
859
|
+
timestamp_granularities
|
|
860
|
+
<a
|
|
861
|
+
href="https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-timestamp_granularities"
|
|
862
|
+
target="_blank"
|
|
863
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
864
|
+
></a>
|
|
865
|
+
<span class="property-type">array</span>
|
|
866
|
+
</dt>
|
|
867
|
+
<dd>The timestamp granularities to populate for this transcription. <code>response_format</code> must be set to <code>verbose_json</code> to use timestamp granularities. Either or both of these options are supported: <code>word</code>, or <code>segment</code>.</dd>
|
|
855
868
|
</dl>
|
|
856
869
|
|
|
857
870
|
<h2>Create Translation</h2>
|
|
@@ -1831,6 +1844,18 @@
|
|
|
1831
1844
|
<span class="property-type">string</span>
|
|
1832
1845
|
</dt>
|
|
1833
1846
|
<dd>A cursor for use in pagination.</dd>
|
|
1847
|
+
|
|
1848
|
+
<dt class="optional">
|
|
1849
|
+
run_id
|
|
1850
|
+
<a
|
|
1851
|
+
href="https://platform.openai.com/docs/api-reference/messages/listMessages#messages-listmessages-run_id"
|
|
1852
|
+
target="_blank"
|
|
1853
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
1854
|
+
></a>
|
|
1855
|
+
<span class="property-type">string</span>
|
|
1856
|
+
</dt>
|
|
1857
|
+
<dd>Filter messages by the run ID that generated them.</dd>
|
|
1858
|
+
|
|
1834
1859
|
</dl>
|
|
1835
1860
|
|
|
1836
1861
|
<h3>Create Message</h3>
|
|
@@ -2224,6 +2249,90 @@
|
|
|
2224
2249
|
<span class="property-type">object</span>
|
|
2225
2250
|
</dt>
|
|
2226
2251
|
<dd>Set of 16 key-value pairs that can be attached to an object.</dd>
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
<dt class="optional">
|
|
2255
|
+
temperature
|
|
2256
|
+
<a
|
|
2257
|
+
href="https://platform.openai.com/docs/api-reference/runs/createThreadAndRun#runs-createthreadandrun-temperature"
|
|
2258
|
+
target="_blank"
|
|
2259
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2260
|
+
></a>
|
|
2261
|
+
<span class="property-type">number</span>
|
|
2262
|
+
</dt>
|
|
2263
|
+
<dd>What sampling temperature to use, between 0 and 2.</dd>
|
|
2264
|
+
|
|
2265
|
+
<dt class="optional">
|
|
2266
|
+
stream
|
|
2267
|
+
<a
|
|
2268
|
+
href="https://platform.openai.com/docs/api-reference/runs/createThreadAndRun#runs-createthreadandrun-stream"
|
|
2269
|
+
target="_blank"
|
|
2270
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2271
|
+
></a>
|
|
2272
|
+
<span class="property-type">boolean</span>
|
|
2273
|
+
</dt>
|
|
2274
|
+
<dd>If <code>true</code>, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a <code>data: [DONE]</code> message.</dd>
|
|
2275
|
+
|
|
2276
|
+
<dt class="optional">
|
|
2277
|
+
max_prompt_tokens
|
|
2278
|
+
<a
|
|
2279
|
+
href="https://platform.openai.com/docs/api-reference/runs/createThreadAndRun#runs-createthreadandrun-max_prompt_tokens"
|
|
2280
|
+
target="_blank"
|
|
2281
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2282
|
+
></a>
|
|
2283
|
+
<span class="property-type">integer</span>
|
|
2284
|
+
</dt>
|
|
2285
|
+
<dd>The maximum number of prompt tokens that may be used over the course of the run.</dd>
|
|
2286
|
+
|
|
2287
|
+
<dt class="optional">
|
|
2288
|
+
max_completion_tokens
|
|
2289
|
+
<a
|
|
2290
|
+
href="https://platform.openai.com/docs/api-reference/runs/createThreadAndRun#runs-createthreadandrun-max_completion_tokens"
|
|
2291
|
+
target="_blank"
|
|
2292
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2293
|
+
></a>
|
|
2294
|
+
<span class="property-type">integer</span>
|
|
2295
|
+
</dt>
|
|
2296
|
+
<dd>The maximum number of completion tokens that may be used over the course of the run.</dd>
|
|
2297
|
+
|
|
2298
|
+
<dt class="optional">
|
|
2299
|
+
truncation_strategy
|
|
2300
|
+
<a
|
|
2301
|
+
href="https://platform.openai.com/docs/api-reference/runs/createThreadAndRun#runs-createthreadandrun-truncation_strategy"
|
|
2302
|
+
target="_blank"
|
|
2303
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2304
|
+
></a>
|
|
2305
|
+
<span class="property-type">object</span>
|
|
2306
|
+
<dd>
|
|
2307
|
+
<strong><code>@property {string} type</code></strong> - The truncation strategy to use for the thread. The default is <code>auto</code>. If set to <code>last_messages</code>, the thread will be truncated to the n most recent messages in the thread. When set to <code>auto</code>, messages in the middle of the thread will be dropped to fit the context length of the model, <code>max_prompt_tokens</code>.
|
|
2308
|
+
</dd>
|
|
2309
|
+
<dd>
|
|
2310
|
+
<strong><code>@property {integer} [last_messages]</code></strong> - The number of most recent messages from the thread when constructing the context for the run.
|
|
2311
|
+
</dd>
|
|
2312
|
+
</dt>
|
|
2313
|
+
|
|
2314
|
+
<dt class="optional">
|
|
2315
|
+
tool_choice
|
|
2316
|
+
<a
|
|
2317
|
+
href="https://platform.openai.com/docs/api-reference/runs/createThreadAndRun#runs-createthreadandrun-tool_choice"
|
|
2318
|
+
target="_blank"
|
|
2319
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2320
|
+
></a>
|
|
2321
|
+
<span class="property-type">string | object</span>
|
|
2322
|
+
</dt>
|
|
2323
|
+
<dd>Controls which (if any) tool is called by the model. <code>none</code> means the model will not call any tools and instead generates a message. <code>auto</code> is the default value and means the model can pick between generating a message or calling a tool. Specifying a particular tool like <code>{"type": "TOOL_TYPE"}</code> forces the model to call that tool.</dd>
|
|
2324
|
+
|
|
2325
|
+
<dt class="optional">
|
|
2326
|
+
response_format
|
|
2327
|
+
<a
|
|
2328
|
+
href="https://platform.openai.com/docs/api-reference/runs/createThreadAndRun#runs-createthreadandrun-response_format"
|
|
2329
|
+
target="_blank"
|
|
2330
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2331
|
+
></a>
|
|
2332
|
+
<span class="property-type">string | object</span>
|
|
2333
|
+
</dt>
|
|
2334
|
+
<dd>Specifies the format that the model must output.</dd>
|
|
2335
|
+
|
|
2227
2336
|
</dl>
|
|
2228
2337
|
|
|
2229
2338
|
<h2>List Runs</h2>
|
|
@@ -2328,9 +2437,35 @@
|
|
|
2328
2437
|
<span class="property-type">string</span>
|
|
2329
2438
|
</dt>
|
|
2330
2439
|
<dd>
|
|
2331
|
-
|
|
2332
|
-
run.
|
|
2440
|
+
Overrides the instructions of the assistant. This is useful for modifying the behavior on a per-run basis.
|
|
2333
2441
|
</dd>
|
|
2442
|
+
|
|
2443
|
+
<dt class="optional">
|
|
2444
|
+
additional_instructions
|
|
2445
|
+
<a
|
|
2446
|
+
href="https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-additional_instructions"
|
|
2447
|
+
target="_blank"
|
|
2448
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2449
|
+
></a>
|
|
2450
|
+
<span class="property-type">string</span>
|
|
2451
|
+
</dt>
|
|
2452
|
+
<dd>
|
|
2453
|
+
Appends additional instructions at the end of the instructions for the run. This is useful for modifying the behavior on a per-run basis without overriding other instructions.
|
|
2454
|
+
</dd>
|
|
2455
|
+
|
|
2456
|
+
<dt class="optional">
|
|
2457
|
+
additional_messages
|
|
2458
|
+
<a
|
|
2459
|
+
href="https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-additional_messages"
|
|
2460
|
+
target="_blank"
|
|
2461
|
+
><i class="fa fa-external-link fa-sm" aria-hidden="true"></i
|
|
2462
|
+
></a>
|
|
2463
|
+
<span class="property-type">array</span>
|
|
2464
|
+
</dt>
|
|
2465
|
+
<dd>
|
|
2466
|
+
Adds additional messages to the thread before creating the run.
|
|
2467
|
+
</dd>
|
|
2468
|
+
|
|
2334
2469
|
<dt class="optional">
|
|
2335
2470
|
tools
|
|
2336
2471
|
<a
|
|
@@ -2789,4 +2924,4 @@
|
|
|
2789
2924
|
<script type="text/html" data-help-name="Service Host">
|
|
2790
2925
|
<p><b>Header</b>: Variable name to set API key</p>
|
|
2791
2926
|
<p><b>Value</b>: Value of API key</p>
|
|
2792
|
-
</script>
|
|
2927
|
+
</script>
|
package/node.js
CHANGED
|
@@ -11,7 +11,15 @@ module.exports = function (RED) {
|
|
|
11
11
|
node.config = config;
|
|
12
12
|
|
|
13
13
|
node.on("input", function (msg) {
|
|
14
|
-
let
|
|
14
|
+
let clientApiKey = node.service.credentials.secureApiKeyValue || "";
|
|
15
|
+
let clientApiBase = node.service.apiBase;
|
|
16
|
+
let clientOrganization = node.service.organizationId;
|
|
17
|
+
|
|
18
|
+
let client = new lib.OpenaiApi(
|
|
19
|
+
clientApiKey,
|
|
20
|
+
clientApiBase,
|
|
21
|
+
clientOrganization,
|
|
22
|
+
);
|
|
15
23
|
let payload;
|
|
16
24
|
|
|
17
25
|
const propertyType = node.config.propertyType || "msg";
|
|
@@ -26,11 +34,8 @@ module.exports = function (RED) {
|
|
|
26
34
|
|
|
27
35
|
const serviceName = node.config.method; // Set the service name to call.
|
|
28
36
|
let serviceParametersObject = {
|
|
29
|
-
organization: node.service.organizationId,
|
|
30
|
-
apiBase: node.service.apiBase,
|
|
31
|
-
apiKey: node.service.credentials.secureApiKeyValue || "",
|
|
32
37
|
_node: node,
|
|
33
|
-
|
|
38
|
+
msg: msg,
|
|
34
39
|
};
|
|
35
40
|
|
|
36
41
|
// Dynamically call the function based on the service name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inductiv/node-red-openai-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"ai"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"openai": "^4.
|
|
30
|
+
"openai": "^4.36.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"eslint": "^8.54.0",
|