From 6804e4c679ee9f53bf8dbf6209105a2b9785c6a1 Mon Sep 17 00:00:00 2001 From: kingbri Date: Fri, 10 May 2024 23:19:57 -0400 Subject: [PATCH 1/3] Index: Expose min_tokens for TabbyAPI Now supports the minimum amount of tokens to generate. Signed-off-by: kingbri --- public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index a515020d1..ec9b8f7a1 100644 --- a/public/index.html +++ b/public/index.html @@ -1239,7 +1239,7 @@ -
+
Min Length From 62faddac8d1272507b678c76ebc7c150487bf062 Mon Sep 17 00:00:00 2001 From: kingbri Date: Sat, 11 May 2024 00:58:29 -0400 Subject: [PATCH 2/3] Textgen: Add banned_strings TabbyAPI supports the ability to ban the presence of strings during a generation. Add this support in SillyTavern by handling lines enclosed in quotes as a special case. Signed-off-by: kingbri --- public/scripts/textgen-settings.js | 31 ++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 588a52fb5..ed1065935 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -328,15 +328,20 @@ function getTokenizerForTokenIds() { } /** - * @returns {string} String with comma-separated banned token IDs + * @typedef {{banned_tokens: string, banned_strings: string[]}} TokenBanResult + * @returns {TokenBanResult} String with comma-separated banned token IDs */ function getCustomTokenBans() { if (!settings.banned_tokens && !textgenerationwebui_banned_in_macros.length) { - return ''; + return { + banned_tokens: '', + banned_strings: [], + }; } const tokenizer = getTokenizerForTokenIds(); - const result = []; + const banned_tokens = []; + const banned_strings = []; const sequences = settings.banned_tokens .split('\n') .concat(textgenerationwebui_banned_in_macros) @@ -358,24 +363,31 @@ function getCustomTokenBans() { const tokens = JSON.parse(line); if (Array.isArray(tokens) && tokens.every(t => Number.isInteger(t))) { - result.push(...tokens); + banned_tokens.push(...tokens); } else { throw new Error('Not an array of integers'); } } catch (err) { console.log(`Failed to parse bad word token list: ${line}`, err); } + } else if (line.startsWith('"') && line.endsWith('"')) { + // Remove the enclosing quotes + + banned_strings.push(line.slice(1, -1)) } else { try { const tokens = getTextTokens(tokenizer, line); - result.push(...tokens); + banned_tokens.push(...tokens); } catch { console.log(`Could not tokenize raw text: ${line}`); } } } - return result.filter(onlyUnique).map(x => String(x)).join(','); + return { + banned_tokens: banned_tokens.filter(onlyUnique).map(x => String(x)).join(','), + banned_strings: banned_strings, + }; } /** @@ -987,6 +999,8 @@ export function isJsonSchemaSupported() { export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, isContinue, cfgValues, type) { const canMultiSwipe = !isContinue && !isImpersonate && type !== 'quiet'; + const {banned_tokens, banned_strings} = getCustomTokenBans(); + let params = { 'prompt': finalPrompt, 'model': getTextGenModel(), @@ -1033,8 +1047,9 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, 'mirostat_tau': settings.mirostat_tau, 'mirostat_eta': settings.mirostat_eta, 'custom_token_bans': [APHRODITE, MANCER].includes(settings.type) ? - toIntArray(getCustomTokenBans()) : - getCustomTokenBans(), + toIntArray(banned_tokens) : + banned_tokens, + 'banned_strings': banned_strings, 'api_type': settings.type, 'api_server': getTextGenServer(), 'legacy_api': settings.legacy_api && (settings.type === OOBA || settings.type === APHRODITE), From 27ccc6b09056d385db83c7a341e2ed0cf86d32bc Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 11 May 2024 11:38:22 +0300 Subject: [PATCH 3/3] Minor stylistic changes --- public/scripts/textgen-settings.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index ed1065935..8cd76769c 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -709,10 +709,7 @@ jQuery(function () { $(`#${id}_counter_textgenerationwebui`).val(value); settings[id] = value; //special handling for vLLM/Aphrodite using -1 as disabled instead of 0 - if ($(this).attr('id') === 'top_k_textgenerationwebui' && - (settings.type === textgen_types.VLLM || - settings.type === textgen_types.APHRODITE) && - value === 0) { + if ($(this).attr('id') === 'top_k_textgenerationwebui' && [INFERMATICAI, APHRODITE, VLLM].includes(settings.type) && value === 0) { settings[id] = -1; $(this).val(-1); } @@ -999,7 +996,7 @@ export function isJsonSchemaSupported() { export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, isContinue, cfgValues, type) { const canMultiSwipe = !isContinue && !isImpersonate && type !== 'quiet'; - const {banned_tokens, banned_strings} = getCustomTokenBans(); + const { banned_tokens, banned_strings } = getCustomTokenBans(); let params = { 'prompt': finalPrompt,