backend-manager 3.2.84 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "3.2.84",
3
+ "version": "3.2.85",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -5,8 +5,16 @@ const uuid = require('uuid');
5
5
  let JSON5;
6
6
 
7
7
  function BackendAssistant() {
8
- this.meta = {};
9
- this.initialized = false;
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) {
@@ -223,68 +231,21 @@ BackendAssistant.prototype.log = function () {
223
231
  self._log.apply(self, args);
224
232
  };
225
233
 
226
- BackendAssistant.prototype.error = function () {
227
- const self = this;
228
-
229
- const args = Array.prototype.slice.call(arguments);
230
-
231
- args.unshift('error');
232
- self.log.apply(self, args);
233
- };
234
-
235
- BackendAssistant.prototype.warn = function () {
236
- const self = this;
237
-
238
- const args = Array.prototype.slice.call(arguments);
239
-
240
- args.unshift('warn');
241
- self.log.apply(self, args);
242
- };
243
-
244
- BackendAssistant.prototype.info = function () {
245
- const self = this;
246
-
247
- const args = Array.prototype.slice.call(arguments);
248
-
249
- args.unshift('info');
250
- self.log.apply(self, args);
251
- };
252
-
253
- BackendAssistant.prototype.debug = function () {
254
- const self = this;
255
-
256
- const args = Array.prototype.slice.call(arguments);
257
-
258
- args.unshift('debug');
259
- self.log.apply(self, args);
260
- };
261
-
262
- BackendAssistant.prototype.notice = function () {
263
- const self = this;
264
-
265
- const args = Array.prototype.slice.call(arguments);
266
-
267
- args.unshift('notice');
268
- self.log.apply(self, args);
269
- };
270
-
271
- BackendAssistant.prototype.critical = function () {
272
- const self = this;
273
-
274
- const args = Array.prototype.slice.call(arguments);
275
-
276
- args.unshift('critical');
277
- self.log.apply(self, args);
278
- };
279
-
280
- BackendAssistant.prototype.emergency = function () {
281
- const self = this;
234
+ function addLogMethods() {
235
+ const levels = ['error', 'warn', 'info', 'debug', 'notice', 'critical', 'emergency'];
282
236
 
283
- const args = Array.prototype.slice.call(arguments);
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);
284
242
 
285
- args.unshift('emergency');
286
- self.log.apply(self, args);
287
- };
243
+ // Prepend level to args
244
+ args.unshift(level);
245
+ self.log.apply(this, args);
246
+ };
247
+ });
248
+ }
288
249
 
289
250
  BackendAssistant.prototype._log = function () {
290
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
- options.history.messages.push({
194
- role: 'user',
195
- content: message,
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);