backend-manager 3.2.83 → 3.2.85
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
|
@@ -5,8 +5,16 @@ const uuid = require('uuid');
|
|
|
5
5
|
let JSON5;
|
|
6
6
|
|
|
7
7
|
function BackendAssistant() {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const self = this;
|
|
9
|
+
|
|
10
|
+
// Set ref
|
|
11
|
+
self.meta = {};
|
|
12
|
+
self.initialized = false;
|
|
13
|
+
|
|
14
|
+
// Add log methods
|
|
15
|
+
addLogMethods();
|
|
16
|
+
|
|
17
|
+
return self;
|
|
10
18
|
}
|
|
11
19
|
|
|
12
20
|
function tryParse(input) {
|
|
@@ -61,9 +69,11 @@ BackendAssistant.prototype.init = function (ref, options) {
|
|
|
61
69
|
|
|
62
70
|
// Set ID
|
|
63
71
|
try {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
const headers = self?.ref?.req.headers || {};
|
|
73
|
+
|
|
74
|
+
self.id = headers['function-execution-id']
|
|
75
|
+
|| headers['X-Cloud-Trace-Context']
|
|
76
|
+
|| self.Manager.Utilities().randomId();
|
|
67
77
|
} catch {
|
|
68
78
|
self.id = now.getTime();
|
|
69
79
|
}
|
|
@@ -221,68 +231,21 @@ BackendAssistant.prototype.log = function () {
|
|
|
221
231
|
self._log.apply(self, args);
|
|
222
232
|
};
|
|
223
233
|
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
const args = Array.prototype.slice.call(arguments);
|
|
234
|
+
function addLogMethods() {
|
|
235
|
+
const levels = ['error', 'warn', 'info', 'debug', 'notice', 'critical', 'emergency'];
|
|
228
236
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
237
|
+
// Add log methods
|
|
238
|
+
levels.forEach((level) => {
|
|
239
|
+
BackendAssistant.prototype[level] = function() {
|
|
240
|
+
const self = this;
|
|
241
|
+
const args = Array.prototype.slice.call(arguments);
|
|
232
242
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
self.log.apply(self, args);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
BackendAssistant.prototype.info = function () {
|
|
243
|
-
const self = this;
|
|
244
|
-
|
|
245
|
-
const args = Array.prototype.slice.call(arguments);
|
|
246
|
-
|
|
247
|
-
args.unshift('info');
|
|
248
|
-
self.log.apply(self, args);
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
BackendAssistant.prototype.debug = function () {
|
|
252
|
-
const self = this;
|
|
253
|
-
|
|
254
|
-
const args = Array.prototype.slice.call(arguments);
|
|
255
|
-
|
|
256
|
-
args.unshift('debug');
|
|
257
|
-
self.log.apply(self, args);
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
BackendAssistant.prototype.notice = function () {
|
|
261
|
-
const self = this;
|
|
262
|
-
|
|
263
|
-
const args = Array.prototype.slice.call(arguments);
|
|
264
|
-
|
|
265
|
-
args.unshift('notice');
|
|
266
|
-
self.log.apply(self, args);
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
BackendAssistant.prototype.critical = function () {
|
|
270
|
-
const self = this;
|
|
271
|
-
|
|
272
|
-
const args = Array.prototype.slice.call(arguments);
|
|
273
|
-
|
|
274
|
-
args.unshift('critical');
|
|
275
|
-
self.log.apply(self, args);
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
BackendAssistant.prototype.emergency = function () {
|
|
279
|
-
const self = this;
|
|
280
|
-
|
|
281
|
-
const args = Array.prototype.slice.call(arguments);
|
|
282
|
-
|
|
283
|
-
args.unshift('emergency');
|
|
284
|
-
self.log.apply(self, args);
|
|
285
|
-
};
|
|
243
|
+
// Prepend level to args
|
|
244
|
+
args.unshift(level);
|
|
245
|
+
self.log.apply(this, args);
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
286
249
|
|
|
287
250
|
BackendAssistant.prototype._log = function () {
|
|
288
251
|
const self = this;
|
|
@@ -167,6 +167,13 @@ OpenAI.prototype.request = function (options) {
|
|
|
167
167
|
return reject(assistant.errorify(`Error loading message: ${message}`, {code: 400}));
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
// Format history
|
|
171
|
+
options.history.messages.forEach((m) => {
|
|
172
|
+
m.role = m.role || 'system';
|
|
173
|
+
m.content = (m.content || '').trim();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Request
|
|
170
177
|
function _request(mode, options) {
|
|
171
178
|
return new Promise(async function(resolve, reject) {
|
|
172
179
|
let resultPath = '';
|
|
@@ -190,10 +197,17 @@ OpenAI.prototype.request = function (options) {
|
|
|
190
197
|
role: 'system',
|
|
191
198
|
content: prompt,
|
|
192
199
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
200
|
+
|
|
201
|
+
// Set last history item
|
|
202
|
+
const lastHistory = options.history.messages[options.history.messages.length - 1];
|
|
203
|
+
|
|
204
|
+
// If message is different than last message in history, add it
|
|
205
|
+
if (lastHistory?.content !== message) {
|
|
206
|
+
options.history.messages.push({
|
|
207
|
+
role: 'user',
|
|
208
|
+
content: message,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
197
211
|
|
|
198
212
|
// Log message
|
|
199
213
|
_log('Messages', options.history.messages);
|