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 @@
1621 </div>1621 </div>
1622 <div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p">1622 <div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p">
1623 <hr class="width100p">1623 <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>
1626 <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>1637 <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>
1627 </h4>1638 </h4>
1639
1640 </span>
1628 <div class="wide100p">1641 <div class="wide100p">
1629 <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>1642 <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>
1630 </div>1643 </div>
public/scripts/textgen-settings.js+37 -0
@@ -182,6 +182,7 @@ const settings = {
182 grammar_string: '',182 grammar_string: '',
183 json_schema: {},183 json_schema: {},
184 banned_tokens: '',184 banned_tokens: '',
185 sendBannedTokens: true,
185 sampler_priority: OOBA_DEFAULT_ORDER,186 sampler_priority: OOBA_DEFAULT_ORDER,
186 samplers: LLAMACPP_DEFAULT_ORDER,187 samplers: LLAMACPP_DEFAULT_ORDER,
187 samplers_priorities: APHRODITE_DEFAULT_ORDER,188 samplers_priorities: APHRODITE_DEFAULT_ORDER,
@@ -274,6 +275,7 @@ export const setting_names = [
274 'grammar_string',275 'grammar_string',
275 'json_schema',276 'json_schema',
276 'banned_tokens',277 'banned_tokens',
278 'sendBannedTokens',
277 'ignore_eos_token',279 'ignore_eos_token',
278 'spaces_between_special_tokens',280 'spaces_between_special_tokens',
279 'speculative_ngram',281 'speculative_ngram',
@@ -452,6 +454,22 @@ function getCustomTokenBans() {
452 };454 };
453}455}
454456
457async 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
465async 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
455/**473/**
456 * Calculates logit bias object from the logit bias list.474 * Calculates logit bias object from the logit bias list.
457 * @returns {object} Logit bias object475 * @returns {object} Logit bias object
@@ -594,6 +612,16 @@ function sortAphroditeItemsByOrder(orderArray) {
594}612}
595613
596jQuery(function () {614jQuery(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
597 $('#koboldcpp_order').sortable({625 $('#koboldcpp_order').sortable({
598 delay: getSortableDelay(),626 delay: getSortableDelay(),
599 stop: function () {627 stop: function () {
@@ -927,6 +955,11 @@ function setSettingByName(setting, value, trigger) {
927 return;955 return;
928 }956 }
929957
958 if ('sendBannedTokens' === setting) {
959 $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', value).trigger('change');
960 return;
961 }
962
930 const isCheckbox = $(`#${setting}_textgenerationwebui`).attr('type') == 'checkbox';963 const isCheckbox = $(`#${setting}_textgenerationwebui`).attr('type') == 'checkbox';
931 const isText = $(`#${setting}_textgenerationwebui`).attr('type') == 'text' || $(`#${setting}_textgenerationwebui`).is('textarea');964 const isText = $(`#${setting}_textgenerationwebui`).attr('type') == 'text' || $(`#${setting}_textgenerationwebui`).is('textarea');
932 if (isCheckbox) {965 if (isCheckbox) {
@@ -1461,5 +1494,9 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
1461 }1494 }
1462 }1495 }
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
1464 return params;1501 return params;
1465}1502}
public/style.css+2 -1
@@ -2816,7 +2816,8 @@ select option:not(:checked) {
2816}2816}
28172817
2818#instruct_enabled_label .menu_button:not(.toggleEnabled),2818#instruct_enabled_label .menu_button:not(.toggleEnabled),
2819#sysprompt_enabled_label .menu_button:not(.toggleEnabled) {2819#sysprompt_enabled_label .menu_button:not(.toggleEnabled),
2820#bannedStringsKillSwitch_label .menu_button:not(.toggleEnabled) {
2820 color: Red;2821 color: Red;
2821}2822}
28222823