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

Function getEncoding

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

* Get or create a cached encoding for a model

(modelName: string)

Source from the content-addressed store, hash-verified

16 * Get or create a cached encoding for a model
17 */
18function getEncoding(modelName: string): Tiktoken {
19 if (encodingCache.has(modelName)) {
20 return encodingCache.get(modelName)!
21 }
22
23 try {
24 const encoding = encodingForModel(modelName as Parameters<typeof encodingForModel>[0])
25 encodingCache.set(modelName, encoding)
26 return encoding
27 } catch (error) {
28 logger.warn(`Failed to get encoding for model ${modelName}, falling back to cl100k_base`)
29 const encoding = encodingForModel('gpt-4')
30 encodingCache.set(modelName, encoding)
31 return encoding
32 }
33}
34
35if (typeof process !== 'undefined') {
36 process.on('beforeExit', () => {

Callers 3

getAccurateTokenCountFunction · 0.85
getTokenStringsFunction · 0.85
truncateToTokenLimitFunction · 0.85

Calls 3

getMethod · 0.65
setMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected