diff --git a/api/config/winston.js b/api/config/winston.js index 6cba153f163..0c167b807ff 100644 --- a/api/config/winston.js +++ b/api/config/winston.js @@ -106,7 +106,7 @@ if ( transports.push( new winston.transports.Console({ level: 'debug', - format: winston.format.combine(consoleFormat, debugTraverse), + format: winston.format.combine(fileFormat, debugTraverse), }), ); } else { diff --git a/api/models/Transaction.js b/api/models/Transaction.js index e608203592e..dcca3315a4a 100644 --- a/api/models/Transaction.js +++ b/api/models/Transaction.js @@ -36,11 +36,17 @@ transactionSchema.statics.create = async function (transactionData) { } // Adjust the user's balance - return await Balance.findOneAndUpdate( + const updatedBalance = await Balance.findOneAndUpdate( { user: transaction.user }, { $inc: { tokenCredits: transaction.tokenValue } }, { upsert: true, new: true }, ).lean(); + + return { + user: transaction.user.toString(), + [transaction.tokenType]: transaction.tokenValue, + balance: updatedBalance.tokenCredits, + }; }; module.exports = mongoose.model('Transaction', transactionSchema); diff --git a/api/models/spendTokens.js b/api/models/spendTokens.js index f52075b13d1..3d83581762e 100644 --- a/api/models/spendTokens.js +++ b/api/models/spendTokens.js @@ -49,8 +49,10 @@ const spendTokens = async (txData, tokenUsage) => { prompt && completion && logger.debug('[spendTokens] Transaction data record against balance:', { - prompt, - completion, + user: prompt.user, + prompt: prompt.prompt, + completion: completion.completion, + balance: completion.balance, }); } catch (err) { logger.error('[spendTokens]', err); diff --git a/config/add-balance.js b/config/add-balance.js index 69caab8a0f5..2527dad96be 100644 --- a/config/add-balance.js +++ b/config/add-balance.js @@ -84,7 +84,7 @@ const connect = require('./connect'); } // Check the result - if (!result?.tokenCredits) { + if (!result?.balance) { console.red('Error: Something went wrong while updating the balance!'); console.error(result); silentExit(1);