add killswitch for banned strings

c5dad20fc41d8cf006df7e418eeb7a508dd815d8

RossAscends <124905043+RossAscends@users.noreply.github.com>

3 files changed, +54 -3Showing whitespace changes
public/index.html+15 -2
@@ -1621,10 +1621,23 @@
16211621 </div>
16221622 <div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p">
16231623 <hr class="width100p">
1624- <h4 class="range-block-title justifyCenter">
1624+
1625- <span data-i18n="Banned Tokens">Banned Tokens/Strings</span>
1625+ <span class="flex-container flexnowrap">
1626+
1627+
1628+ <h4 class="range-block-title justifyCenter flex-container">
1629+ <label id="bannedStringsKillSwitch_label" for="bannedStringsKillSwitch_textgenerationwebui" class="checkbox_label">
1630+ <input id="bannedStringsKillSwitch_textgenerationwebui" type="checkbox" style="display:none;" />
1631+ <small><i class="fa-solid fa-power-off menu_button margin0"></i></small>
1632+ </label>
1633+ <span data-i18n="Banned Tokens">
1634+
1635+ Banned Tokens/Strings
1636+ </span>
16261637 <div class="margin5 fa-solid fa-circle-info opacity50p " data-i18n="[title]LLaMA / Mistral / Yi models only" title="Enter sequences you don't want to appear in the output.&#13;Unquoted text will be tokenized in the back end and banned as tokens.&#13;[token ids] will be banned as-is.&#13;Most tokens have a leading space. Use token counter (with the correct tokenizer selected first!) if you are unsure.&#13;Enclose text in double quotes to ban the entire string as a set.&#13;Quoted Strings and [Token ids] must be on their own line."></div>
16271638 </h4>
1639+
1640+ </span>
16281641 <div class="wide100p">
16291642 <textarea id="banned_tokens_textgenerationwebui" class="text_pole textarea_compact" name="banned_tokens_textgenerationwebui" rows="3" data-i18n="[placeholder]Example: some text [42, 69, 1337]" placeholder='some text as tokens&#10;[420, 69, 1337]&#10;"Some verbatim string"'></textarea>
16301643 </div>
public/scripts/textgen-settings.js+37 -0
@@ -182,6 +182,7 @@ const settings = {
182182 grammar_string: '',
183183 json_schema: {},
184184 banned_tokens: '',
185+ sendBannedTokens: true,
185186 sampler_priority: OOBA_DEFAULT_ORDER,
186187 samplers: LLAMACPP_DEFAULT_ORDER,
187188 samplers_priorities: APHRODITE_DEFAULT_ORDER,
@@ -274,6 +275,7 @@ export const setting_names = [
274275 'grammar_string',
275276 'json_schema',
276277 'banned_tokens',
278+ 'sendBannedTokens',
277279 'ignore_eos_token',
278280 'spaces_between_special_tokens',
279281 'speculative_ngram',
@@ -452,6 +454,22 @@ function getCustomTokenBans() {
452454 };
453455}
454456
457+async function enableBannedStringsKillSwitch() {
458+ $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', true);
459+ $('#bannedStringsKillSwitch_label').find('.menu_button').addClass('toggleEnabled').prop('title', 'Banned tokens/strings are being sent into the request.');
460+ settings.sendBannedTokens = true;
461+ saveSettingsDebounced();
462+ return '';
463+}
464+
465+async function disableBannedStringsKillSwitch() {
466+ $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', false);
467+ $('#bannedStringsKillSwitch_label').find('.menu_button').removeClass('toggleEnabled').prop('title', 'Banned tokens/strings are NOT being sent into the request.');
468+ settings.sendBannedTokens = false;
469+ saveSettingsDebounced();
470+ return '';
471+}
472+
455473/**
456474 * Calculates logit bias object from the logit bias list.
457475 * @returns {object} Logit bias object
@@ -594,6 +612,16 @@ function sortAphroditeItemsByOrder(orderArray) {
594612}
595613
596614jQuery(function () {
615+
616+ $('#bannedStringsKillSwitch_textgenerationwebui').on('change', function () {
617+ const checked = $(this).prop('checked');
618+ if (checked) {
619+ enableBannedStringsKillSwitch();
620+ } else {
621+ disableBannedStringsKillSwitch();
622+ }
623+ });
624+
597625 $('#koboldcpp_order').sortable({
598626 delay: getSortableDelay(),
599627 stop: function () {
@@ -927,6 +955,11 @@ function setSettingByName(setting, value, trigger) {
927955 return;
928956 }
929957
958+ if ('sendBannedTokens' === setting) {
959+ $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', value).trigger('change');
960+ return;
961+ }
962+
930963 const isCheckbox = $(`#${setting}_textgenerationwebui`).attr('type') == 'checkbox';
931964 const isText = $(`#${setting}_textgenerationwebui`).attr('type') == 'text' || $(`#${setting}_textgenerationwebui`).is('textarea');
932965 if (isCheckbox) {
@@ -1461,5 +1494,9 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
14611494 }
14621495 }
14631496
1497+ //last check before sending sampler params, strip banned strings if toggled off.
1498+ const sendBannedStrings = $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked');
1499+ if (!sendBannedStrings) { delete params.banned_strings; }
1500+
14641501 return params;
14651502}
public/style.css+2 -1
@@ -2816,7 +2816,8 @@ select option:not(:checked) {
28162816}
28172817
28182818#instruct_enabled_label .menu_button:not(.toggleEnabled),
28192819#sysprompt_enabled_label .menu_button:not(.toggleEnabled) {,
2820+#bannedStringsKillSwitch_label .menu_button:not(.toggleEnabled) {
28202821 color: Red;
28212822}
28222823