Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

refactor(Tx): record rate and use Math.ceil instead of Math.floor

Danny Avila09c03b9df01a
diff --git a/api/models/Transaction.js b/api/models/Transaction.js
index e5092efe1f..635db45b63 100644
--- a/api/models/Transaction.js
+++ b/api/models/Transaction.js
@@ -3,6 +3,7 @@ const { isEnabled } = require('../server/utils/handleText');
const transactionSchema = require('./schema/transaction');
const { getMultiplier } = require('./tx');
const Balance = require('./Balance');
+const cancelRate = 1.15;
// Method to calculate and set the tokenValue for a transaction
transactionSchema.methods.calculateTokenValue = function () {
@@ -11,9 +12,11 @@ transactionSchema.methods.calculateTokenValue = function () {
}
const { valueKey, tokenType, model } = this;
const multiplier = getMultiplier({ valueKey, tokenType, model });
+ this.rate = multiplier;
this.tokenValue = this.rawAmount * multiplier;
if (this.context && this.tokenType === 'completion' && this.context === 'incomplete') {
- this.tokenValue = Math.floor(this.tokenValue * 1.15);
+ this.tokenValue = Math.ceil(this.tokenValue * cancelRate);
+ this.rate *= cancelRate;
}
};
diff --git a/api/models/schema/transaction.js b/api/models/schema/transaction.js
index 71ddb6a0b4..95fd9fc86a 100644
--- a/api/models/schema/transaction.js
+++ b/api/models/schema/transaction.js
@@ -26,6 +26,7 @@ const transactionSchema = mongoose.Schema({
valueKey: {
type: String,
},
+ rate: Number,
rawAmount: Number,
tokenValue: Number,
});