UNPKG

@paroicms/site-generator-plugin

Version:

ParoiCMS Site Generator Plugin

9 lines (8 loc) 305 B
/** * Estimates token count based on character count. * Most LLMs use subword tokenization where 1 token is roughly 4 characters in English. */ export function estimateTokenCount(text) { // Approximate token count using character count / 4 for English text return Math.ceil(text.length / 4); }