From 7179fc3c1aa194fa0d8a9873a48056a6584c2d10 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2025 12:06:00 +0000 Subject: [PATCH] fix: match PR #54 token counting implementation - remove token categories and use character-based estimation Co-Authored-By: sha.zhou@jina.ai --- src/app.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index fb1159f..ef86ae3 100644 --- a/src/app.ts +++ b/src/app.ts @@ -10,7 +10,6 @@ import { ChatCompletionResponse, ChatCompletionChunk, AnswerAction, - TOKEN_CATEGORIES, Model } from './types'; import fs from 'fs/promises'; @@ -446,7 +445,8 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => { res.write(`data: ${JSON.stringify(closeThinkChunk)}\n\n`); // Track error token and send error message - context.tokenTracker.trackUsage('evaluator', 1, TOKEN_CATEGORIES.REJECTED); + const estimatedTokens = Math.ceil(Buffer.byteLength(errorMessage, 'utf-8') / 4); + context.tokenTracker.trackUsage('evaluator', estimatedTokens); const errorChunk: ChatCompletionChunk = { id: requestId, object: 'chat.completion.chunk',