MCPcopy Create free account
hub / github.com/Noumena-Network/code / roughTokenCountEstimationForContent

Function roughTokenCountEstimationForContent

src/services/tokenEstimation.ts:378–396  ·  view source on GitHub ↗
(
  content:
    | string
    | Array<Anthropic.ContentBlock>
    | Array<Anthropic.ContentBlockParam>
    | undefined,
)

Source from the content-addressed store, hash-verified

376}
377
378function roughTokenCountEstimationForContent(
379 content:
380 | string
381 | Array<Anthropic.ContentBlock>
382 | Array<Anthropic.ContentBlockParam>
383 | undefined,
384): number {
385 if (!content) {
386 return 0
387 }
388 if (typeof content === 'string') {
389 return roughTokenCountEstimation(content)
390 }
391 let totalTokens = 0
392 for (const block of content) {
393 totalTokens += roughTokenCountEstimationForBlock(block)
394 }
395 return totalTokens
396}
397
398function roughTokenCountEstimationForBlock(
399 block: string | Anthropic.ContentBlock | Anthropic.ContentBlockParam,

Calls 2

Tested by

no test coverage detected