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] 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; }