mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
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:
parent
4f17e69f1b
commit
11b98d3d13
1 changed files with 2 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue