* Anthropic Claude-specific token estimation
(text: string)
| 254 | * Anthropic Claude-specific token estimation |
| 255 | */ |
| 256 | function estimateAnthropicTokens(text: string): number { |
| 257 | const words = text.trim().split(/\s+/) |
| 258 | let tokenCount = 0 |
| 259 | |
| 260 | for (const word of words) { |
| 261 | if (word.length === 0) continue |
| 262 | |
| 263 | if (word.length <= 4) { |
| 264 | tokenCount += 1 |
| 265 | } else if (word.length <= 8) { |
| 266 | tokenCount += Math.ceil(word.length / 5) |
| 267 | } else { |
| 268 | tokenCount += Math.ceil(word.length / 4.5) |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | const newlineCount = (text.match(/\n/g) || []).length |
| 273 | tokenCount += newlineCount * 0.3 |
| 274 | |
| 275 | return tokenCount |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Google Gemini-specific token estimation |
no outgoing calls
no test coverage detected