mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
🖥️ feat: Match STDOUT Logs with Debug File Logs (#1944)
* chore: improve token balance logging post-request * feat: match stdout logging with file debug logging when using DEBUG_CONSOLE
This commit is contained in:
parent
ef86b25dae
commit
b2ef75e009
4 changed files with 13 additions and 5 deletions
|
@ -106,7 +106,7 @@ if (
|
||||||
transports.push(
|
transports.push(
|
||||||
new winston.transports.Console({
|
new winston.transports.Console({
|
||||||
level: 'debug',
|
level: 'debug',
|
||||||
format: winston.format.combine(consoleFormat, debugTraverse),
|
format: winston.format.combine(fileFormat, debugTraverse),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -36,11 +36,17 @@ transactionSchema.statics.create = async function (transactionData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust the user's balance
|
// Adjust the user's balance
|
||||||
return await Balance.findOneAndUpdate(
|
const updatedBalance = await Balance.findOneAndUpdate(
|
||||||
{ user: transaction.user },
|
{ user: transaction.user },
|
||||||
{ $inc: { tokenCredits: transaction.tokenValue } },
|
{ $inc: { tokenCredits: transaction.tokenValue } },
|
||||||
{ upsert: true, new: true },
|
{ upsert: true, new: true },
|
||||||
).lean();
|
).lean();
|
||||||
|
|
||||||
|
return {
|
||||||
|
user: transaction.user.toString(),
|
||||||
|
[transaction.tokenType]: transaction.tokenValue,
|
||||||
|
balance: updatedBalance.tokenCredits,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = mongoose.model('Transaction', transactionSchema);
|
module.exports = mongoose.model('Transaction', transactionSchema);
|
||||||
|
|
|
@ -49,8 +49,10 @@ const spendTokens = async (txData, tokenUsage) => {
|
||||||
prompt &&
|
prompt &&
|
||||||
completion &&
|
completion &&
|
||||||
logger.debug('[spendTokens] Transaction data record against balance:', {
|
logger.debug('[spendTokens] Transaction data record against balance:', {
|
||||||
prompt,
|
user: prompt.user,
|
||||||
completion,
|
prompt: prompt.prompt,
|
||||||
|
completion: completion.completion,
|
||||||
|
balance: completion.balance,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('[spendTokens]', err);
|
logger.error('[spendTokens]', err);
|
||||||
|
|
|
@ -84,7 +84,7 @@ const connect = require('./connect');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the result
|
// Check the result
|
||||||
if (!result?.tokenCredits) {
|
if (!result?.balance) {
|
||||||
console.red('Error: Something went wrong while updating the balance!');
|
console.red('Error: Something went wrong while updating the balance!');
|
||||||
console.error(result);
|
console.error(result);
|
||||||
silentExit(1);
|
silentExit(1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue