From 11b98d3d13c2cdded6b6f3d1ca5aa2366c448422 Mon Sep 17 00:00:00 2001 From: Danny Avila <110412045+danny-avila@users.noreply.github.com> Date: Fri, 26 May 2023 09:43:35 -0400 Subject: [PATCH] refactor(chatgpt-client.js): initialize usage object with empty object instead of null (#386) refactor(chatgpt-client.js): simplify usage object assignment --- api/app/clients/chatgpt-client.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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); }