mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
fix: count read API tokens as completion tokens
Co-Authored-By: sha.zhou@jina.ai <sha.zhou@jina.ai>
This commit is contained in:
@@ -74,12 +74,12 @@ export function readUrl(url: string, tracker?: TokenTracker): Promise<{ response
|
||||
|
||||
if (tracker) {
|
||||
// Track API response tokens
|
||||
tracker.trackUsage('read_api', apiTokens, TOKEN_CATEGORIES.PROMPT);
|
||||
tracker.trackUsage('read_api', apiTokens, TOKEN_CATEGORIES.ACCEPTED);
|
||||
|
||||
// Track content length tokens using the same estimation method
|
||||
if (response.data.content) {
|
||||
const contentTokens = Math.ceil(Buffer.byteLength(response.data.content, 'utf-8') / 4);
|
||||
tracker.trackUsage('read_content', contentTokens, TOKEN_CATEGORIES.PROMPT);
|
||||
tracker.trackUsage('read_content', contentTokens);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user