@inductiv/node-red-openai-api 0.1.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/LICENSE +7 -0
- package/README.md +66 -0
- package/examples/assistants.json +442 -0
- package/examples/audio.json +122 -0
- package/examples/chat.json +87 -0
- package/examples/embeddings.json +72 -0
- package/examples/files.json +72 -0
- package/examples/fine-tuning.json +72 -0
- package/examples/images.json +82 -0
- package/examples/messages.json +77 -0
- package/examples/models.json +92 -0
- package/examples/moderations.json +77 -0
- package/examples/runs.json +77 -0
- package/examples/threads.json +67 -0
- package/icons/icon.png +0 -0
- package/lib.js +617 -0
- package/locales/de-DE/node.json +112 -0
- package/locales/en-US/node.json +112 -0
- package/locales/ja/node.json +112 -0
- package/locales/zh-CN/node.json +112 -0
- package/node.html +771 -0
- package/node.js +256 -0
- package/package.json +45 -0
package/lib.js
ADDED
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
/*jshint -W069 */
|
|
2
|
+
|
|
3
|
+
const { threadId } = require('worker_threads');
|
|
4
|
+
const { v4: uuidv4 } = require('uuid');
|
|
5
|
+
const FileType = require('file-type');
|
|
6
|
+
|
|
7
|
+
var OpenaiApi = (function () {
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const axios = require('axios');
|
|
11
|
+
const FormData = require('form-data'); // Only if you handle form data
|
|
12
|
+
|
|
13
|
+
function OpenaiApi(options) {
|
|
14
|
+
var domain = (typeof options === 'object') ? options.domain : options;
|
|
15
|
+
this.domain = domain ? domain : 'https://api.openai.com/v1';
|
|
16
|
+
if (this.domain.length === 0) {
|
|
17
|
+
throw new Error('Domain parameter must be specified as a string.');
|
|
18
|
+
}
|
|
19
|
+
this.apiKey = (typeof options === 'object') ? (options.apiKey ? options.apiKey : {}) : {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function mergeQueryParams(parameters, queryParameters) {
|
|
23
|
+
if (parameters.$queryParameters) {
|
|
24
|
+
Object.keys(parameters.$queryParameters)
|
|
25
|
+
.forEach(function (parameterName) {
|
|
26
|
+
var parameter = parameters.$queryParameters[parameterName];
|
|
27
|
+
queryParameters[parameterName] = parameter;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return queryParameters;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
OpenaiApi.prototype.request = function (method, url, body, headers, queryParameters, form) {
|
|
34
|
+
// Create an instance of axios with default headers
|
|
35
|
+
const axiosInstance = axios.create({
|
|
36
|
+
headers: headers
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Initialize the data to be sent
|
|
40
|
+
let data = body;
|
|
41
|
+
|
|
42
|
+
// Handle 'multipart/form-data'
|
|
43
|
+
if (Object.keys(form).length > 0 && headers['Content-Type'] === 'multipart/form-data') {
|
|
44
|
+
const formData = new FormData();
|
|
45
|
+
for (const key of Object.keys(parameters)) {
|
|
46
|
+
formData.append(key, parameters.body[key]);
|
|
47
|
+
};
|
|
48
|
+
data = formData;
|
|
49
|
+
} else if (typeof body === 'object' && !(body instanceof Buffer)) {
|
|
50
|
+
// Ensure the headers are set for JSON
|
|
51
|
+
headers['Content-Type'] = 'application/json';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Remove body data for GET requests
|
|
55
|
+
if (method === "GET") {
|
|
56
|
+
data = undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Make the axios request
|
|
60
|
+
return axiosInstance({
|
|
61
|
+
method: method,
|
|
62
|
+
url: url,
|
|
63
|
+
params: queryParameters,
|
|
64
|
+
data: data
|
|
65
|
+
})
|
|
66
|
+
.then(response => {
|
|
67
|
+
// Check for JSON response and parse if necessary
|
|
68
|
+
if (/^application\/(.*\+)?json/.test(response.headers['content-type'])) {
|
|
69
|
+
return { response: response, body: response.data };
|
|
70
|
+
} else {
|
|
71
|
+
// For non-JSON responses, resolve with the raw response
|
|
72
|
+
return { response: response, body: response.data };
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
.catch(error => {
|
|
76
|
+
// Handle errors
|
|
77
|
+
if (error.response) {
|
|
78
|
+
// The server responded with a status code that falls out of the range of 2xx
|
|
79
|
+
throw { response: error.response, body: error.response.data };
|
|
80
|
+
} else if (error.request) {
|
|
81
|
+
// The request was made but no response was received
|
|
82
|
+
throw new Error('No response received');
|
|
83
|
+
} else {
|
|
84
|
+
// Something happened in setting up the request that triggered an Error
|
|
85
|
+
throw new Error(error.message);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
OpenaiApi.prototype.setApiKey = function (value, headerOrQueryName, isQuery) {
|
|
91
|
+
this.apiKey.value = value;
|
|
92
|
+
this.apiKey.headerOrQueryName = headerOrQueryName;
|
|
93
|
+
this.apiKey.isQuery = isQuery;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
OpenaiApi.prototype.setAuthHeaders = function (headerParams) {
|
|
97
|
+
var headers = headerParams ? headerParams : {};
|
|
98
|
+
if (!this.apiKey.isQuery && this.apiKey.headerOrQueryName) {
|
|
99
|
+
headers[this.apiKey.headerOrQueryName] = `Bearer ${this.apiKey.value}`;
|
|
100
|
+
}
|
|
101
|
+
return headers;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
OpenaiApi.prototype.getFromEndpoint = function (path, parameters, expectedQueryParams, customHeaders) {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
// parameters = parameters || {};
|
|
107
|
+
var domain = this.domain;
|
|
108
|
+
var queryParameters = {}, baseHeaders = {};
|
|
109
|
+
|
|
110
|
+
baseHeaders = this.setAuthHeaders(headers);
|
|
111
|
+
baseHeaders['Accept'] = 'application/json';
|
|
112
|
+
|
|
113
|
+
var headers = {
|
|
114
|
+
...baseHeaders,
|
|
115
|
+
...customHeaders
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
// Only add query parameters if they are expected and exist
|
|
120
|
+
if (expectedQueryParams) {
|
|
121
|
+
expectedQueryParams.forEach(param => {
|
|
122
|
+
if (parameters.body[param] !== undefined) {
|
|
123
|
+
queryParameters[param] = parameters.body[param];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Merge any additional query parameters from the parameters object
|
|
129
|
+
queryParameters = mergeQueryParams(parameters, queryParameters);
|
|
130
|
+
|
|
131
|
+
// Axios request configuration
|
|
132
|
+
const config = {
|
|
133
|
+
method: 'GET',
|
|
134
|
+
url: domain + path,
|
|
135
|
+
headers: headers,
|
|
136
|
+
params: queryParameters
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Axios POST request
|
|
140
|
+
axios(config)
|
|
141
|
+
.then(response => {
|
|
142
|
+
resolve(response);
|
|
143
|
+
})
|
|
144
|
+
.catch(error => {
|
|
145
|
+
reject(error);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
OpenaiApi.prototype.postToEndpoint = function (path, parameters, expectedQueryParams, contentType, filePath, customHeaders) {
|
|
152
|
+
return new Promise((resolve, reject) => {
|
|
153
|
+
const _path = require('path');
|
|
154
|
+
|
|
155
|
+
parameters = parameters || {};
|
|
156
|
+
var domain = this.domain;
|
|
157
|
+
var queryParameters = {}, baseHeaders = {}, data;
|
|
158
|
+
|
|
159
|
+
baseHeaders = this.setAuthHeaders({});
|
|
160
|
+
baseHeaders['Accept'] = 'application/json';
|
|
161
|
+
|
|
162
|
+
var headers = {
|
|
163
|
+
...baseHeaders,
|
|
164
|
+
...customHeaders
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Determine the Content-Type
|
|
168
|
+
if (contentType === 'form-data') {
|
|
169
|
+
var formData = new FormData();
|
|
170
|
+
|
|
171
|
+
Object.entries(parameters.body).forEach(([key, value]) => {
|
|
172
|
+
if (value instanceof Buffer) {
|
|
173
|
+
if (!filePath) {
|
|
174
|
+
throw new Error('msg.payload must include a `filename` property.');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const filename = _path.basename(filePath);
|
|
178
|
+
formData.append(key, value, filename);
|
|
179
|
+
} else {
|
|
180
|
+
if (parameters.body[key] !== undefined) {
|
|
181
|
+
formData.append(key, value);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
data = formData;
|
|
187
|
+
|
|
188
|
+
let formHeaders = formData.getHeaders();
|
|
189
|
+
Object.assign(headers, formHeaders);
|
|
190
|
+
} else {
|
|
191
|
+
// Handle JSON payloads
|
|
192
|
+
headers['Content-Type'] = 'application/json';
|
|
193
|
+
data = parameters.body || {};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Add expected query parameters to the queryParameters object
|
|
197
|
+
if (expectedQueryParams) {
|
|
198
|
+
expectedQueryParams.forEach(param => {
|
|
199
|
+
if (parameters.body[param] !== undefined) {
|
|
200
|
+
queryParameters[param] = parameters.body[param];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Merge any additional query parameters from the parameters object
|
|
206
|
+
queryParameters = mergeQueryParams(parameters.body, queryParameters);
|
|
207
|
+
|
|
208
|
+
// Axios request configuration
|
|
209
|
+
const config = {
|
|
210
|
+
method: 'POST',
|
|
211
|
+
url: domain + path,
|
|
212
|
+
headers: headers,
|
|
213
|
+
params: queryParameters,
|
|
214
|
+
data: data
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// Axios POST request
|
|
218
|
+
axios(config)
|
|
219
|
+
.then(response => {
|
|
220
|
+
resolve(response);
|
|
221
|
+
})
|
|
222
|
+
.catch(error => {
|
|
223
|
+
reject(error);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
OpenaiApi.prototype.deleteFromEndpoint = function (path, parameters, expectedQueryParams, customHeaders) {
|
|
229
|
+
return new Promise((resolve, reject) => {
|
|
230
|
+
parameters = parameters || {};
|
|
231
|
+
var domain = this.domain;
|
|
232
|
+
var queryParameters = {}, baseHeaders = {};
|
|
233
|
+
|
|
234
|
+
baseHeaders = this.setAuthHeaders(headers);
|
|
235
|
+
baseHeaders['Accept'] = 'application/json';
|
|
236
|
+
|
|
237
|
+
var headers = {
|
|
238
|
+
...baseHeaders,
|
|
239
|
+
...customHeaders
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Only add query parameters if they are expected and exist
|
|
243
|
+
if (expectedQueryParams) {
|
|
244
|
+
expectedQueryParams.forEach(param => {
|
|
245
|
+
if (parameters[param] !== undefined) {
|
|
246
|
+
queryParameters[param] = parameters.body[param];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Merge any additional query parameters from the parameters object
|
|
252
|
+
queryParameters = mergeQueryParams(parameters, queryParameters);
|
|
253
|
+
|
|
254
|
+
// Axios request configuration
|
|
255
|
+
const config = {
|
|
256
|
+
method: 'DELETE',
|
|
257
|
+
url: domain + path,
|
|
258
|
+
headers: headers,
|
|
259
|
+
params: queryParameters
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// Axios POST request
|
|
263
|
+
axios(config)
|
|
264
|
+
.then(response => {
|
|
265
|
+
resolve(response);
|
|
266
|
+
})
|
|
267
|
+
.catch(error => {
|
|
268
|
+
reject(error);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
OpenaiApi.prototype.createChatCompletion = function (parameters) {
|
|
274
|
+
const response = this.postToEndpoint('/chat/completions', parameters);
|
|
275
|
+
return response;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
OpenaiApi.prototype.createImage = function (parameters) {
|
|
279
|
+
return this.postToEndpoint('/images/generations', parameters);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
OpenaiApi.prototype.createImageEdit = function (parameters) {
|
|
283
|
+
const filename = parameters.body.filename;
|
|
284
|
+
delete parameters.body.filename;
|
|
285
|
+
|
|
286
|
+
return this.postToEndpoint('/images/edits', parameters, null, 'form-data', filename);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
OpenaiApi.prototype.createImageVariation = function (parameters) {
|
|
290
|
+
const filename = parameters.body.filename;
|
|
291
|
+
delete parameters.body.filename;
|
|
292
|
+
|
|
293
|
+
return this.postToEndpoint('/images/variations', parameters, null, 'form-data', filename);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
OpenaiApi.prototype.createEmbedding = function (parameters) {
|
|
297
|
+
return this.postToEndpoint('/embeddings', parameters);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
OpenaiApi.prototype.createSpeech = function (parameters) {
|
|
301
|
+
return this.postToEndpoint('/audio/speech', parameters);
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
OpenaiApi.prototype.createTranscription = function (parameters) {
|
|
305
|
+
const filename = parameters.body.filename;
|
|
306
|
+
delete parameters.body.filename;
|
|
307
|
+
|
|
308
|
+
return this.postToEndpoint('/audio/transcriptions', parameters, null, 'form-data', filename);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
OpenaiApi.prototype.createTranslation = function (parameters) {
|
|
312
|
+
const filename = parameters.body.filename;
|
|
313
|
+
delete parameters.body.filename;
|
|
314
|
+
|
|
315
|
+
return this.postToEndpoint('/audio/translations', parameters, null, 'form-data', filename);
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
OpenaiApi.prototype.listFiles = function (parameters) {
|
|
319
|
+
const expectedQueryParameters = ['purpose'];
|
|
320
|
+
return this.getFromEndpoint('/files', parameters, expectedQueryParameters);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
OpenaiApi.prototype.createFile = function (parameters) {
|
|
324
|
+
let filename;
|
|
325
|
+
|
|
326
|
+
// reference the incoming filename
|
|
327
|
+
filename = parameters.body.filename;
|
|
328
|
+
delete parameters.body.filename;
|
|
329
|
+
|
|
330
|
+
return this.postToEndpoint('/files', parameters, null, 'form-data', filename);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
OpenaiApi.prototype.deleteFile = function (parameters) {
|
|
334
|
+
const file_id = parameters.body.file_id;
|
|
335
|
+
return this.deleteFromEndpoint(`/files/${file_id}`, parameters);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
OpenaiApi.prototype.retrieveFile = function (parameters) {
|
|
339
|
+
const file_id = parameters.body.file_id;
|
|
340
|
+
return this.getFromEndpoint(`/files/${file_id}`, parameters);
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
OpenaiApi.prototype.downloadFile = function (parameters) {
|
|
344
|
+
const file_id = parameters.body.file_id;
|
|
345
|
+
return this.getFromEndpoint(`/files/${file_id}/content`, parameters);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
OpenaiApi.prototype.createFineTuningJob = function (parameters) {
|
|
349
|
+
return this.postToEndpoint('/fine_tuning/jobs', parameters);
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
OpenaiApi.prototype.listPaginatedFineTuningJobs = function (parameters) {
|
|
353
|
+
const expectedQueryParameters = ['after', 'limit'];
|
|
354
|
+
return this.getFromEndpoint('/fine_tuning/jobs', parameters, expectedQueryParameters);
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
OpenaiApi.prototype.retrieveFineTuningJob = function (parameters) {
|
|
358
|
+
const fine_tuning_job_id = parameters.body.fine_tuning_job_id;
|
|
359
|
+
return this.getFromEndpoint(`/fine_tuning/jobs/${fine_tuning_job_id}`, parameters);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
OpenaiApi.prototype.listFineTuningEvents = function (parameters) {
|
|
363
|
+
const expectedQueryParameters = ['after', 'limit'];
|
|
364
|
+
const fine_tuning_job_id = parameters.body.fine_tuning_job_id;
|
|
365
|
+
|
|
366
|
+
return this.getFromEndpoint(`/fine_tuning/jobs/${fine_tuning_job_id}/events`, parameters, expectedQueryParameters);
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
OpenaiApi.prototype.cancelFineTuningJob = function (parameters) {
|
|
370
|
+
const fine_tuning_job_id = parameters.body.fine_tuning_job_id;
|
|
371
|
+
return this.postToEndpoint(`/fine_tuning/jobs/${fine_tuning_job_id}/cancel`, parameters);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
OpenaiApi.prototype.listModels = function (parameters) {
|
|
375
|
+
return this.getFromEndpoint('/models', parameters);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
OpenaiApi.prototype.retrieveModel = function (parameters) {
|
|
379
|
+
const model = parameters.body.model;
|
|
380
|
+
|
|
381
|
+
return this.getFromEndpoint(`/models/${model}`, parameters);
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
OpenaiApi.prototype.deleteModel = function (parameters) {
|
|
385
|
+
const model = parameters.body.model;
|
|
386
|
+
|
|
387
|
+
return this.deleteFromEndpoint(`/models/${model}`, parameters);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
OpenaiApi.prototype.createModeration = function (parameters) {
|
|
391
|
+
return this.postToEndpoint('/moderations', parameters);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
OpenaiApi.prototype.listAssistants = function (parameters) {
|
|
395
|
+
var expectedQueryParameters = ['limit', 'order', 'after', 'before'];
|
|
396
|
+
var customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
397
|
+
|
|
398
|
+
return this.getFromEndpoint('/assistants', parameters, expectedQueryParameters, customHeaders);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
OpenaiApi.prototype.createAssistant = function (parameters) {
|
|
402
|
+
var customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
403
|
+
|
|
404
|
+
return this.postToEndpoint('/assistants', parameters, null, null, null, customHeaders);
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
OpenaiApi.prototype.getAssistant = function (parameters) {
|
|
408
|
+
const assistantId = parameters.body.assistant_id;
|
|
409
|
+
|
|
410
|
+
var customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
411
|
+
|
|
412
|
+
return this.getFromEndpoint(`/assistants/${assistantId}`, parameters, null, customHeaders);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
OpenaiApi.prototype.modifyAssistant = function (parameters) {
|
|
416
|
+
|
|
417
|
+
const assistant_id = parameters.body.assistant_id;
|
|
418
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
419
|
+
|
|
420
|
+
return this.postToEndpoint(`/assistants/${assistant_id}`, parameters, null, null, null, customHeaders);
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
OpenaiApi.prototype.deleteAssistant = function (parameters) {
|
|
424
|
+
const assistant_id = parameters.body.assistant_id;
|
|
425
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
426
|
+
|
|
427
|
+
return this.deleteFromEndpoint(`/assistants/${assistant_id}`, parameters, null, customHeaders);
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
OpenaiApi.prototype.createThread = function (parameters) {
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
434
|
+
return this.postToEndpoint('/threads', parameters, null, null, null, customHeaders);
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
OpenaiApi.prototype.getThread = function (parameters) {
|
|
438
|
+
const threadId = parameters.body.thread_id;
|
|
439
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
440
|
+
|
|
441
|
+
return this.getFromEndpoint(`/threads/${threadId}`, parameters, null, customHeaders);
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
OpenaiApi.prototype.modifyThread = function (parameters) {
|
|
445
|
+
const threadId = parameters.body.thread_id;
|
|
446
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
447
|
+
|
|
448
|
+
return this.postToEndpoint(`/threads/${threadId}`, parameters, null, null, null, customHeaders);
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
OpenaiApi.prototype.deleteThread = function (parameters) {
|
|
452
|
+
const threadId = parameters.body.thread_id;
|
|
453
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
454
|
+
|
|
455
|
+
return this.deleteFromEndpoint(`/threads/${threadId}`, parameters, null, customHeaders);
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
OpenaiApi.prototype.listMessages = function (parameters) {
|
|
459
|
+
const threadId = parameters.body.thread_id;
|
|
460
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
461
|
+
|
|
462
|
+
const expectedQueryParameters = ['limit', 'order', 'after', 'before'];
|
|
463
|
+
|
|
464
|
+
return this.getFromEndpoint(`/threads/${threadId}/messages`, parameters, expectedQueryParameters, customHeaders);
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
OpenaiApi.prototype.createMessage = function (parameters) {
|
|
468
|
+
const threadId = parameters.body.thread_id;
|
|
469
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
470
|
+
|
|
471
|
+
return this.postToEndpoint(`/threads/${threadId}/messages`, parameters, null, null, null, customHeaders)
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
OpenaiApi.prototype.getMessage = function (parameters) {
|
|
475
|
+
|
|
476
|
+
const threadId = parameters.body.thread_id;
|
|
477
|
+
const messageId = parameters.messageId;
|
|
478
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
479
|
+
|
|
480
|
+
return this.getFromEndpoint(`/threads/${threadId}/messages/${messageId}`, parameters, null, customHeaders);
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
OpenaiApi.prototype.modifyMessage = function (parameters) {
|
|
484
|
+
|
|
485
|
+
const threadId = parameters.body.thread_id;
|
|
486
|
+
const messageId = parameters.messageId;
|
|
487
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
488
|
+
|
|
489
|
+
return this.postToEndpoint(`/threads/${threadId}/messages/${messageId}`, parameters, null, null, null, customHeaders);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
OpenaiApi.prototype.createThreadAndRun = function (parameters) {
|
|
493
|
+
|
|
494
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
495
|
+
|
|
496
|
+
return this.postToEndpoint('/threads/runs', parameters, null, null, null, customHeaders);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
OpenaiApi.prototype.listRuns = function (parameters) {
|
|
500
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
501
|
+
const expectedQueryParameters = ['limit', 'order', 'after', 'before'];
|
|
502
|
+
const threadId = parameters.body.thread_id;
|
|
503
|
+
|
|
504
|
+
return this.getFromEndpoint(`/threads/${threadId}/runs`, parameters, expectedQueryParameters, customHeaders);
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
OpenaiApi.prototype.createRun = function (parameters) {
|
|
508
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
509
|
+
const threadId = parameters.body.thread_id;
|
|
510
|
+
|
|
511
|
+
return this.postToEndpoint(`/threads/${threadId}/runs`, parameters, null, null, null, customHeaders);
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
OpenaiApi.prototype.getRun = function (parameters) {
|
|
515
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
516
|
+
const threadId = parameters.body.thread_id;
|
|
517
|
+
const runId = parameters.runId;
|
|
518
|
+
|
|
519
|
+
return this.getFromEndpoint(`/threads/${threadId}/runs/${runId}`, parameters, null, customHeaders);
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
OpenaiApi.prototype.modifyRun = function (parameters) {
|
|
523
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
524
|
+
const threadId = parameters.body.thread_id;
|
|
525
|
+
const runId = parameters.runId;
|
|
526
|
+
|
|
527
|
+
return this.postToEndpoint(`/threads/${threadId}/runs/${runId}`, parameters, null, null, null, customHeaders);
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
OpenaiApi.prototype.submitToolOuputsToRun = function (parameters) {
|
|
531
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
532
|
+
const threadId = parameters.body.thread_id;
|
|
533
|
+
const runId = parameters.runId;
|
|
534
|
+
|
|
535
|
+
return this.postToEndpoint(`/threads/${threadId}/runs/${runId}/submit_tool_outputs`, parameters, null, null, null, customHeaders);
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
OpenaiApi.prototype.cancelRun = function (parameters) {
|
|
539
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
540
|
+
const threadId = parameters.body.thread_id;
|
|
541
|
+
const runId = parameters.runId;
|
|
542
|
+
|
|
543
|
+
return this.postToEndpoint(`/threads/${threadId}/runs/${runId}/cancel`, parameters, null, null, null, customHeaders);
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
OpenaiApi.prototype.listRunSteps = function (parameters) {
|
|
547
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
548
|
+
const threadId = parameters.body.thread_id;
|
|
549
|
+
const runId = parameters.runId;
|
|
550
|
+
|
|
551
|
+
return this.getFromEndpoint(`/threads/${threadId}/runs/${runId}/steps`, parameters, null, customHeaders);
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
OpenaiApi.prototype.getRunStep = function (parameters) {
|
|
555
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
556
|
+
const threadId = parameters.body.thread_id;
|
|
557
|
+
const runId = parameters.runId;
|
|
558
|
+
const stepId = parameters.stepId;
|
|
559
|
+
|
|
560
|
+
return this.getFromEndpoint(`/threads/${threadId}/runs/${runId}/steps/${stepId}`, parameters, null, customHeaders);
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
OpenaiApi.prototype.listAssistantFiles = function (parameters) {
|
|
564
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
565
|
+
const assistantId = parameters.assistantId;
|
|
566
|
+
|
|
567
|
+
return this.getFromEndpoint(`/assistants/${assistantId}/files`, parameters, null, customHeaders);
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
OpenaiApi.prototype.createAssistantFile = function (parameters) {
|
|
571
|
+
|
|
572
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
573
|
+
const assistantId = parameters.assistantId;
|
|
574
|
+
|
|
575
|
+
return this.postToEndpoint(`/assistants/${assistantId}/files`, parameters, null, null, null, customHeaders);
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
OpenaiApi.prototype.getAssistantFile = function (parameters) {
|
|
579
|
+
|
|
580
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
581
|
+
const assistantId = parameters.assistantId;
|
|
582
|
+
const fileId = parameters.fileId;
|
|
583
|
+
|
|
584
|
+
return this.getFromEndpoint(`/assistants/${assistantId}/files/${fileId}`, parameters, null, customHeaders);
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
OpenaiApi.prototype.deleteAssistantFile = function (parameters) {
|
|
588
|
+
|
|
589
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
590
|
+
const assistantId = parameters.assistantId;
|
|
591
|
+
const fileId = parameters.fileId;
|
|
592
|
+
|
|
593
|
+
return this.deleteFromEndpoint(`/assistants/${assistantId}/files/${fileId}`, parameters, null, customHeaders);
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
OpenaiApi.prototype.listMessageFiles = function (parameters) {
|
|
597
|
+
|
|
598
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
599
|
+
const threadId = parameters.body.thread_id;
|
|
600
|
+
const messageId = parameters.messageId;
|
|
601
|
+
|
|
602
|
+
return this.getFromEndpoint(`/threads/${threadId}/messages/${messageId}/files`, parameters, null, customHeaders);
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
OpenaiApi.prototype.getMessageFile = function (parameters) {
|
|
606
|
+
const customHeaders = { 'OpenAI-Beta': 'assistants=v1' };
|
|
607
|
+
const threadId = parameters.body.thread_id;
|
|
608
|
+
const messageId = parameters.messageId;
|
|
609
|
+
const fileId = parameters.fileId;
|
|
610
|
+
|
|
611
|
+
return this.getFromEndpoint(`/threads/${threadId}/messages/${messageId}/files/${fileId}`, parameters, null, customHeaders);
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
return OpenaiApi;
|
|
615
|
+
})();
|
|
616
|
+
|
|
617
|
+
exports.OpenaiApi = OpenaiApi;
|