Skip to content

Commit ada1e73

Browse files
committed
allow all tokens when counting tokens
1 parent 3e47ade commit ada1e73

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

backend/src/util/token-counter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export function countTokens(text: string): number {
1111
if (cached !== undefined) {
1212
return cached
1313
}
14-
const count = Math.floor(encode(text).length * ANTHROPIC_TOKEN_FUDGE_FACTOR)
14+
const count = Math.floor(
15+
encode(text, { allowedSpecial: 'all' }).length *
16+
ANTHROPIC_TOKEN_FUDGE_FACTOR,
17+
)
1518

1619
if (text.length > 100) {
1720
// Cache only if the text is long enough to be worth it.

0 commit comments

Comments
 (0)