backend-manager 3.2.78 → 3.2.80
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/package.json +4 -4
- package/src/manager/libraries/openai.js +52 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backend-manager",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.80",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"homepage": "https://itwcreativeworks.com",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@firebase/rules-unit-testing": "^2.0.7",
|
|
38
|
-
"@google-cloud/storage": "^7.
|
|
38
|
+
"@google-cloud/storage": "^7.8.0",
|
|
39
39
|
"@sendgrid/mail": "^7.7.0",
|
|
40
40
|
"@sentry/node": "^6.19.7",
|
|
41
41
|
"busboy": "^1.6.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"cors": "^2.8.5",
|
|
44
44
|
"dotenv": "^16.4.5",
|
|
45
45
|
"firebase-admin": "^11.11.1",
|
|
46
|
-
"firebase-functions": "^4.
|
|
46
|
+
"firebase-functions": "^4.8.0",
|
|
47
47
|
"fs-jetpack": "^5.1.0",
|
|
48
48
|
"hcaptcha": "^0.1.1",
|
|
49
49
|
"inquirer": "^8.2.5",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"moment": "^2.30.1",
|
|
57
57
|
"nanoid": "^3.3.7",
|
|
58
58
|
"node-fetch": "^2.7.0",
|
|
59
|
-
"node-powertools": "^1.
|
|
59
|
+
"node-powertools": "^1.3.0",
|
|
60
60
|
"npm-api": "^1.0.1",
|
|
61
61
|
"paypal-server-api": "^2.0.0",
|
|
62
62
|
"pushid": "^1.0.0",
|
|
@@ -82,6 +82,9 @@ OpenAI.prototype.request = function (options) {
|
|
|
82
82
|
options.log = typeof options.log === 'undefined' ? false : options.log;
|
|
83
83
|
options.user = options.user || assistant.getUser();
|
|
84
84
|
|
|
85
|
+
options.retries = typeof options.retries === 'undefined' ? 0 : options.retries;
|
|
86
|
+
options.retryTriggers = typeof options.retryTriggers === 'undefined' ? ['network', 'parse'] : options.retryTriggers;
|
|
87
|
+
|
|
85
88
|
options.prompt = options.prompt || {};
|
|
86
89
|
options.prompt.path = options.prompt.path || '';
|
|
87
90
|
options.prompt.content = options.prompt.content || '';
|
|
@@ -100,6 +103,8 @@ OpenAI.prototype.request = function (options) {
|
|
|
100
103
|
options.temperature = typeof options.temperature === 'undefined' ? 0.7 : options.temperature;
|
|
101
104
|
options.maxTokens = typeof options.maxTokens === 'undefined' ? 512 : options.maxTokens;
|
|
102
105
|
|
|
106
|
+
let attempt = 0;
|
|
107
|
+
|
|
103
108
|
function _log() {
|
|
104
109
|
if (!options.log) {
|
|
105
110
|
return;
|
|
@@ -249,31 +254,59 @@ OpenAI.prototype.request = function (options) {
|
|
|
249
254
|
}
|
|
250
255
|
}
|
|
251
256
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
_log('Response', r);
|
|
257
|
+
function _attempt() {
|
|
258
|
+
const retries = options.retries;
|
|
259
|
+
const triggers = options.retryTriggers;
|
|
256
260
|
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
const content = options.response === 'json' ? JSON5.parse(r) : r;
|
|
261
|
+
// Increment attempt
|
|
262
|
+
attempt++;
|
|
260
263
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
264
|
+
// Log
|
|
265
|
+
_log(`Request ${attempt}/${retries}`);
|
|
266
|
+
|
|
267
|
+
// Request
|
|
268
|
+
_request('chatgpt', options)
|
|
269
|
+
.then((r) => {
|
|
270
|
+
_log('Response', r);
|
|
271
|
+
|
|
272
|
+
// Try to parse JSON response if needed
|
|
273
|
+
try {
|
|
274
|
+
const content = options.response === 'json' ? JSON5.parse(r) : r;
|
|
275
|
+
|
|
276
|
+
// Return
|
|
277
|
+
return resolve({
|
|
278
|
+
content: content,
|
|
279
|
+
tokens: self.tokens,
|
|
280
|
+
moderation: moderation,
|
|
281
|
+
})
|
|
282
|
+
} catch (e) {
|
|
283
|
+
assistant.error('Error parsing response', r, e);
|
|
284
|
+
|
|
285
|
+
// Retry
|
|
286
|
+
if (attempt < retries && triggers.includes('parse')) {
|
|
287
|
+
return _attempt();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Return
|
|
291
|
+
return reject(e);
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
.catch((e) => {
|
|
295
|
+
assistant.error('Error requesting', e);
|
|
296
|
+
|
|
297
|
+
// Retry
|
|
298
|
+
if (attempt < retries && triggers.includes('network')) {
|
|
299
|
+
return _attempt();
|
|
300
|
+
}
|
|
269
301
|
|
|
270
302
|
// Return
|
|
271
303
|
return reject(e);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Make attempt
|
|
308
|
+
_attempt();
|
|
275
309
|
});
|
|
276
310
|
}
|
|
277
311
|
|
|
278
|
-
|
|
279
312
|
module.exports = OpenAI;
|