mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#228 Don't use a selected tokenizer for parallel prompt building of OAI prompts
This commit is contained in:
@ -73,6 +73,7 @@ import {
|
|||||||
oai_settings,
|
oai_settings,
|
||||||
is_get_status_openai,
|
is_get_status_openai,
|
||||||
openai_messages_count,
|
openai_messages_count,
|
||||||
|
getTokenCountOpenAI,
|
||||||
} from "./scripts/openai.js";
|
} from "./scripts/openai.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -368,7 +369,20 @@ $(document).ajaxError(function myErrorHandler(_, xhr) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function getTokenCount(str, padding = 0) {
|
function getTokenCount(str, padding = 0) {
|
||||||
switch (power_user.tokenizer) {
|
let tokenizerType = power_user.tokenizer;
|
||||||
|
|
||||||
|
if (main_api === 'openai') {
|
||||||
|
// For main prompt building
|
||||||
|
if (padding == power_user.token_padding) {
|
||||||
|
tokenizerType = tokenizers.NONE;
|
||||||
|
// For extensions and WI
|
||||||
|
} else {
|
||||||
|
return getTokenCountOpenAI(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (tokenizerType) {
|
||||||
case tokenizers.NONE:
|
case tokenizers.NONE:
|
||||||
return Math.ceil(str.length / CHARACTERS_PER_TOKEN_RATIO) + padding;
|
return Math.ceil(str.length / CHARACTERS_PER_TOKEN_RATIO) + padding;
|
||||||
case tokenizers.GPT3:
|
case tokenizers.GPT3:
|
||||||
|
@ -127,6 +127,11 @@ const oai_settings = {
|
|||||||
let openai_setting_names;
|
let openai_setting_names;
|
||||||
let openai_settings;
|
let openai_settings;
|
||||||
|
|
||||||
|
export function getTokenCountOpenAI(text) {
|
||||||
|
const message = { role: 'system', content: text };
|
||||||
|
return countTokens(message, true);
|
||||||
|
}
|
||||||
|
|
||||||
function validateReverseProxy() {
|
function validateReverseProxy() {
|
||||||
if (!oai_settings.reverse_proxy) {
|
if (!oai_settings.reverse_proxy) {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user