Add model hash to TC API tokenizer cache key
| @@ -433,6 +433,7 @@ export async function getTokenCountAsync(str, padding = undefined) { | |||
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | let tokenizerType = power_user.tokenizer; | 435 | let tokenizerType = power_user.tokenizer; |
| 436 | let modelHash = ''; | ||
| 436 | 437 | ||
| 437 | if (main_api === 'openai') { | 438 | if (main_api === 'openai') { |
| 438 | if (padding === power_user.token_padding) { | 439 | if (padding === power_user.token_padding) { |
| @@ -448,13 +449,17 @@ export async function getTokenCountAsync(str, padding = undefined) { | |||
| 448 | tokenizerType = getTokenizerBestMatch(main_api); | 449 | tokenizerType = getTokenizerBestMatch(main_api); |
| 449 | } | 450 | } |
| 450 | 451 | ||
| 452 | if (tokenizerType === tokenizers.API_TEXTGENERATIONWEBUI) { | ||
| 453 | modelHash = getStringHash(getTextGenModel() || online_status).toString(); | ||
| 454 | } | ||
| 455 | |||
| 451 | if (padding === undefined) { | 456 | if (padding === undefined) { |
| 452 | padding = 0; | 457 | padding = 0; |
| 453 | } | 458 | } |
| 454 | 459 | ||
| 455 | const cacheObject = getTokenCacheObject(); | 460 | const cacheObject = getTokenCacheObject(); |
| 456 | const hash = getStringHash(str); | 461 | const hash = getStringHash(str); |
| 457 | const cacheKey = `${tokenizerType}-${hash}+${padding}`; | 462 | const cacheKey = `${tokenizerType}-${hash}${modelHash}+${padding}`; |
| 458 | 463 | ||
| 459 | if (typeof cacheObject[cacheKey] === 'number') { | 464 | if (typeof cacheObject[cacheKey] === 'number') { |
| 460 | return cacheObject[cacheKey]; | 465 | return cacheObject[cacheKey]; |
| @@ -484,6 +489,7 @@ export function getTokenCount(str, padding = undefined) { | |||
| 484 | } | 489 | } |
| 485 | 490 | ||
| 486 | let tokenizerType = power_user.tokenizer; | 491 | let tokenizerType = power_user.tokenizer; |
| 492 | let modelHash = ''; | ||
| 487 | 493 | ||
| 488 | if (main_api === 'openai') { | 494 | if (main_api === 'openai') { |
| 489 | if (padding === power_user.token_padding) { | 495 | if (padding === power_user.token_padding) { |
| @@ -499,13 +505,17 @@ export function getTokenCount(str, padding = undefined) { | |||
| 499 | tokenizerType = getTokenizerBestMatch(main_api); | 505 | tokenizerType = getTokenizerBestMatch(main_api); |
| 500 | } | 506 | } |
| 501 | 507 | ||
| 508 | if (tokenizerType === tokenizers.API_TEXTGENERATIONWEBUI) { | ||
| 509 | modelHash = getStringHash(getTextGenModel() || online_status).toString(); | ||
| 510 | } | ||
| 511 | |||
| 502 | if (padding === undefined) { | 512 | if (padding === undefined) { |
| 503 | padding = 0; | 513 | padding = 0; |
| 504 | } | 514 | } |
| 505 | 515 | ||
| 506 | const cacheObject = getTokenCacheObject(); | 516 | const cacheObject = getTokenCacheObject(); |
| 507 | const hash = getStringHash(str); | 517 | const hash = getStringHash(str); |
| 508 | const cacheKey = `${tokenizerType}-${hash}+${padding}`; | 518 | const cacheKey = `${tokenizerType}-${hash}${modelHash}+${padding}`; |
| 509 | 519 | ||
| 510 | if (typeof cacheObject[cacheKey] === 'number') { | 520 | if (typeof cacheObject[cacheKey] === 'number') { |
| 511 | return cacheObject[cacheKey]; | 521 | return cacheObject[cacheKey]; |