mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-29 15:38:01 -05:00
14 lines
380 B
TypeScript
14 lines
380 B
TypeScript
import cl100k_base from '@dqbd/tiktoken/encoders/cl100k_base.json';
|
|
import { Tiktoken } from '@dqbd/tiktoken/lite';
|
|
|
|
export function tokenCount(content: string): number {
|
|
const encoding = new Tiktoken(
|
|
cl100k_base.bpe_ranks,
|
|
cl100k_base.special_tokens,
|
|
cl100k_base.pat_str
|
|
);
|
|
const tokens = encoding.encode(content);
|
|
encoding.free();
|
|
return tokens.length;
|
|
}
|