Code QuizIntermediate

Estimating Token Count for a Prompt

Approximating token count from character length before sending a prompt.

Codejavascript
// Rough estimate: ~4 characters per token for English text
function estimateTokens(text) {
  return text.length * 4;
}

const prompt = "Summarize the quarterly report.";
console.log(estimateTokens(prompt)); // used to check budget

What is the bug in this token estimate?