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

Function estimateInputTokens

apps/sim/lib/tokenization/estimators.ts:311–334  ·  view source on GitHub ↗
(
  systemPrompt?: string,
  context?: string,
  messages?: Array<{ role: string; content: string }>,
  providerId?: string
)

Source from the content-addressed store, hash-verified

309 * Estimates tokens for input content including context
310 */
311export function estimateInputTokens(
312 systemPrompt?: string,
313 context?: string,
314 messages?: Array<{ role: string; content: string }>,
315 providerId?: string
316): TokenEstimate {
317 let totalText = ''
318
319 if (systemPrompt) {
320 totalText += `${systemPrompt}\n`
321 }
322
323 if (context) {
324 totalText += `${context}\n`
325 }
326
327 if (messages) {
328 for (const message of messages) {
329 totalText += `${message.role}: ${message.content}\n`
330 }
331 }
332
333 return estimateTokenCount(totalText, providerId)
334}
335
336/**
337 * Estimates tokens for output content

Callers 1

calculateStreamingCostFunction · 0.90

Calls 1

estimateTokenCountFunction · 0.85

Tested by

no test coverage detected