diff --git a/public/scripts/tokenizers.js b/public/scripts/tokenizers.js index a39be642d..59d55ba7f 100644 --- a/public/scripts/tokenizers.js +++ b/public/scripts/tokenizers.js @@ -433,6 +433,7 @@ export async function getTokenCountAsync(str, padding = undefined) { } let tokenizerType = power_user.tokenizer; + let modelHash = ''; if (main_api === 'openai') { if (padding === power_user.token_padding) { @@ -448,13 +449,17 @@ export async function getTokenCountAsync(str, padding = undefined) { tokenizerType = getTokenizerBestMatch(main_api); } + if (tokenizerType === tokenizers.API_TEXTGENERATIONWEBUI) { + modelHash = getStringHash(getTextGenModel() || online_status).toString(); + } + if (padding === undefined) { padding = 0; } const cacheObject = getTokenCacheObject(); const hash = getStringHash(str); - const cacheKey = `${tokenizerType}-${hash}+${padding}`; + const cacheKey = `${tokenizerType}-${hash}${modelHash}+${padding}`; if (typeof cacheObject[cacheKey] === 'number') { return cacheObject[cacheKey]; @@ -484,6 +489,7 @@ export function getTokenCount(str, padding = undefined) { } let tokenizerType = power_user.tokenizer; + let modelHash = ''; if (main_api === 'openai') { if (padding === power_user.token_padding) { @@ -499,13 +505,17 @@ export function getTokenCount(str, padding = undefined) { tokenizerType = getTokenizerBestMatch(main_api); } + if (tokenizerType === tokenizers.API_TEXTGENERATIONWEBUI) { + modelHash = getStringHash(getTextGenModel() || online_status).toString(); + } + if (padding === undefined) { padding = 0; } const cacheObject = getTokenCacheObject(); const hash = getStringHash(str); - const cacheKey = `${tokenizerType}-${hash}+${padding}`; + const cacheKey = `${tokenizerType}-${hash}${modelHash}+${padding}`; if (typeof cacheObject[cacheKey] === 'number') { return cacheObject[cacheKey];