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
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
fix(tokenizer): error handle encoding for invalid encoding data (#385)
Danny Avila4f17e69f1bde
diff --git a/api/app/clients/chatgpt-client.js b/api/app/clients/chatgpt-client.jsindex a5e9a05e6e..dcc56e7ce7 100644--- a/api/app/clients/chatgpt-client.js+++ b/api/app/clients/chatgpt-client.js@@ -68,18 +68,28 @@ const askClient = async ({...(parentMessageId && conversationId ? { parentMessageId, conversationId } : {})};- const enc = encoding_for_model(tiktokenModels.has(model) ? model : 'gpt-3.5-turbo');- const usage = {- prompt_tokens: (enc.encode(promptText)).length + (enc.encode(text)).length,+ let usage = null;+ 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,+ }+ } catch (e) {+ console.log('Error encoding prompt text', e);}const res = await client.sendMessage(text, { ...options, userId });- usage.completion_tokens = (enc.encode(res.response)).length;- usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;- return {- ...res,- usage,++ try {+ usage.completion_tokens = (enc.encode(res.response)).length;+ usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;+ res.usage = usage;+ } catch (e) {+ console.log('Error encoding response text', e);}++ return res;};module.exports = { askClient };