mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 14:30:17 +08:00
fix: restore TOKEN_CATEGORIES in read.ts and jina-search.ts to match PR #54
Co-Authored-By: sha.zhou@jina.ai <sha.zhou@jina.ai>
This commit is contained in:
parent
8035028a56
commit
6d77060caa
@ -1,6 +1,6 @@
|
||||
import https from 'https';
|
||||
import { TokenTracker } from "../utils/token-tracker";
|
||||
import { SearchResponse } from '../types';
|
||||
import { SearchResponse, TOKEN_CATEGORIES } from '../types';
|
||||
import { JINA_API_KEY } from "../config";
|
||||
|
||||
export function search(query: string, tracker?: TokenTracker): Promise<{ response: SearchResponse, tokens: number }> {
|
||||
@ -63,7 +63,7 @@ export function search(query: string, tracker?: TokenTracker): Promise<{ respons
|
||||
console.log('Total URLs:', response.data.length);
|
||||
|
||||
if (tracker) {
|
||||
tracker.trackUsage('search', totalTokens);
|
||||
tracker.trackUsage('search', totalTokens, TOKEN_CATEGORIES.PROMPT);
|
||||
}
|
||||
|
||||
resolve({ response, tokens: totalTokens });
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import https from 'https';
|
||||
import { TokenTracker } from "../utils/token-tracker";
|
||||
import { ReadResponse } from '../types';
|
||||
import { ReadResponse, TOKEN_CATEGORIES } from '../types';
|
||||
import { JINA_API_KEY } from "../config";
|
||||
|
||||
export function readUrl(url: string, tracker?: TokenTracker): Promise<{ response: ReadResponse, tokens: number }> {
|
||||
@ -74,12 +74,12 @@ export function readUrl(url: string, tracker?: TokenTracker): Promise<{ response
|
||||
|
||||
if (tracker) {
|
||||
// Track API response tokens
|
||||
tracker.trackUsage('read_api', apiTokens);
|
||||
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);
|
||||
tracker.trackUsage('read_content', contentTokens, TOKEN_CATEGORIES.REASONING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user