MCPcopy Index your code
hub / github.com/simstudioai/sim / estimateGoogleTokens

Function estimateGoogleTokens

apps/sim/lib/tokenization/estimators.ts:281–298  ·  view source on GitHub ↗

* Google Gemini-specific token estimation

(text: string)

Source from the content-addressed store, hash-verified

279 * Google Gemini-specific token estimation
280 */
281function estimateGoogleTokens(text: string): number {
282 const words = text.trim().split(/\s+/)
283 let tokenCount = 0
284
285 for (const word of words) {
286 if (word.length === 0) continue
287
288 if (word.length <= 5) {
289 tokenCount += 1
290 } else if (word.length <= 10) {
291 tokenCount += Math.ceil(word.length / 6)
292 } else {
293 tokenCount += Math.ceil(word.length / 5)
294 }
295 }
296
297 return tokenCount
298}
299
300/**
301 * Generic token estimation fallback

Callers 1

estimateTokenCountFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected