From c5dad20fc41d8cf006df7e418eeb7a508dd815d8 Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Sun, 2 Feb 2025 12:00:01 +0900 Subject: [PATCH 1/8] add killswitch for banned strings --- public/index.html | 21 +++++++++++++---- public/scripts/textgen-settings.js | 37 ++++++++++++++++++++++++++++++ public/style.css | 3 ++- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index ee15ea62e..5d27a19b5 100644 --- a/public/index.html +++ b/public/index.html @@ -1621,10 +1621,23 @@

-

- Banned Tokens/Strings -
-

+ + + + +

+ + + + Banned Tokens/Strings + +
+

+ +
diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 29bce0858..d79dee667 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -182,6 +182,7 @@ const settings = { grammar_string: '', json_schema: {}, banned_tokens: '', + sendBannedTokens: true, sampler_priority: OOBA_DEFAULT_ORDER, samplers: LLAMACPP_DEFAULT_ORDER, samplers_priorities: APHRODITE_DEFAULT_ORDER, @@ -274,6 +275,7 @@ export const setting_names = [ 'grammar_string', 'json_schema', 'banned_tokens', + 'sendBannedTokens', 'ignore_eos_token', 'spaces_between_special_tokens', 'speculative_ngram', @@ -452,6 +454,22 @@ function getCustomTokenBans() { }; } +async function enableBannedStringsKillSwitch() { + $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', true); + $('#bannedStringsKillSwitch_label').find('.menu_button').addClass('toggleEnabled').prop('title', 'Banned tokens/strings are being sent into the request.'); + settings.sendBannedTokens = true; + saveSettingsDebounced(); + return ''; +} + +async function disableBannedStringsKillSwitch() { + $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', false); + $('#bannedStringsKillSwitch_label').find('.menu_button').removeClass('toggleEnabled').prop('title', 'Banned tokens/strings are NOT being sent into the request.'); + settings.sendBannedTokens = false; + saveSettingsDebounced(); + return ''; +} + /** * Calculates logit bias object from the logit bias list. * @returns {object} Logit bias object @@ -594,6 +612,16 @@ function sortAphroditeItemsByOrder(orderArray) { } jQuery(function () { + + $('#bannedStringsKillSwitch_textgenerationwebui').on('change', function () { + const checked = $(this).prop('checked'); + if (checked) { + enableBannedStringsKillSwitch(); + } else { + disableBannedStringsKillSwitch(); + } + }); + $('#koboldcpp_order').sortable({ delay: getSortableDelay(), stop: function () { @@ -927,6 +955,11 @@ function setSettingByName(setting, value, trigger) { return; } + if ('sendBannedTokens' === setting) { + $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', value).trigger('change'); + return; + } + const isCheckbox = $(`#${setting}_textgenerationwebui`).attr('type') == 'checkbox'; const isText = $(`#${setting}_textgenerationwebui`).attr('type') == 'text' || $(`#${setting}_textgenerationwebui`).is('textarea'); if (isCheckbox) { @@ -1461,5 +1494,9 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, } } + //last check before sending sampler params, strip banned strings if toggled off. + const sendBannedStrings = $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked'); + if (!sendBannedStrings) { delete params.banned_strings; } + return params; } diff --git a/public/style.css b/public/style.css index fc2a4728a..cf0ea18af 100644 --- a/public/style.css +++ b/public/style.css @@ -2816,7 +2816,8 @@ select option:not(:checked) { } #instruct_enabled_label .menu_button:not(.toggleEnabled), -#sysprompt_enabled_label .menu_button:not(.toggleEnabled) { +#sysprompt_enabled_label .menu_button:not(.toggleEnabled), +#bannedStringsKillSwitch_label .menu_button:not(.toggleEnabled) { color: Red; } From 412d638e9e7335b9e1416cf512c3af5bb6469959 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 13 Feb 2025 22:07:36 +0200 Subject: [PATCH 2/8] Text Completion: Add global banned strings list --- public/index.html | 9 +++++++++ public/scripts/preset-manager.js | 1 + public/scripts/textgen-settings.js | 7 +++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index d46dab4fd..c276f29e4 100644 --- a/public/index.html +++ b/public/index.html @@ -1625,6 +1625,15 @@ Banned Tokens/Strings
+
+ Global list +
+
+ +
+
+ Preset-specific list +
diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index 0d7d3c133..4a21efa9e 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -587,6 +587,7 @@ class PresetManager { 'derived', 'generic_model', 'include_reasoning', + 'global_banned_tokens', ]; const settings = Object.assign({}, getSettingsByApiId(this.apiId)); diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 50c630841..392e33546 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -182,6 +182,7 @@ const settings = { grammar_string: '', json_schema: {}, banned_tokens: '', + global_banned_tokens: '', sampler_priority: OOBA_DEFAULT_ORDER, samplers: LLAMACPP_DEFAULT_ORDER, samplers_priorities: APHRODITE_DEFAULT_ORDER, @@ -274,6 +275,7 @@ export const setting_names = [ 'grammar_string', 'json_schema', 'banned_tokens', + 'global_banned_tokens', 'ignore_eos_token', 'spaces_between_special_tokens', 'speculative_ngram', @@ -404,8 +406,9 @@ function getCustomTokenBans() { const tokenizer = getTokenizerForTokenIds(); const banned_tokens = []; const banned_strings = []; - const sequences = settings.banned_tokens - .split('\n') + const sequences = [] + .concat(settings.banned_tokens.split('\n')) + .concat(settings.global_banned_tokens.split('\n')) .concat(textgenerationwebui_banned_in_macros) .filter(x => x.length > 0) .filter(onlyUnique); From 8a4cf86b6560106026f28ba6ba0f8ca8d07ba306 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 15 Feb 2025 00:28:38 +0200 Subject: [PATCH 3/8] Integrate killswitch into the block --- public/css/toggle-dependent.css | 4 ++++ public/index.html | 34 +++++++++++++++++------------- public/scripts/preset-manager.js | 1 + public/scripts/textgen-settings.js | 9 ++++---- public/style.css | 2 +- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/public/css/toggle-dependent.css b/public/css/toggle-dependent.css index 967aa55e6..59c2e9a28 100644 --- a/public/css/toggle-dependent.css +++ b/public/css/toggle-dependent.css @@ -493,3 +493,7 @@ label[for="trim_spaces"]:not(:has(input:checked)) small { #mistralai_other_models:empty { display: none; } + +#banned_tokens_block_ooba:not(:has(#send_banned_tokens_textgenerationwebui:checked)) #banned_tokens_controls_ooba { + filter: brightness(0.5); +} diff --git a/public/index.html b/public/index.html index d1a6db538..54a9c143f 100644 --- a/public/index.html +++ b/public/index.html @@ -1621,30 +1621,34 @@

-

+
+
+ Banned Tokens/Strings +
+
- Banned Tokens/Strings -
-

-
- Global list
-
- -
-
- Preset-specific list -
-
- +
+
+ Global list +
+
+ +
+
+ Preset-specific list +
+
+ +
- Logit Bias + Logit Bias
Add diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js index 4a21efa9e..14991900f 100644 --- a/public/scripts/preset-manager.js +++ b/public/scripts/preset-manager.js @@ -588,6 +588,7 @@ class PresetManager { 'generic_model', 'include_reasoning', 'global_banned_tokens', + 'send_banned_tokens', ]; const settings = Object.assign({}, getSettingsByApiId(this.apiId)); diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 027fca9fb..828a9b03e 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -399,7 +399,7 @@ function getTokenizerForTokenIds() { * @returns {TokenBanResult} String with comma-separated banned token IDs */ function getCustomTokenBans() { - if (!settings.banned_tokens && !textgenerationwebui_banned_in_macros.length) { + if (!settings.send_banned_tokens || (!settings.banned_tokens && !textgenerationwebui_banned_in_macros.length)) { return { banned_tokens: '', banned_strings: [], @@ -616,9 +616,8 @@ function sortAphroditeItemsByOrder(orderArray) { } jQuery(function () { - - $('#bannedStringsKillSwitch_textgenerationwebui').on('change', function () { - const checked = $(this).prop('checked'); + $('#send_banned_tokens_textgenerationwebui').on('change', function () { + const checked = !!$(this).prop('checked'); if (checked) { enableBannedStringsKillSwitch(); } else { @@ -966,7 +965,7 @@ function setSettingByName(setting, value, trigger) { $(`#${setting}_textgenerationwebui`).prop('checked', val); if ('send_banned_tokens' === setting) { - $('#send_banned_tokens_textgenerationwebui').trigger('change'); + $(`#${setting}_textgenerationwebui`).trigger('change'); } } else if (isText) { diff --git a/public/style.css b/public/style.css index 1aac652f2..5ae78dc1c 100644 --- a/public/style.css +++ b/public/style.css @@ -2876,7 +2876,7 @@ select option:not(:checked) { #instruct_enabled_label .menu_button:not(.toggleEnabled), #sysprompt_enabled_label .menu_button:not(.toggleEnabled), -#bannedStringsKillSwitch_label .menu_button:not(.toggleEnabled) { +#send_banned_tokens_label .menu_button:not(.toggleEnabled) { color: Red; } From c37c9051a62abc18d7f873dd010ac0ab4981e492 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 15 Feb 2025 00:34:07 +0200 Subject: [PATCH 4/8] Fix bug when only global bans are defined --- public/scripts/textgen-settings.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 828a9b03e..72d75a7f5 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -399,7 +399,7 @@ function getTokenizerForTokenIds() { * @returns {TokenBanResult} String with comma-separated banned token IDs */ function getCustomTokenBans() { - if (!settings.send_banned_tokens || (!settings.banned_tokens && !textgenerationwebui_banned_in_macros.length)) { + if (!settings.send_banned_tokens || (!settings.banned_tokens && !settings.global_banned_tokens && !textgenerationwebui_banned_in_macros.length)) { return { banned_tokens: '', banned_strings: [], @@ -460,7 +460,7 @@ function getCustomTokenBans() { async function enableBannedStringsKillSwitch() { $('#send_banned_tokens_textgenerationwebui').prop('checked', true); - $('#send_banned_tokens_label').find('.menu_button').addClass('toggleEnabled').prop('title', t`Banned tokens/strings are being sent into the request.`); + $('#send_banned_tokens_label').find('.menu_button').addClass('toggleEnabled').prop('title', t`Banned tokens/strings are being sent in the request.`); settings.send_banned_tokens = true; saveSettingsDebounced(); return ''; @@ -468,7 +468,7 @@ async function enableBannedStringsKillSwitch() { async function disableBannedStringsKillSwitch() { $('#send_banned_tokens_textgenerationwebui').prop('checked', false); - $('#send_banned_tokens_label').find('.menu_button').removeClass('toggleEnabled').prop('title', t`Banned tokens/strings are NOT being sent into the request.`); + $('#send_banned_tokens_label').find('.menu_button').removeClass('toggleEnabled').prop('title', t`Banned tokens/strings are NOT being sent in the request.`); settings.send_banned_tokens = false; saveSettingsDebounced(); return ''; From c87e203b4a6840cf4a0e448dd6108e9f6597e735 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 15 Feb 2025 12:37:48 +0200 Subject: [PATCH 5/8] Refactor banned strings kill switch functions into a single toggle function --- public/scripts/textgen-settings.js | 31 +++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 72d75a7f5..021bf1697 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -458,22 +458,18 @@ function getCustomTokenBans() { }; } -async function enableBannedStringsKillSwitch() { - $('#send_banned_tokens_textgenerationwebui').prop('checked', true); - $('#send_banned_tokens_label').find('.menu_button').addClass('toggleEnabled').prop('title', t`Banned tokens/strings are being sent in the request.`); - settings.send_banned_tokens = true; +/** + * Sets the banned strings kill switch toggle. + * @param {boolean} isEnabled Kill switch state + * @param {string} title Label title + */ +function toggleBannedStringsKillSwitch(isEnabled, title) { + $('#send_banned_tokens_textgenerationwebui').prop('checked', isEnabled); + $('#send_banned_tokens_label').find('.menu_button').toggleClass('toggleEnabled', isEnabled).prop('title', title); + settings.send_banned_tokens = isEnabled; saveSettingsDebounced(); return ''; } - -async function disableBannedStringsKillSwitch() { - $('#send_banned_tokens_textgenerationwebui').prop('checked', false); - $('#send_banned_tokens_label').find('.menu_button').removeClass('toggleEnabled').prop('title', t`Banned tokens/strings are NOT being sent in the request.`); - settings.send_banned_tokens = false; - saveSettingsDebounced(); - return ''; -} - /** * Calculates logit bias object from the logit bias list. * @returns {object} Logit bias object @@ -618,11 +614,10 @@ function sortAphroditeItemsByOrder(orderArray) { jQuery(function () { $('#send_banned_tokens_textgenerationwebui').on('change', function () { const checked = !!$(this).prop('checked'); - if (checked) { - enableBannedStringsKillSwitch(); - } else { - disableBannedStringsKillSwitch(); - } + toggleBannedStringsKillSwitch(checked, + checked + ? t`Banned tokens/strings are being sent in the request.` + : t`Banned tokens/strings are NOT being sent in the request.`); }); $('#koboldcpp_order').sortable({ From 23f0b6ed096fd838f24fe68cc33043afee5a8deb Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 15 Feb 2025 12:38:45 +0200 Subject: [PATCH 6/8] Add a blank line --- public/scripts/textgen-settings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 021bf1697..464561275 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -470,6 +470,7 @@ function toggleBannedStringsKillSwitch(isEnabled, title) { saveSettingsDebounced(); return ''; } + /** * Calculates logit bias object from the logit bias list. * @returns {object} Logit bias object From 1f41124844fde3917595788dcbaf665a8d7a91ce Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 16 Feb 2025 02:13:08 +0200 Subject: [PATCH 7/8] Remove pointless return --- public/scripts/textgen-settings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 464561275..7fefed1d9 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -468,7 +468,6 @@ function toggleBannedStringsKillSwitch(isEnabled, title) { $('#send_banned_tokens_label').find('.menu_button').toggleClass('toggleEnabled', isEnabled).prop('title', title); settings.send_banned_tokens = isEnabled; saveSettingsDebounced(); - return ''; } /** From 59928d37ffdd82b512010c034d4d43e73d1d8bb1 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 16 Feb 2025 02:16:21 +0200 Subject: [PATCH 8/8] Add common togglable class for coloring buttons --- public/index.html | 6 +++--- public/style.css | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/public/index.html b/public/index.html index 54a9c143f..b6a3e6557 100644 --- a/public/index.html +++ b/public/index.html @@ -1628,7 +1628,7 @@
@@ -3534,7 +3534,7 @@
@@ -3712,7 +3712,7 @@
diff --git a/public/style.css b/public/style.css index 19cf020d5..ff585ca65 100644 --- a/public/style.css +++ b/public/style.css @@ -2879,10 +2879,8 @@ select option:not(:checked) { color: var(--active) !important; } -#instruct_enabled_label .menu_button:not(.toggleEnabled), -#sysprompt_enabled_label .menu_button:not(.toggleEnabled), -#send_banned_tokens_label .menu_button:not(.toggleEnabled) { - color: Red; +.menu_button.togglable:not(.toggleEnabled) { + color: red; } .displayBlock {