@inductiv/node-red-openai-api 0.7.0 → 1.0.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 +50 -62
- package/examples/assistants.json +156 -189
- package/examples/chat.json +5 -3
- package/examples/embeddings.json +9 -2
- package/examples/fine-tuning.json +3 -1
- package/examples/messages.json +4 -2
- package/examples/models.json +3 -1
- package/examples/threads.json +3 -1
- package/lib.js +411 -656
- package/locales/de-DE/node.json +20 -2
- package/locales/en-US/node.json +18 -1
- package/locales/ja/node.json +18 -3
- package/locales/zh-CN/node.json +20 -2
- package/node.html +1141 -171
- package/node.js +9 -4
- package/package.json +22 -15
package/lib.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { response } = require("express");
|
|
2
|
+
|
|
1
3
|
let OpenaiApi = (function () {
|
|
2
4
|
"use strict";
|
|
3
5
|
|
|
@@ -5,358 +7,389 @@ let OpenaiApi = (function () {
|
|
|
5
7
|
const OpenAI = require("openai").OpenAI;
|
|
6
8
|
|
|
7
9
|
class OpenaiApi {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
apiKey: parameters.apiKey,
|
|
14
|
-
baseURL: parameters.apiBase,
|
|
15
|
-
organization: parameters.organization,
|
|
10
|
+
constructor(apiKey, baseURL, organization) {
|
|
11
|
+
this.clientParams = {
|
|
12
|
+
apiKey: apiKey,
|
|
13
|
+
baseURL: baseURL,
|
|
14
|
+
organization: organization,
|
|
16
15
|
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Begin Vector Store File functions
|
|
19
|
+
async createVectorStoreFile(parameters) {
|
|
20
|
+
const openai = new OpenAI(this.clientParams);
|
|
21
|
+
const { vector_store_id, ...params } = parameters.msg.payload;
|
|
22
|
+
const response = await openai.beta.vectorStores.files.create(
|
|
23
|
+
vector_store_id,
|
|
24
|
+
params,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async listVectorStoreFiles(parameters) {
|
|
31
|
+
/* Returns a list of vector store files. */
|
|
17
32
|
|
|
18
|
-
const openai = new OpenAI(clientParams);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
const openai = new OpenAI(this.clientParams);
|
|
34
|
+
const { vector_store_id, ...params } = parameters.msg.payload;
|
|
35
|
+
const list = await openai.beta.vectorStores.files.list(
|
|
36
|
+
vector_store_id,
|
|
37
|
+
params,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return [...list.data];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async retrieveVectorStoreFile(parameters) {
|
|
44
|
+
/* Retrieves a vector store file. */
|
|
45
|
+
|
|
46
|
+
const openai = new OpenAI(this.clientParams);
|
|
47
|
+
const { vector_store_id, file_id } = parameters.msg.payload;
|
|
48
|
+
const response = openai.beta.vectorStores.files.retrieve(
|
|
49
|
+
vector_store_id,
|
|
50
|
+
file_id,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return response;
|
|
54
|
+
}
|
|
22
55
|
|
|
23
|
-
|
|
24
|
-
|
|
56
|
+
async deleteVectorStoreFile(parameters) {
|
|
57
|
+
/* Removes a file from the vector store. */
|
|
58
|
+
|
|
59
|
+
const openai = new OpenAI(this.clientParams);
|
|
60
|
+
const { vector_store_id, file_id, ...params } = parameters.msg.payload;
|
|
61
|
+
const response = openai.beta.vectorStores.files.del(
|
|
62
|
+
vector_store_id,
|
|
63
|
+
file_id,
|
|
64
|
+
params,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return response;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// End Vector Store File functions
|
|
71
|
+
|
|
72
|
+
async createVectorStoreFileBatch(parameters) {
|
|
73
|
+
const openai = new OpenAI(this.clientParams);
|
|
74
|
+
const { vector_store_id, ...params } = parameters.msg.payload;
|
|
75
|
+
const response = await openai.beta.vectorStores.fileBatches.create(
|
|
76
|
+
vector_store_id,
|
|
77
|
+
params,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return response;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async retrieveVectorStoreFileBatch(parameters) {
|
|
84
|
+
const openai = new OpenAI(this.clientParams);
|
|
85
|
+
const { vector_store_id, batch_id, ...params } = parameters.msg.payload;
|
|
86
|
+
const response = await openai.beta.vectorStores.fileBatches.retrieve(
|
|
87
|
+
vector_store_id,
|
|
88
|
+
batch_id,
|
|
89
|
+
params,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return response;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async cancelVectorStoreFileBatch(parameters) {
|
|
96
|
+
const openai = new OpenAI(this.clientParams);
|
|
97
|
+
const { vector_store_id, batch_id, ...params } = parameters.msg.payload;
|
|
98
|
+
const response = await openai.beta.vectorStores.fileBatches.retrieve(
|
|
99
|
+
vector_store_id,
|
|
100
|
+
batch_id,
|
|
101
|
+
params,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return response;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async listVectorStoreBatchFiles(parameters) {
|
|
108
|
+
const openai = new OpenAI(this.clientParams);
|
|
109
|
+
const { vector_store_id, batch_id, ...params } = parameters.msg.payload;
|
|
110
|
+
const list = await openai.beta.vectorStores.fileBatches.listFiles(
|
|
111
|
+
vector_store_id,
|
|
112
|
+
batch_id,
|
|
113
|
+
params,
|
|
114
|
+
);
|
|
115
|
+
const batchFiles = [...list.data];
|
|
116
|
+
|
|
117
|
+
return batchFiles;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async createVectorStore(parameters) {
|
|
121
|
+
const openai = new OpenAI(this.clientParams);
|
|
122
|
+
const response = await openai.beta.vectorStores.create(
|
|
123
|
+
parameters.msg.payload,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async listVectorStores(parameters) {
|
|
130
|
+
const openai = new OpenAI(this.clientParams);
|
|
131
|
+
const list = await openai.beta.vectorStores.list(parameters.msg.payload);
|
|
132
|
+
const vectorStores = [...list.data];
|
|
133
|
+
|
|
134
|
+
return vectorStores;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async retrieveVectorStore(parameters) {
|
|
138
|
+
const openai = new OpenAI(this.clientParams);
|
|
139
|
+
const { vector_store_id, ...params } = parameters.msg.payload;
|
|
140
|
+
const response = await openai.beta.vectorStores.retrieve(
|
|
141
|
+
vector_store_id,
|
|
142
|
+
params,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
return response;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async modifyVectorStore(parameters) {
|
|
149
|
+
const openai = new OpenAI(this.clientParams);
|
|
150
|
+
const { vector_store_id, ...params } = parameters.msg.payload;
|
|
151
|
+
const response = await openai.beta.vectorStores.update(
|
|
152
|
+
vector_store_id,
|
|
153
|
+
params,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
return response;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async deleteVectorStore(parameters) {
|
|
160
|
+
const openai = new OpenAI(this.clientParams);
|
|
161
|
+
const { vector_store_id, ...params } = parameters.msg.payload;
|
|
162
|
+
const response = await openai.beta.vectorStores.del(
|
|
163
|
+
vector_store_id,
|
|
164
|
+
params,
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
return response;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async createBatch(parameters) {
|
|
171
|
+
const openai = new OpenAI(this.clientParams);
|
|
172
|
+
const response = await openai.batches.create(parameters.msg.payload);
|
|
173
|
+
|
|
174
|
+
return response;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async retrieveBatch(parameters) {
|
|
178
|
+
const openai = new OpenAI(this.clientParams);
|
|
179
|
+
const { batch_id, ...params } = parameters.msg.payload;
|
|
180
|
+
const response = await openai.batches.retrieve(batch_id, params);
|
|
181
|
+
|
|
182
|
+
return response;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async listBatch(parameters) {
|
|
186
|
+
const openai = new OpenAI(this.clientParams);
|
|
187
|
+
const list = await openai.batches.list(parameters.msg.payload);
|
|
188
|
+
const batches = [...list.data];
|
|
189
|
+
|
|
190
|
+
return batches;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async cancelBatch(parameters) {
|
|
194
|
+
const openai = new OpenAI(this.clientParams);
|
|
195
|
+
const { batch_id, ...params } = parameters.msg.payload;
|
|
196
|
+
const response = await openai.batches.cancel(batch_id, params);
|
|
197
|
+
|
|
198
|
+
return response;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async createChatCompletion(parameters) {
|
|
202
|
+
const { _node, ...params } = parameters;
|
|
203
|
+
const openai = new OpenAI(this.clientParams);
|
|
204
|
+
const response = await openai.chat.completions.create(params.msg.payload);
|
|
205
|
+
|
|
206
|
+
if (params.msg.payload.stream) {
|
|
207
|
+
_node.status({
|
|
25
208
|
fill: "green",
|
|
26
209
|
shape: "dot",
|
|
27
210
|
text: "OpenaiApi.status.streaming",
|
|
28
211
|
});
|
|
29
212
|
for await (const chunk of response) {
|
|
30
213
|
if (typeof chunk === "object") {
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
|
|
214
|
+
let { _msgid, ...newMsg } = parameters.msg;
|
|
215
|
+
newMsg.payload = chunk;
|
|
216
|
+
|
|
217
|
+
_node.send(newMsg);
|
|
34
218
|
}
|
|
35
219
|
}
|
|
36
|
-
|
|
220
|
+
_node.status({});
|
|
37
221
|
} else {
|
|
38
222
|
return response;
|
|
39
223
|
}
|
|
40
224
|
}
|
|
41
225
|
|
|
42
226
|
async createImage(parameters) {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
baseURL: parameters.apiBase,
|
|
46
|
-
organization: parameters.organization,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const openai = new OpenAI(clientParams);
|
|
50
|
-
const response = await openai.images.generate({
|
|
51
|
-
...parameters.msg.payload,
|
|
52
|
-
});
|
|
227
|
+
const openai = new OpenAI(this.clientParams);
|
|
228
|
+
const response = await openai.images.generate(parameters.msg.payload);
|
|
53
229
|
|
|
54
|
-
return response;
|
|
230
|
+
return response.data;
|
|
55
231
|
}
|
|
56
232
|
|
|
57
233
|
async createImageEdit(parameters) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
baseURL: parameters.apiBase,
|
|
61
|
-
organization: parameters.organization,
|
|
62
|
-
};
|
|
63
|
-
const openai = new OpenAI(clientParams);
|
|
234
|
+
const openai = new OpenAI(this.clientParams);
|
|
235
|
+
let { image, mask, ...params } = parameters.msg.payload;
|
|
64
236
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (parameters.msg.payload.mask) {
|
|
69
|
-
parameters.msg.payload.mask = fs.createReadStream(
|
|
70
|
-
parameters.msg.payload.mask,
|
|
71
|
-
);
|
|
237
|
+
params.image = fs.createReadStream(image);
|
|
238
|
+
if (mask) {
|
|
239
|
+
params.mask = fs.createReadStream(mask);
|
|
72
240
|
}
|
|
241
|
+
const response = await openai.images.edit(params);
|
|
73
242
|
|
|
74
|
-
|
|
75
|
-
...parameters.msg.payload,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return response;
|
|
243
|
+
return response.data;
|
|
79
244
|
}
|
|
80
245
|
|
|
81
246
|
async createImageVariation(parameters) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
baseURL: parameters.apiBase,
|
|
85
|
-
organization: parameters.organization,
|
|
86
|
-
};
|
|
87
|
-
const openai = new OpenAI(clientParams);
|
|
247
|
+
const openai = new OpenAI(this.clientParams);
|
|
248
|
+
let { image, ...params } = parameters.msg.payload;
|
|
88
249
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
);
|
|
92
|
-
const response = await openai.images.createVariation({
|
|
93
|
-
...parameters.msg.payload,
|
|
94
|
-
});
|
|
250
|
+
params.image = fs.createReadStream(image);
|
|
251
|
+
const response = await openai.images.createVariation(params);
|
|
95
252
|
|
|
96
|
-
return response;
|
|
253
|
+
return response.data;
|
|
97
254
|
}
|
|
98
255
|
|
|
99
256
|
async createEmbedding(parameters) {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
baseURL: parameters.apiBase,
|
|
103
|
-
organization: parameters.organization,
|
|
104
|
-
};
|
|
105
|
-
const openai = new OpenAI(clientParams);
|
|
257
|
+
const openai = new OpenAI(this.clientParams);
|
|
258
|
+
const response = await openai.embeddings.create(parameters.msg.payload);
|
|
106
259
|
|
|
107
|
-
|
|
108
|
-
...parameters.msg.payload,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
return response;
|
|
260
|
+
return response.data;
|
|
112
261
|
}
|
|
113
262
|
|
|
114
263
|
async createSpeech(parameters) {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
baseURL: parameters.apiBase,
|
|
118
|
-
organization: parameters.organization,
|
|
119
|
-
};
|
|
120
|
-
const openai = new OpenAI(clientParams);
|
|
121
|
-
|
|
122
|
-
const audio = await openai.audio.speech.create({
|
|
123
|
-
...parameters.msg.payload,
|
|
124
|
-
});
|
|
264
|
+
const openai = new OpenAI(this.clientParams);
|
|
265
|
+
const audio = await openai.audio.speech.create(parameters.msg.payload);
|
|
125
266
|
const response = Buffer.from(await audio.arrayBuffer());
|
|
126
267
|
|
|
127
268
|
return response;
|
|
128
269
|
}
|
|
129
270
|
|
|
130
271
|
async createTranscription(parameters) {
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
baseURL: parameters.apiBase,
|
|
134
|
-
organization: parameters.organization,
|
|
135
|
-
};
|
|
136
|
-
const openai = new OpenAI(clientParams);
|
|
272
|
+
const openai = new OpenAI(this.clientParams);
|
|
273
|
+
let { file, ...params } = parameters.msg.payload;
|
|
137
274
|
|
|
138
|
-
|
|
139
|
-
parameters.msg.payload.file,
|
|
140
|
-
);
|
|
275
|
+
params.file = fs.createReadStream(file);
|
|
141
276
|
|
|
142
|
-
const response = await openai.audio.transcriptions.create(
|
|
143
|
-
...parameters.msg.payload,
|
|
144
|
-
});
|
|
277
|
+
const response = await openai.audio.transcriptions.create(params);
|
|
145
278
|
|
|
146
279
|
return response;
|
|
147
280
|
}
|
|
148
281
|
|
|
149
282
|
async createTranslation(parameters) {
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
baseURL: parameters.apiBase,
|
|
153
|
-
organization: parameters.organization,
|
|
154
|
-
};
|
|
155
|
-
const openai = new OpenAI(clientParams);
|
|
283
|
+
const openai = new OpenAI(this.clientParams);
|
|
284
|
+
let { file, ...params } = parameters.msg.payload;
|
|
156
285
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
);
|
|
160
|
-
const response = await openai.audio.translations.create({
|
|
161
|
-
...parameters.msg.payload,
|
|
162
|
-
});
|
|
286
|
+
params.file = fs.createReadStream(file);
|
|
287
|
+
|
|
288
|
+
const response = await openai.audio.translations.create(params);
|
|
163
289
|
|
|
164
290
|
return response;
|
|
165
291
|
}
|
|
166
292
|
|
|
167
293
|
async listFiles(parameters) {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
baseURL: parameters.apiBase,
|
|
171
|
-
organization: parameters.organization,
|
|
172
|
-
};
|
|
173
|
-
const openai = new OpenAI(clientParams);
|
|
294
|
+
const openai = new OpenAI(this.clientParams);
|
|
295
|
+
const list = await openai.files.list(parameters.msg.payload);
|
|
174
296
|
|
|
175
|
-
|
|
176
|
-
...parameters.msg.payload,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
let files = [];
|
|
180
|
-
for await (const file of list) {
|
|
181
|
-
files.push(file);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return files;
|
|
297
|
+
return [...list.data];
|
|
185
298
|
}
|
|
186
299
|
|
|
187
300
|
async createFile(parameters) {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
baseURL: parameters.apiBase,
|
|
191
|
-
organization: parameters.organization,
|
|
192
|
-
};
|
|
193
|
-
const openai = new OpenAI(clientParams);
|
|
301
|
+
const openai = new OpenAI(this.clientParams);
|
|
302
|
+
let { file, ...params } = parameters.msg.payload;
|
|
194
303
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
);
|
|
198
|
-
const response = await openai.files.create({
|
|
199
|
-
...parameters.msg.payload,
|
|
200
|
-
});
|
|
304
|
+
params.file = fs.createReadStream(file);
|
|
305
|
+
|
|
306
|
+
const response = await openai.files.create(params);
|
|
201
307
|
|
|
202
308
|
return response;
|
|
203
309
|
}
|
|
204
310
|
|
|
205
311
|
async deleteFile(parameters) {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
organization: parameters.organization,
|
|
210
|
-
};
|
|
211
|
-
const openai = new OpenAI(clientParams);
|
|
212
|
-
|
|
213
|
-
const response = await openai.files.del({
|
|
214
|
-
...parameters.msg.payload,
|
|
215
|
-
});
|
|
312
|
+
const openai = new OpenAI(this.clientParams);
|
|
313
|
+
const { file_id, ...params } = parameters.msg.payload;
|
|
314
|
+
const response = await openai.files.del(file_id, params);
|
|
216
315
|
|
|
217
316
|
return response;
|
|
218
317
|
}
|
|
219
318
|
|
|
220
319
|
async retrieveFile(parameters) {
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
organization: parameters.organization,
|
|
225
|
-
};
|
|
226
|
-
const openai = new OpenAI(clientParams);
|
|
227
|
-
|
|
228
|
-
const file_id = parameters.msg.payload.file_id;
|
|
229
|
-
delete parameters.msg.payload.file_id;
|
|
230
|
-
|
|
231
|
-
const response = await openai.files.retrieve(file_id, {
|
|
232
|
-
...parameters.msg.payload,
|
|
233
|
-
});
|
|
320
|
+
const openai = new OpenAI(this.clientParams);
|
|
321
|
+
const { file_id, ...params } = parameters.msg.payload;
|
|
322
|
+
const response = await openai.files.retrieve(file_id, params);
|
|
234
323
|
|
|
235
324
|
return response;
|
|
236
325
|
}
|
|
237
326
|
|
|
238
327
|
async downloadFile(parameters) {
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
organization: parameters.organization,
|
|
243
|
-
};
|
|
244
|
-
const openai = new OpenAI(clientParams);
|
|
245
|
-
|
|
246
|
-
const file_id = parameters.msg.payload.file_id;
|
|
247
|
-
delete parameters.msg.payload.file_id;
|
|
248
|
-
|
|
249
|
-
const response = await openai.files.retrieveContent(file_id, {
|
|
250
|
-
...parameters.msg.payload,
|
|
251
|
-
});
|
|
328
|
+
const openai = new OpenAI(this.clientParams);
|
|
329
|
+
const { file_id, ...params } = parameters.msg.payload;
|
|
330
|
+
const response = await openai.files.content(file_id, params);
|
|
252
331
|
|
|
253
332
|
return response;
|
|
254
333
|
}
|
|
255
334
|
|
|
256
335
|
async createFineTuningJob(parameters) {
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
};
|
|
262
|
-
const openai = new OpenAI(clientParams);
|
|
263
|
-
|
|
264
|
-
const response = await openai.fineTuning.jobs.create({
|
|
265
|
-
...parameters.msg.payload,
|
|
266
|
-
});
|
|
336
|
+
const openai = new OpenAI(this.clientParams);
|
|
337
|
+
const response = await openai.fineTuning.jobs.create(
|
|
338
|
+
parameters.msg.payload,
|
|
339
|
+
);
|
|
267
340
|
|
|
268
341
|
return response;
|
|
269
342
|
}
|
|
270
343
|
|
|
271
344
|
async listPaginatedFineTuningJobs(parameters) {
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
baseURL: parameters.apiBase,
|
|
275
|
-
organization: parameters.organization,
|
|
276
|
-
};
|
|
277
|
-
const openai = new OpenAI(clientParams);
|
|
278
|
-
|
|
279
|
-
const list = await openai.fineTuning.jobs.list({
|
|
280
|
-
...parameters.msg.payload,
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
let response = [];
|
|
284
|
-
for await (const fineTune of list) {
|
|
285
|
-
response.push(fineTune);
|
|
286
|
-
}
|
|
345
|
+
const openai = new OpenAI(this.clientParams);
|
|
346
|
+
const list = await openai.fineTuning.jobs.list(parameters.msg.payload);
|
|
287
347
|
|
|
288
|
-
return
|
|
348
|
+
return [...list.data];
|
|
289
349
|
}
|
|
290
350
|
|
|
291
351
|
async retrieveFineTuningJob(parameters) {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
baseURL: parameters.apiBase,
|
|
295
|
-
organization: parameters.organization,
|
|
296
|
-
};
|
|
297
|
-
const openai = new OpenAI(clientParams);
|
|
298
|
-
|
|
352
|
+
const openai = new OpenAI(this.clientParams);
|
|
353
|
+
const { fine_tuning_job_id, ...params } = parameters.msg.payload;
|
|
299
354
|
const response = await openai.fineTuning.jobs.retrieve(
|
|
300
|
-
|
|
355
|
+
fine_tuning_job_id,
|
|
356
|
+
params,
|
|
301
357
|
);
|
|
302
358
|
|
|
303
359
|
return response;
|
|
304
360
|
}
|
|
305
361
|
|
|
306
362
|
async listFineTuningEvents(parameters) {
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
baseURL: parameters.apiBase,
|
|
310
|
-
organization: parameters.organization,
|
|
311
|
-
};
|
|
312
|
-
const openai = new OpenAI(clientParams);
|
|
313
|
-
|
|
314
|
-
let response = [];
|
|
363
|
+
const openai = new OpenAI(this.clientParams);
|
|
364
|
+
const { fine_tuning_job_id, ...params } = parameters.msg.payload;
|
|
315
365
|
const list = await openai.fineTuning.jobs.listEvents(
|
|
316
|
-
|
|
366
|
+
fine_tuning_job_id,
|
|
367
|
+
params,
|
|
317
368
|
);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
return response;
|
|
369
|
+
|
|
370
|
+
return [...list.data];
|
|
322
371
|
}
|
|
323
372
|
|
|
324
373
|
async cancelFineTuningJob(parameters) {
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
baseURL: parameters.apiBase,
|
|
328
|
-
organization: parameters.organization,
|
|
329
|
-
};
|
|
330
|
-
const openai = new OpenAI(clientParams);
|
|
331
|
-
|
|
374
|
+
const openai = new OpenAI(this.clientParams);
|
|
375
|
+
const { fine_tuning_job_id, ...params } = parameters.msg.payload;
|
|
332
376
|
const response = await openai.fineTuning.jobs.cancel(
|
|
333
|
-
|
|
377
|
+
fine_tuning_job_id,
|
|
378
|
+
params,
|
|
334
379
|
);
|
|
335
380
|
|
|
336
381
|
return response;
|
|
337
382
|
}
|
|
338
383
|
|
|
339
384
|
async listModels(parameters) {
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
baseURL: parameters.apiBase,
|
|
343
|
-
organization: parameters.organization,
|
|
344
|
-
};
|
|
345
|
-
const openai = new OpenAI(clientParams);
|
|
346
|
-
|
|
347
|
-
const response = await openai.models.list();
|
|
385
|
+
const openai = new OpenAI(this.clientParams);
|
|
386
|
+
const list = await openai.models.list();
|
|
348
387
|
|
|
349
|
-
return
|
|
388
|
+
return [...list.data];
|
|
350
389
|
}
|
|
351
390
|
|
|
352
391
|
async retrieveModel(parameters) {
|
|
353
|
-
const
|
|
354
|
-
apiKey: parameters.apiKey,
|
|
355
|
-
baseURL: parameters.apiBase,
|
|
356
|
-
organization: parameters.organization,
|
|
357
|
-
};
|
|
358
|
-
const openai = new OpenAI(clientParams);
|
|
359
|
-
|
|
392
|
+
const openai = new OpenAI(this.clientParams);
|
|
360
393
|
const model = parameters.msg.payload.model;
|
|
361
394
|
const response = await openai.models.retrieve(model);
|
|
362
395
|
|
|
@@ -364,13 +397,7 @@ let OpenaiApi = (function () {
|
|
|
364
397
|
}
|
|
365
398
|
|
|
366
399
|
async deleteModel(parameters) {
|
|
367
|
-
const
|
|
368
|
-
apiKey: parameters.apiKey,
|
|
369
|
-
baseURL: parameters.apiBase,
|
|
370
|
-
organization: parameters.organization,
|
|
371
|
-
};
|
|
372
|
-
const openai = new OpenAI(clientParams);
|
|
373
|
-
|
|
400
|
+
const openai = new OpenAI(this.clientParams);
|
|
374
401
|
const model = parameters.msg.payload.model;
|
|
375
402
|
const response = await openai.models.del(model);
|
|
376
403
|
|
|
@@ -378,549 +405,277 @@ let OpenaiApi = (function () {
|
|
|
378
405
|
}
|
|
379
406
|
|
|
380
407
|
async createModeration(parameters) {
|
|
381
|
-
const
|
|
382
|
-
apiKey: parameters.apiKey,
|
|
383
|
-
baseURL: parameters.apiBase,
|
|
384
|
-
organization: parameters.organization,
|
|
385
|
-
};
|
|
386
|
-
const openai = new OpenAI(clientParams);
|
|
387
|
-
|
|
408
|
+
const openai = new OpenAI(this.clientParams);
|
|
388
409
|
const response = await openai.moderations.create(parameters.msg.payload);
|
|
389
410
|
return response;
|
|
390
411
|
}
|
|
391
412
|
|
|
392
413
|
async listAssistants(parameters) {
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
baseURL: parameters.apiBase,
|
|
396
|
-
organization: parameters.organization,
|
|
397
|
-
};
|
|
398
|
-
const openai = new OpenAI(clientParams);
|
|
414
|
+
const openai = new OpenAI(this.clientParams);
|
|
415
|
+
const list = await openai.beta.assistants.list(parameters.msg.payload);
|
|
399
416
|
|
|
400
|
-
|
|
401
|
-
...parameters.msg.payload,
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
return response.body;
|
|
417
|
+
return [...list.data];
|
|
405
418
|
}
|
|
406
419
|
|
|
407
420
|
async createAssistant(parameters) {
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
};
|
|
413
|
-
const openai = new OpenAI(clientParams);
|
|
414
|
-
|
|
415
|
-
const response = await openai.beta.assistants.create({
|
|
416
|
-
...parameters.msg.payload,
|
|
417
|
-
});
|
|
421
|
+
const openai = new OpenAI(this.clientParams);
|
|
422
|
+
const response = await openai.beta.assistants.create(
|
|
423
|
+
parameters.msg.payload,
|
|
424
|
+
);
|
|
418
425
|
|
|
419
426
|
return response;
|
|
420
427
|
}
|
|
421
428
|
|
|
422
429
|
async getAssistant(parameters) {
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const id = parameters.msg.payload.assistant_id;
|
|
431
|
-
const response = await openai.beta.assistants.retrieve(id);
|
|
430
|
+
const openai = new OpenAI(this.clientParams);
|
|
431
|
+
const { assistant_id, ...params } = parameters.msg.payload;
|
|
432
|
+
const response = await openai.beta.assistants.retrieve(
|
|
433
|
+
assistant_id,
|
|
434
|
+
params,
|
|
435
|
+
);
|
|
432
436
|
|
|
433
437
|
return response;
|
|
434
438
|
}
|
|
435
439
|
|
|
436
440
|
async modifyAssistant(parameters) {
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const id = parameters.msg.payload.assistant_id;
|
|
445
|
-
delete parameters.msg.payload.assistant_id;
|
|
446
|
-
|
|
447
|
-
const response = await openai.beta.assistants.update(id, {
|
|
448
|
-
...parameters.msg.payload,
|
|
449
|
-
});
|
|
441
|
+
const openai = new OpenAI(this.clientParams);
|
|
442
|
+
const { assistant_id, ...params } = parameters.msg.payload;
|
|
443
|
+
const response = await openai.beta.assistants.update(
|
|
444
|
+
assistant_id,
|
|
445
|
+
params,
|
|
446
|
+
);
|
|
450
447
|
|
|
451
448
|
return response;
|
|
452
449
|
}
|
|
453
450
|
|
|
454
451
|
async deleteAssistant(parameters) {
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
organization: parameters.organization,
|
|
459
|
-
};
|
|
460
|
-
const openai = new OpenAI(clientParams);
|
|
461
|
-
|
|
462
|
-
const id = parameters.msg.payload.assistant_id;
|
|
463
|
-
const response = await openai.beta.assistants.del(id);
|
|
452
|
+
const openai = new OpenAI(this.clientParams);
|
|
453
|
+
const { assistant_id, ...params } = parameters.msg.payload;
|
|
454
|
+
const response = await openai.beta.assistants.del(assistant_id, params);
|
|
464
455
|
|
|
465
456
|
return response;
|
|
466
457
|
}
|
|
467
458
|
|
|
468
459
|
async createThread(parameters) {
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
baseURL: parameters.apiBase,
|
|
472
|
-
organization: parameters.organization,
|
|
473
|
-
};
|
|
474
|
-
const openai = new OpenAI(clientParams);
|
|
475
|
-
|
|
476
|
-
const response = await openai.beta.threads.create({
|
|
477
|
-
...parameters.msg.payload,
|
|
478
|
-
});
|
|
460
|
+
const openai = new OpenAI(this.clientParams);
|
|
461
|
+
const response = await openai.beta.threads.create(parameters.msg.payload);
|
|
479
462
|
|
|
480
463
|
return response;
|
|
481
464
|
}
|
|
482
465
|
|
|
483
466
|
async getThread(parameters) {
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
organization: parameters.organization,
|
|
488
|
-
};
|
|
489
|
-
const openai = new OpenAI(clientParams);
|
|
490
|
-
|
|
491
|
-
const id = parameters.msg.payload.thread_id;
|
|
492
|
-
const response = await openai.beta.threads.retrieve(id);
|
|
467
|
+
const openai = new OpenAI(this.clientParams);
|
|
468
|
+
const { thread_id, ...params } = parameters.msg.payload;
|
|
469
|
+
const response = await openai.beta.threads.retrieve(thread_id, params);
|
|
493
470
|
|
|
494
471
|
return response;
|
|
495
472
|
}
|
|
496
473
|
|
|
497
474
|
async modifyThread(parameters) {
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
organization: parameters.organization,
|
|
502
|
-
};
|
|
503
|
-
const openai = new OpenAI(clientParams);
|
|
504
|
-
|
|
505
|
-
const id = parameters.msg.payload.thread_id;
|
|
506
|
-
delete parameters.msg.payload.thread_id;
|
|
507
|
-
|
|
508
|
-
const response = await openai.beta.threads.update(id, {
|
|
509
|
-
...parameters.msg.payload,
|
|
510
|
-
});
|
|
475
|
+
const openai = new OpenAI(this.clientParams);
|
|
476
|
+
const { thread_id, ...params } = parameters.msg.payload;
|
|
477
|
+
const response = await openai.beta.threads.update(thread_id, params);
|
|
511
478
|
|
|
512
479
|
return response;
|
|
513
480
|
}
|
|
514
481
|
|
|
515
482
|
async deleteThread(parameters) {
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
organization: parameters.organization,
|
|
520
|
-
};
|
|
521
|
-
const openai = new OpenAI(clientParams);
|
|
522
|
-
|
|
523
|
-
const id = parameters.msg.payload.thread_id;
|
|
524
|
-
const response = await openai.beta.threads.del(id);
|
|
483
|
+
const openai = new OpenAI(this.clientParams);
|
|
484
|
+
const { thread_id, ...params } = parameters.msg.payload;
|
|
485
|
+
const response = await openai.beta.threads.del(thread_id, params);
|
|
525
486
|
|
|
526
487
|
return response;
|
|
527
488
|
}
|
|
528
489
|
|
|
529
490
|
async listMessages(parameters) {
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
organization: parameters.organization,
|
|
534
|
-
};
|
|
535
|
-
const openai = new OpenAI(clientParams);
|
|
536
|
-
|
|
537
|
-
const id = parameters.msg.payload.thread_id;
|
|
538
|
-
const response = await openai.beta.threads.messages.list(id);
|
|
491
|
+
const openai = new OpenAI(this.clientParams);
|
|
492
|
+
const { thread_id, ...params } = parameters.msg.payload;
|
|
493
|
+
const list = await openai.beta.threads.messages.list(thread_id, params);
|
|
539
494
|
|
|
540
|
-
return
|
|
495
|
+
return [...list.data];
|
|
541
496
|
}
|
|
542
497
|
|
|
543
498
|
async createMessage(parameters) {
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
552
|
-
delete parameters.msg.payload.thread_id;
|
|
553
|
-
|
|
554
|
-
const response = await openai.beta.threads.messages.create(thread_id, {
|
|
555
|
-
...parameters.msg.payload,
|
|
556
|
-
});
|
|
499
|
+
const openai = new OpenAI(this.clientParams);
|
|
500
|
+
const { thread_id, ...params } = parameters.msg.payload;
|
|
501
|
+
const response = await openai.beta.threads.messages.create(
|
|
502
|
+
thread_id,
|
|
503
|
+
params,
|
|
504
|
+
);
|
|
557
505
|
|
|
558
506
|
return response;
|
|
559
507
|
}
|
|
560
508
|
|
|
561
509
|
async getMessage(parameters) {
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
baseURL: parameters.apiBase,
|
|
565
|
-
organization: parameters.organization,
|
|
566
|
-
};
|
|
567
|
-
const openai = new OpenAI(clientParams);
|
|
568
|
-
|
|
569
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
570
|
-
const message_id = parameters.msg.payload.message_id;
|
|
571
|
-
|
|
510
|
+
const openai = new OpenAI(this.clientParams);
|
|
511
|
+
const { thread_id, message_id, ...params } = parameters.msg.payload;
|
|
572
512
|
const response = await openai.beta.threads.messages.retrieve(
|
|
573
513
|
thread_id,
|
|
574
514
|
message_id,
|
|
515
|
+
params,
|
|
575
516
|
);
|
|
576
517
|
|
|
577
518
|
return response;
|
|
578
519
|
}
|
|
579
520
|
|
|
580
521
|
async modifyMessage(parameters) {
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
baseURL: parameters.apiBase,
|
|
584
|
-
organization: parameters.organization,
|
|
585
|
-
};
|
|
586
|
-
const openai = new OpenAI(clientParams);
|
|
587
|
-
|
|
588
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
589
|
-
const message_id = parameters.msg.payload.message_id;
|
|
590
|
-
delete parameters.msg.payload.thread_id;
|
|
591
|
-
delete parameters.msg.payload.message_id;
|
|
592
|
-
|
|
522
|
+
const openai = new OpenAI(this.clientParams);
|
|
523
|
+
const { thread_id, message_id, ...params } = parameters.msg.payload;
|
|
593
524
|
const response = await openai.beta.threads.messages.update(
|
|
594
525
|
thread_id,
|
|
595
526
|
message_id,
|
|
596
|
-
|
|
597
|
-
...parameters.msg.payload,
|
|
598
|
-
},
|
|
527
|
+
params,
|
|
599
528
|
);
|
|
600
529
|
|
|
601
530
|
return response;
|
|
602
531
|
}
|
|
603
532
|
|
|
604
533
|
async createThreadAndRun(parameters) {
|
|
605
|
-
const
|
|
606
|
-
apiKey: parameters.apiKey,
|
|
607
|
-
baseURL: parameters.apiBase,
|
|
608
|
-
organization: parameters.organization,
|
|
609
|
-
};
|
|
610
|
-
const openai = new OpenAI(clientParams);
|
|
534
|
+
const openai = new OpenAI(this.clientParams);
|
|
611
535
|
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
536
|
+
const { _node, ...params } = parameters;
|
|
537
|
+
const response = await openai.beta.threads.createAndRun(
|
|
538
|
+
params.msg.payload,
|
|
539
|
+
);
|
|
615
540
|
|
|
616
|
-
|
|
541
|
+
if (params.msg.payload.stream) {
|
|
542
|
+
_node.status({
|
|
543
|
+
fill: "green",
|
|
544
|
+
shape: "dot",
|
|
545
|
+
text: "OpenaiApi.status.streaming",
|
|
546
|
+
});
|
|
547
|
+
for await (const chunk of response) {
|
|
548
|
+
if (typeof chunk === "object") {
|
|
549
|
+
let { _msgid, ...newMsg } = parameters.msg;
|
|
550
|
+
newMsg.payload = chunk.data;
|
|
551
|
+
|
|
552
|
+
_node.send(newMsg);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
_node.status({});
|
|
556
|
+
} else {
|
|
557
|
+
return response;
|
|
558
|
+
}
|
|
617
559
|
}
|
|
618
560
|
|
|
619
561
|
async listRuns(parameters) {
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
organization: parameters.organization,
|
|
624
|
-
};
|
|
625
|
-
const openai = new OpenAI(clientParams);
|
|
626
|
-
|
|
627
|
-
const thred_id = parameters.msg.payload.thread_id;
|
|
628
|
-
delete parameters.msg.payload.thread_id;
|
|
629
|
-
|
|
630
|
-
const response = await openai.beta.threads.runs.list(thred_id, {
|
|
631
|
-
...parameters.msg.payload,
|
|
632
|
-
});
|
|
562
|
+
const openai = new OpenAI(this.clientParams);
|
|
563
|
+
const { thread_id, ...params } = parameters.msg.payload;
|
|
564
|
+
const list = await openai.beta.threads.runs.list(thread_id, params);
|
|
633
565
|
|
|
634
|
-
return
|
|
566
|
+
return [...list.data];
|
|
635
567
|
}
|
|
636
568
|
|
|
637
569
|
async createRun(parameters) {
|
|
638
|
-
const
|
|
639
|
-
apiKey: parameters.apiKey,
|
|
640
|
-
baseURL: parameters.apiBase,
|
|
641
|
-
organization: parameters.organization,
|
|
642
|
-
};
|
|
643
|
-
const openai = new OpenAI(clientParams);
|
|
570
|
+
const openai = new OpenAI(this.clientParams);
|
|
644
571
|
|
|
645
|
-
const
|
|
646
|
-
|
|
572
|
+
const { _node, ..._params } = parameters;
|
|
573
|
+
const { thread_id, ...params } = _params.msg.payload;
|
|
574
|
+
const response = await openai.beta.threads.runs.create(thread_id, params);
|
|
647
575
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
576
|
+
if (params.stream) {
|
|
577
|
+
_node.status({
|
|
578
|
+
fill: "green",
|
|
579
|
+
shape: "dot",
|
|
580
|
+
text: "OpenaiApi.status.streaming",
|
|
581
|
+
});
|
|
582
|
+
for await (const chunk of response) {
|
|
583
|
+
if (typeof chunk === "object") {
|
|
584
|
+
let { _msgid, ...newMsg } = parameters.msg;
|
|
585
|
+
newMsg.payload = chunk.data;
|
|
651
586
|
|
|
652
|
-
|
|
587
|
+
_node.send(newMsg);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
_node.status({});
|
|
591
|
+
} else {
|
|
592
|
+
return response;
|
|
593
|
+
}
|
|
653
594
|
}
|
|
654
595
|
|
|
655
596
|
async getRun(parameters) {
|
|
656
|
-
const
|
|
657
|
-
|
|
658
|
-
baseURL: parameters.apiBase,
|
|
659
|
-
organization: parameters.organization,
|
|
660
|
-
};
|
|
661
|
-
const openai = new OpenAI(clientParams);
|
|
662
|
-
|
|
663
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
664
|
-
const run_id = parameters.msg.payload.run_id;
|
|
665
|
-
delete parameters.msg.payload.thread_id;
|
|
666
|
-
delete parameters.msg.payload.run_id;
|
|
667
|
-
|
|
597
|
+
const openai = new OpenAI(this.clientParams);
|
|
598
|
+
const { thread_id, run_id, ...params } = parameters.msg.payload;
|
|
668
599
|
const response = await openai.beta.threads.runs.retrieve(
|
|
669
600
|
thread_id,
|
|
670
601
|
run_id,
|
|
602
|
+
params,
|
|
671
603
|
);
|
|
672
604
|
|
|
673
605
|
return response;
|
|
674
606
|
}
|
|
675
607
|
|
|
676
608
|
async modifyRun(parameters) {
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
baseURL: parameters.apiBase,
|
|
680
|
-
organization: parameters.organization,
|
|
681
|
-
};
|
|
682
|
-
const openai = new OpenAI(clientParams);
|
|
683
|
-
|
|
684
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
685
|
-
const run_id = parameters.msg.payload.run_id;
|
|
686
|
-
delete parameters.msg.payload.thread_id;
|
|
687
|
-
delete parameters.msg.payload.run_id;
|
|
688
|
-
|
|
609
|
+
const openai = new OpenAI(this.clientParams);
|
|
610
|
+
const { thread_id, run_id, ...params } = parameters.msg.payload;
|
|
689
611
|
const response = await openai.beta.threads.runs.update(
|
|
690
612
|
thread_id,
|
|
691
613
|
run_id,
|
|
692
|
-
|
|
693
|
-
...parameters.msg.payload,
|
|
694
|
-
},
|
|
614
|
+
params,
|
|
695
615
|
);
|
|
696
616
|
|
|
697
617
|
return response;
|
|
698
618
|
}
|
|
699
619
|
|
|
700
|
-
async
|
|
701
|
-
const
|
|
702
|
-
apiKey: parameters.apiKey,
|
|
703
|
-
baseURL: parameters.apiBase,
|
|
704
|
-
organization: parameters.organization,
|
|
705
|
-
};
|
|
706
|
-
const openai = new OpenAI(clientParams);
|
|
707
|
-
|
|
708
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
709
|
-
const run_id = parameters.msg.payload.run_id;
|
|
710
|
-
delete parameters.msg.payload.thread_id;
|
|
711
|
-
delete parameters.msg.payload.run_id;
|
|
620
|
+
async submitToolOutputsToRun(parameters) {
|
|
621
|
+
const openai = new OpenAI(this.clientParams);
|
|
712
622
|
|
|
623
|
+
const {_node, ..._params} = parameters;
|
|
624
|
+
const { thread_id, run_id, ...params } = _params.msg.payload;
|
|
713
625
|
const response = await openai.beta.threads.runs.submitToolOutputs(
|
|
714
626
|
thread_id,
|
|
715
627
|
run_id,
|
|
716
|
-
|
|
717
|
-
...parameters.msg.payload,
|
|
718
|
-
},
|
|
628
|
+
params,
|
|
719
629
|
);
|
|
720
630
|
|
|
721
|
-
|
|
631
|
+
if (params.stream) {
|
|
632
|
+
_node.status({
|
|
633
|
+
fill: "green",
|
|
634
|
+
shape: "dot",
|
|
635
|
+
text: "OpenaiApi.status.streaming",
|
|
636
|
+
});
|
|
637
|
+
for await (const chunk of response) {
|
|
638
|
+
if (typeof chunk === "object") {
|
|
639
|
+
let { _msgid, ...newMsg } = parameters.msg;
|
|
640
|
+
newMsg.payload = chunk.data;
|
|
641
|
+
|
|
642
|
+
_node.send(newMsg);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
_node.status({});
|
|
646
|
+
} else {
|
|
647
|
+
return response;
|
|
648
|
+
}
|
|
722
649
|
}
|
|
723
650
|
|
|
724
651
|
async cancelRun(parameters) {
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
baseURL: parameters.apiBase,
|
|
728
|
-
organization: parameters.organization,
|
|
729
|
-
};
|
|
730
|
-
const openai = new OpenAI(clientParams);
|
|
731
|
-
|
|
732
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
733
|
-
const run_id = parameters.msg.payload.run_id;
|
|
734
|
-
delete parameters.msg.payload.thread_id;
|
|
735
|
-
delete parameters.msg.payload.run_id;
|
|
736
|
-
|
|
652
|
+
const openai = new OpenAI(this.clientParams);
|
|
653
|
+
const { thread_id, run_id, ...params } = parameters.msg.payload;
|
|
737
654
|
const response = await openai.beta.threads.runs.cancel(
|
|
738
655
|
thread_id,
|
|
739
656
|
run_id,
|
|
740
|
-
|
|
741
|
-
...parameters.msg.payload,
|
|
742
|
-
},
|
|
657
|
+
params,
|
|
743
658
|
);
|
|
744
659
|
|
|
745
660
|
return response;
|
|
746
661
|
}
|
|
747
662
|
|
|
748
663
|
async listRunSteps(parameters) {
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
organization: parameters.organization,
|
|
753
|
-
};
|
|
754
|
-
const openai = new OpenAI(clientParams);
|
|
664
|
+
const openai = new OpenAI(this.clientParams);
|
|
665
|
+
const { thread_id, run_id, ...params } = parameters.msg.payload;
|
|
666
|
+
const list = await openai.beta.threads.runs.steps.list(run_id, params);
|
|
755
667
|
|
|
756
|
-
|
|
757
|
-
const run_id = parameters.msg.payload.run_id;
|
|
758
|
-
delete parameters.msg.payload.thread_id;
|
|
759
|
-
delete parameters.msg.payload.run_id;
|
|
760
|
-
|
|
761
|
-
const response = await openai.beta.threads.runs.steps.list(
|
|
762
|
-
thread_id,
|
|
763
|
-
run_id,
|
|
764
|
-
{
|
|
765
|
-
...parameters.msg.payload,
|
|
766
|
-
},
|
|
767
|
-
);
|
|
768
|
-
|
|
769
|
-
return response.body;
|
|
668
|
+
return [...list.data];
|
|
770
669
|
}
|
|
771
670
|
|
|
772
671
|
async getRunStep(parameters) {
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
baseURL: parameters.apiBase,
|
|
776
|
-
organization: parameters.organization,
|
|
777
|
-
};
|
|
778
|
-
const openai = new OpenAI(clientParams);
|
|
779
|
-
|
|
780
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
781
|
-
const run_id = parameters.msg.payload.run_id;
|
|
782
|
-
const step_id = parameters.msg.payload.step_id;
|
|
783
|
-
|
|
672
|
+
const openai = new OpenAI(this.clientParams);
|
|
673
|
+
const { thread_id, run_id, step_id, ...params } = parameters.msg.payload;
|
|
784
674
|
const response = await openai.beta.threads.runs.steps.retrieve(
|
|
785
675
|
thread_id,
|
|
786
676
|
run_id,
|
|
787
677
|
step_id,
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
return response;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
async listAssistantFiles(parameters) {
|
|
794
|
-
const clientParams = {
|
|
795
|
-
apiKey: parameters.apiKey,
|
|
796
|
-
baseURL: parameters.apiBase,
|
|
797
|
-
organization: parameters.organization,
|
|
798
|
-
};
|
|
799
|
-
const openai = new OpenAI(clientParams);
|
|
800
|
-
|
|
801
|
-
const assistant_id = parameters.msg.payload.assistant_id;
|
|
802
|
-
delete parameters.msg.payload.assistant_id;
|
|
803
|
-
|
|
804
|
-
const response = await openai.beta.assistants.files.list(assistant_id, {
|
|
805
|
-
...parameters.msg.payload,
|
|
806
|
-
});
|
|
807
|
-
|
|
808
|
-
return response.body;
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
async createAssistantFile(parameters) {
|
|
812
|
-
const clientParams = {
|
|
813
|
-
apiKey: parameters.apiKey,
|
|
814
|
-
baseURL: parameters.apiBase,
|
|
815
|
-
organization: parameters.organization,
|
|
816
|
-
};
|
|
817
|
-
const openai = new OpenAI(clientParams);
|
|
818
|
-
|
|
819
|
-
const assistant_id = parameters.msg.payload.assistant_id;
|
|
820
|
-
delete parameters.msg.payload.assistant_id;
|
|
821
|
-
|
|
822
|
-
const response = await openai.beta.assistants.files.create(assistant_id, {
|
|
823
|
-
...parameters.msg.payload,
|
|
824
|
-
});
|
|
825
|
-
|
|
826
|
-
return response;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
async getAssistantFile(parameters) {
|
|
830
|
-
const clientParams = {
|
|
831
|
-
apiKey: parameters.apiKey,
|
|
832
|
-
baseURL: parameters.apiBase,
|
|
833
|
-
organization: parameters.organization,
|
|
834
|
-
};
|
|
835
|
-
const openai = new OpenAI(clientParams);
|
|
836
|
-
|
|
837
|
-
const assistant_id = parameters.msg.payload.assistant_id;
|
|
838
|
-
const file_id = parameters.msg.payload.file_id;
|
|
839
|
-
delete parameters.msg.payload.assistant_id;
|
|
840
|
-
delete parameters.msg.payload.file_id;
|
|
841
|
-
|
|
842
|
-
const response = await openai.beta.assistants.files.retrieve(
|
|
843
|
-
assistant_id,
|
|
844
|
-
file_id,
|
|
845
|
-
{
|
|
846
|
-
...parameters.msg.payload,
|
|
847
|
-
},
|
|
848
|
-
);
|
|
849
|
-
|
|
850
|
-
return response;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
async deleteAssistantFile(parameters) {
|
|
854
|
-
const clientParams = {
|
|
855
|
-
apiKey: parameters.apiKey,
|
|
856
|
-
baseURL: parameters.apiBase,
|
|
857
|
-
organization: parameters.organization,
|
|
858
|
-
};
|
|
859
|
-
const openai = new OpenAI(clientParams);
|
|
860
|
-
|
|
861
|
-
const assistant_id = parameters.msg.payload.assistant_id;
|
|
862
|
-
const file_id = parameters.msg.payload.file_id;
|
|
863
|
-
delete parameters.msg.payload.assistant_id;
|
|
864
|
-
delete parameters.msg.payload.file_id;
|
|
865
|
-
|
|
866
|
-
const response = await openai.beta.assistants.files.del(
|
|
867
|
-
assistant_id,
|
|
868
|
-
file_id,
|
|
869
|
-
{
|
|
870
|
-
...parameters.msg.payload,
|
|
871
|
-
},
|
|
872
|
-
);
|
|
873
|
-
|
|
874
|
-
return response;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
async listMessageFiles(parameters) {
|
|
878
|
-
const clientParams = {
|
|
879
|
-
apiKey: parameters.apiKey,
|
|
880
|
-
baseURL: parameters.apiBase,
|
|
881
|
-
organization: parameters.organization,
|
|
882
|
-
};
|
|
883
|
-
const openai = new OpenAI(clientParams);
|
|
884
|
-
|
|
885
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
886
|
-
const message_id = parameters.msg.payload.message_id;
|
|
887
|
-
delete parameters.msg.payload.thread_id;
|
|
888
|
-
delete parameters.msg.payload.message_id;
|
|
889
|
-
|
|
890
|
-
const response = await openai.beta.threads.messages.files.list(
|
|
891
|
-
thread_id,
|
|
892
|
-
message_id,
|
|
893
|
-
{
|
|
894
|
-
...parameters.msg.payload,
|
|
895
|
-
},
|
|
896
|
-
);
|
|
897
|
-
|
|
898
|
-
return response;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
async getMessageFile(parameters) {
|
|
902
|
-
const clientParams = {
|
|
903
|
-
apiKey: parameters.apiKey,
|
|
904
|
-
baseURL: parameters.apiBase,
|
|
905
|
-
organization: parameters.organization,
|
|
906
|
-
};
|
|
907
|
-
const openai = new OpenAI(clientParams);
|
|
908
|
-
|
|
909
|
-
const thread_id = parameters.msg.payload.thread_id;
|
|
910
|
-
const message_id = parameters.msg.payload.message_id;
|
|
911
|
-
const file_id = parameters.msg.payload.file_id;
|
|
912
|
-
|
|
913
|
-
delete parameters.msg.payload.thread_id;
|
|
914
|
-
delete parameters.msg.payload.message_id;
|
|
915
|
-
delete parameters.msg.payload.file_id;
|
|
916
|
-
|
|
917
|
-
const response = await openai.beta.threads.messages.files.retrieve(
|
|
918
|
-
thread_id,
|
|
919
|
-
message_id,
|
|
920
|
-
file_id,
|
|
921
|
-
{
|
|
922
|
-
...parameters.msg.payload,
|
|
923
|
-
},
|
|
678
|
+
params,
|
|
924
679
|
);
|
|
925
680
|
|
|
926
681
|
return response;
|