refactor(chatgpt-client.js): initialize usage object with empty object instead of null (#386)

refactor(chatgpt-client.js): simplify usage object assignment
This commit is contained in:
Danny Avila 2023-05-26 09:43:35 -04:00 committed by GitHub
parent 4f17e69f1b
commit 11b98d3d13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -68,13 +68,11 @@ const askClient = async ({
...(parentMessageId && conversationId ? { parentMessageId, conversationId } : {}) ...(parentMessageId && conversationId ? { parentMessageId, conversationId } : {})
}; };
let usage = null; let usage = {};
let enc = null; let enc = null;
try { try {
enc = encoding_for_model(tiktokenModels.has(model) ? model : 'gpt-3.5-turbo'); enc = encoding_for_model(tiktokenModels.has(model) ? model : 'gpt-3.5-turbo');
usage = { usage.prompt_tokens = (enc.encode(promptText)).length + (enc.encode(text)).length;
prompt_tokens: (enc.encode(promptText)).length + (enc.encode(text)).length,
}
} catch (e) { } catch (e) {
console.log('Error encoding prompt text', e); console.log('Error encoding prompt text', e);
} }