backend-manager 3.2.165 → 3.2.166

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.165",
3
+ "version": "3.2.166",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -263,7 +263,11 @@ OpenAI.prototype.request = function (options) {
263
263
 
264
264
  if (mode === 'chatgpt') {
265
265
  request.url = 'https://api.openai.com/v1/chat/completions';
266
+
267
+ // Get history
266
268
  const history = options.history.messages.slice(-options.history.limit);
269
+
270
+ // Add prompt to history
267
271
  history.unshift({
268
272
  role: 'system',
269
273
  text: prompt,
@@ -344,15 +348,16 @@ OpenAI.prototype.request = function (options) {
344
348
  await fetch(request.url, request)
345
349
  .then(async (r) => {
346
350
  // Set token counts
347
- self.tokens.total.count += r?.usage?.total_tokens || 0;
348
351
  self.tokens.input.count += r?.usage?.prompt_tokens || 0;
349
352
  self.tokens.output.count += r?.usage?.completion_tokens || 0;
353
+ self.tokens.total.count = self.tokens.input.count + self.tokens.output.count;
350
354
 
351
355
  // Set token prices
352
- self.tokens.total.price = (self.tokens.total.count / 1000) * TOKEN_COST_TABLE[options.model].input;
353
356
  self.tokens.input.price = (self.tokens.input.count / 1000) * TOKEN_COST_TABLE[options.model].input;
354
357
  self.tokens.output.price = (self.tokens.output.count / 1000) * TOKEN_COST_TABLE[options.model].output;
358
+ self.tokens.total.price = self.tokens.input.price + self.tokens.output.price;
355
359
 
360
+ // Return
356
361
  return resolve(_.get(r, resultPath));
357
362
  })
358
363
  .catch((e) => {