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 } : {})
};
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);
}