Add model hash to TC API tokenizer cache key

fc4fecf0fdf56b7ec13fb2ab0bffb85d715546a2

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +12 -2Showing whitespace changes
public/scripts/tokenizers.js+12 -2
@@ -433,6 +433,7 @@ export async function getTokenCountAsync(str, padding = undefined) {
433433 }
434434
435435 let tokenizerType = power_user.tokenizer;
436+ let modelHash = '';
436437
437438 if (main_api === 'openai') {
438439 if (padding === power_user.token_padding) {
@@ -448,13 +449,17 @@ export async function getTokenCountAsync(str, padding = undefined) {
448449 tokenizerType = getTokenizerBestMatch(main_api);
449450 }
450451
452+ if (tokenizerType === tokenizers.API_TEXTGENERATIONWEBUI) {
453+ modelHash = getStringHash(getTextGenModel() || online_status).toString();
454+ }
455+
451456 if (padding === undefined) {
452457 padding = 0;
453458 }
454459
455460 const cacheObject = getTokenCacheObject();
456461 const hash = getStringHash(str);
457462 const cacheKey = `${tokenizerType}-${hash}${modelHash}+${padding}`;
458463
459464 if (typeof cacheObject[cacheKey] === 'number') {
460465 return cacheObject[cacheKey];
@@ -484,6 +489,7 @@ export function getTokenCount(str, padding = undefined) {
484489 }
485490
486491 let tokenizerType = power_user.tokenizer;
492+ let modelHash = '';
487493
488494 if (main_api === 'openai') {
489495 if (padding === power_user.token_padding) {
@@ -499,13 +505,17 @@ export function getTokenCount(str, padding = undefined) {
499505 tokenizerType = getTokenizerBestMatch(main_api);
500506 }
501507
508+ if (tokenizerType === tokenizers.API_TEXTGENERATIONWEBUI) {
509+ modelHash = getStringHash(getTextGenModel() || online_status).toString();
510+ }
511+
502512 if (padding === undefined) {
503513 padding = 0;
504514 }
505515
506516 const cacheObject = getTokenCacheObject();
507517 const hash = getStringHash(str);
508518 const cacheKey = `${tokenizerType}-${hash}${modelHash}+${padding}`;
509519
510520 if (typeof cacheObject[cacheKey] === 'number') {
511521 return cacheObject[cacheKey];