mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-09 17:31:19 +00:00
refactor(agents): implement token count adjustment for Claude model messages
Added a method to adjust token counts for messages processed by the Claude model, applying a correction factor to align with API expectations. This enhancement improves the accuracy of token counting, ensuring reliable functionality when interacting with the Claude model.
This commit is contained in:
parent
b58aa164dd
commit
39b8db00cd
1 changed files with 15 additions and 0 deletions
|
|
@ -1230,6 +1230,21 @@ class AgentClient extends BaseClient {
|
|||
const encoding = this.getEncoding();
|
||||
return Tokenizer.getTokenCount(text, encoding);
|
||||
}
|
||||
|
||||
/** @type {number} Anthropic message framing correction factor. */
|
||||
static CLAUDE_TOKEN_CORRECTION = 1.1;
|
||||
|
||||
/**
|
||||
* @param {object} message
|
||||
* @returns {number}
|
||||
*/
|
||||
getTokenCountForMessage(message) {
|
||||
const count = super.getTokenCountForMessage(message);
|
||||
if (this.getEncoding() === 'claude') {
|
||||
return Math.ceil(count * AgentClient.CLAUDE_TOKEN_CORRECTION);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AgentClient;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue