mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01: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 } : {})
|
...(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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue