feat: use API-based token counting for 100% accuracy
Switch from local estimation (gpt-tokenizer) to API-based counting via Google Cloud Code API for accurate token counts. Falls back to local estimation if API call fails.
This commit is contained in:
@@ -278,7 +278,7 @@ export function createCountTokensHandler(accountManager) {
|
|||||||
const result = await countTokens(
|
const result = await countTokens(
|
||||||
{ messages, model, system, tools, tool_choice, thinking },
|
{ messages, model, system, tools, tool_choice, thinking },
|
||||||
accountManager,
|
accountManager,
|
||||||
{ useAPI: false } // Default to local estimation for speed
|
{ useAPI: true } // Use API for accurate token counting
|
||||||
);
|
);
|
||||||
|
|
||||||
res.json(result);
|
res.json(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user