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(chatgpt-client.js): initialize usage object with empty object instead of null (#386)

Danny Avila11b98d3d13c2
diff --git a/api/app/clients/chatgpt-client.js b/api/app/clients/chatgpt-client.js
index dcc56e7ce7..4ce5ee67e9 100644
--- a/api/app/clients/chatgpt-client.js
+++ b/api/app/clients/chatgpt-client.js
@@ -68,13 +68,11 @@ const askClient = async ({
...(parentMessageId && conversationId ? { parentMessageId, conversationId } : {})
};
- let usage = null;
+ let usage = {};
let enc = null;
try {
enc = encoding_for_model(tiktokenModels.has(model) ? model : 'gpt-3.5-turbo');
- usage = {
- prompt_tokens: (enc.encode(promptText)).length + (enc.encode(text)).length,
- }
+ usage.prompt_tokens = (enc.encode(promptText)).length + (enc.encode(text)).length;
} catch (e) {
console.log('Error encoding prompt text', e);
}