backend-manager 3.2.73 → 3.2.75
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
CHANGED
|
@@ -2,6 +2,7 @@ const fetch = require('wonderful-fetch');
|
|
|
2
2
|
const jetpack = require('fs-jetpack');
|
|
3
3
|
const powertools = require('node-powertools');
|
|
4
4
|
const _ = require('lodash');
|
|
5
|
+
const JSON5 = require('json5');
|
|
5
6
|
|
|
6
7
|
const TOKEN_COST_TABLE = {
|
|
7
8
|
// Nov 6th, 2023
|
|
@@ -225,6 +226,7 @@ OpenAI.prototype.request = function (options) {
|
|
|
225
226
|
})
|
|
226
227
|
.catch((e) => e);
|
|
227
228
|
|
|
229
|
+
// Check for moderation flag
|
|
228
230
|
if (moderation.flagged) {
|
|
229
231
|
return reject(assistant.errorify(`This request is inappropriate`, {code: 451}));
|
|
230
232
|
}
|
|
@@ -234,8 +236,10 @@ OpenAI.prototype.request = function (options) {
|
|
|
234
236
|
await _request('chatgpt', options)
|
|
235
237
|
.then((r) => {
|
|
236
238
|
try {
|
|
237
|
-
|
|
239
|
+
// Parse JSON response if needed
|
|
240
|
+
const content = options.response === 'json' ? JSON5.parse(r) : r;
|
|
238
241
|
|
|
242
|
+
// Return
|
|
239
243
|
return resolve({
|
|
240
244
|
content: content,
|
|
241
245
|
tokens: self.tokens,
|
|
@@ -244,6 +248,7 @@ OpenAI.prototype.request = function (options) {
|
|
|
244
248
|
} catch (e) {
|
|
245
249
|
assistant.warn('Error parsing response', r, e);
|
|
246
250
|
|
|
251
|
+
// Return
|
|
247
252
|
return reject(e);
|
|
248
253
|
}
|
|
249
254
|
})
|