MCPcopy
hub / github.com/coder/mux / getTokenizerForModel

Function getTokenizerForModel

src/node/utils/main/tokenizer.ts:203–219  ·  view source on GitHub ↗
(
  modelString: string,
  metadataModelOverride?: string
)

Source from the content-addressed store, hash-verified

201}
202
203export async function getTokenizerForModel(
204 modelString: string,
205 metadataModelOverride?: string
206): Promise<Tokenizer> {
207 if (shouldUseApproxTokenizer()) {
208 return getApproxTokenizer();
209 }
210
211 const resolvedModel = metadataModelOverride ?? modelString;
212 const modelName = resolveModelName(resolvedModel);
213 const encodingName = await resolveEncoding(modelName);
214
215 return {
216 encoding: encodingName,
217 countTokens: (input: string) => countTokensInternal(modelName, input),
218 };
219}
220
221export function countTokens(modelString: string, text: string): Promise<number> {
222 if (shouldUseApproxTokenizer()) {

Callers 8

calculateTokenStatsFunction · 0.90
tokenizer.test.tsFile · 0.90
setModelMethod · 0.90
truncateHistoryMethod · 0.90
buildStreamSystemContextFunction · 0.90
streamMessageMethod · 0.90
tokenizeWithMockModelFunction · 0.90

Calls 5

shouldUseApproxTokenizerFunction · 0.85
getApproxTokenizerFunction · 0.85
resolveModelNameFunction · 0.85
resolveEncodingFunction · 0.85
countTokensInternalFunction · 0.85

Tested by

no test coverage detected