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:
Devin AI 2025-02-11 12:11:11 +00:00
parent 8035028a56
commit 6d77060caa
2 changed files with 5 additions and 5 deletions

View File

@ -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 });

View File

@ -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);
}
}