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