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

fix(getMultiplier): correct rate for gpt-4 context

Danny Avila599d70f1dec7
diff --git a/api/models/tx.js b/api/models/tx.js
index c69166cd95..96f0f80b5a 100644
--- a/api/models/tx.js
+++ b/api/models/tx.js
@@ -1,12 +1,13 @@
const { matchModelName } = require('../utils');
+const defaultRate = 6;
/**
* Mapping of model token sizes to their respective multipliers for prompt and completion.
* @type {Object.<string, {prompt: number, completion: number}>}
*/
const tokenValues = {
- '8k': { prompt: 3, completion: 6 },
- '32k': { prompt: 6, completion: 12 },
+ '8k': { prompt: 30, completion: 60 },
+ '32k': { prompt: 60, completion: 120 },
'4k': { prompt: 1.5, completion: 2 },
'16k': { prompt: 3, completion: 4 },
};
@@ -48,7 +49,7 @@ const getValueKey = (model) => {
*/
const getMultiplier = ({ valueKey, tokenType, model }) => {
if (valueKey && tokenType) {
- return tokenValues[valueKey][tokenType] ?? 4.5;
+ return tokenValues[valueKey][tokenType] ?? defaultRate;
}
if (!tokenType || !model) {
@@ -57,11 +58,11 @@ const getMultiplier = ({ valueKey, tokenType, model }) => {
valueKey = getValueKey(model);
if (!valueKey) {
- return 4.5;
+ return defaultRate;
}
// If we got this far, and values[tokenType] is undefined somehow, return a rough average of default multipliers
- return tokenValues[valueKey][tokenType] ?? 4.5;
+ return tokenValues[valueKey][tokenType] ?? defaultRate;
};
-module.exports = { tokenValues, getValueKey, getMultiplier };
+module.exports = { tokenValues, getValueKey, getMultiplier, defaultRate };
diff --git a/api/models/tx.spec.js b/api/models/tx.spec.js
index 791c1437ca..cab3132fae 100644
--- a/api/models/tx.spec.js
+++ b/api/models/tx.spec.js
@@ -1,4 +1,4 @@
-const { getValueKey, getMultiplier } = require('./tx');
+const { getValueKey, getMultiplier, defaultRate } = require('./tx');
describe('getValueKey', () => {
it('should return "16k" for model name containing "gpt-3.5-turbo-16k"', () => {
@@ -28,8 +28,8 @@ describe('getMultiplier', () => {
expect(getMultiplier({ valueKey: '8k', tokenType: 'completion' })).toBe(6);
});
- it('should return 4.5 if tokenType is provided but not found in tokenValues', () => {
- expect(getMultiplier({ valueKey: '8k', tokenType: 'unknownType' })).toBe(4.5);
+ it('should return defaultRate if tokenType is provided but not found in tokenValues', () => {
+ expect(getMultiplier({ valueKey: '8k', tokenType: 'unknownType' })).toBe(defaultRate);
});
it('should derive the valueKey from the model if not provided', () => {
@@ -41,7 +41,9 @@ describe('getMultiplier', () => {
expect(getMultiplier({ model: 'gpt-4-some-other-info' })).toBe(1);
});
- it('should return 4.5 if derived valueKey does not match any known patterns', () => {
- expect(getMultiplier({ tokenType: 'prompt', model: 'gpt-5-some-other-info' })).toBe(4.5);
+ it('should return defaultRate if derived valueKey does not match any known patterns', () => {
+ expect(getMultiplier({ tokenType: 'prompt', model: 'gpt-5-some-other-info' })).toBe(
+ defaultRate,
+ );
});
});