@@ -4,6 +4,7 @@ import type { ModelConfig } from "@/config.js";
44import logger from "@/logger.js" ;
55
66function getTokenCount ( text : string ) : number {
7+ if ( text . length >= 12000 ) return Math . ceil ( text . length * 0.4 ) ;
78 return encode ( text ) . length ;
89}
910
@@ -31,22 +32,22 @@ function getMessageTokenCount(message: ModelMessage): number {
3132 tokens += getTokenCount ( part . text ) ;
3233 } else if ( "output" in part && part . output ) {
3334 if ( typeof part . output === "object" && "value" in part . output ) {
34- tokens += getTokenCount ( serializeContent ( part . output . value ) ) ;
35+ tokens += getTokenCount ( serializeContent ( ( part . output as any ) . value ) ) ;
3536 } else {
36- tokens += getTokenCount ( serializeContent ( part . output ) ) ;
37+ tokens += getTokenCount ( serializeContent ( ( part as any ) . output ) ) ;
3738 }
38- } else if ( "toolName" in part && typeof part . toolName === "string" ) {
39- tokens += getTokenCount ( part . toolName ) ;
39+ } else if ( "toolName" in part && typeof ( part as any ) . toolName === "string" ) {
40+ tokens += getTokenCount ( ( part as any ) . toolName as string ) ;
4041 tokens += 10 ;
41- if ( "args" in part && part . args ) {
42- tokens += getTokenCount ( serializeContent ( part . args ) ) ;
42+ if ( "args" in part && ( part as any ) . args ) {
43+ tokens += getTokenCount ( serializeContent ( ( part as any ) . args ) ) ;
4344 }
4445 } else {
45- tokens += getTokenCount ( serializeContent ( part ) ) ;
46+ tokens += getTokenCount ( serializeContent ( part as any ) ) ;
4647 }
4748 }
4849 } else {
49- tokens += getTokenCount ( serializeContent ( message . content ) ) ;
50+ tokens += getTokenCount ( serializeContent ( message . content as any ) ) ;
5051 }
5152
5253 tokens += 4 ;
0 commit comments