add killswitch for banned strings
| @@ -1621,10 +1621,23 @@ | ||
| 1621 | 1621 | </div> |
| 1622 | 1622 | <div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p"> |
| 1623 | 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 | 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. Unquoted text will be tokenized in the back end and banned as tokens. [token ids] will be banned as-is. Most tokens have a leading space. Use token counter (with the correct tokenizer selected first!) if you are unsure. Enclose text in double quotes to ban the entire string as a set. Quoted Strings and [Token ids] must be on their own line."></div> |
| 1627 | 1638 | </h4> |
| 1639 | + | |
| 1640 | + </span> | |
| 1628 | 1641 | <div class="wide100p"> |
| 1629 | 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 [420, 69, 1337] "Some verbatim string"'></textarea> |
| 1630 | 1643 | </div> |
| @@ -182,6 +182,7 @@ const settings = { | ||
| 182 | 182 | grammar_string: '', |
| 183 | 183 | json_schema: {}, |
| 184 | 184 | banned_tokens: '', |
| 185 | + sendBannedTokens: true, | |
| 185 | 186 | sampler_priority: OOBA_DEFAULT_ORDER, |
| 186 | 187 | samplers: LLAMACPP_DEFAULT_ORDER, |
| 187 | 188 | samplers_priorities: APHRODITE_DEFAULT_ORDER, |
| @@ -274,6 +275,7 @@ export const setting_names = [ | ||
| 274 | 275 | 'grammar_string', |
| 275 | 276 | 'json_schema', |
| 276 | 277 | 'banned_tokens', |
| 278 | + 'sendBannedTokens', | |
| 277 | 279 | 'ignore_eos_token', |
| 278 | 280 | 'spaces_between_special_tokens', |
| 279 | 281 | 'speculative_ngram', |
| @@ -452,6 +454,22 @@ function getCustomTokenBans() { | ||
| 452 | 454 | }; |
| 453 | 455 | } |
| 454 | 456 | |
| 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 | + | |
| 455 | 473 | /** |
| 456 | 474 | * Calculates logit bias object from the logit bias list. |
| 457 | 475 | * @returns {object} Logit bias object |
| @@ -594,6 +612,16 @@ function sortAphroditeItemsByOrder(orderArray) { | ||
| 594 | 612 | } |
| 595 | 613 | |
| 596 | 614 | jQuery(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 | 625 | $('#koboldcpp_order').sortable({ |
| 598 | 626 | delay: getSortableDelay(), |
| 599 | 627 | stop: function () { |
| @@ -927,6 +955,11 @@ function setSettingByName(setting, value, trigger) { | ||
| 927 | 955 | return; |
| 928 | 956 | } |
| 929 | 957 | |
| 958 | + if ('sendBannedTokens' === setting) { | |
| 959 | + $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', value).trigger('change'); | |
| 960 | + return; | |
| 961 | + } | |
| 962 | + | |
| 930 | 963 | const isCheckbox = $(`#${setting}_textgenerationwebui`).attr('type') == 'checkbox'; |
| 931 | 964 | const isText = $(`#${setting}_textgenerationwebui`).attr('type') == 'text' || $(`#${setting}_textgenerationwebui`).is('textarea'); |
| 932 | 965 | if (isCheckbox) { |
| @@ -1461,5 +1494,9 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, | ||
| 1461 | 1494 | } |
| 1462 | 1495 | } |
| 1463 | 1496 | |
| 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 | 1501 | return params; |
| 1465 | 1502 | } |
| @@ -2816,7 +2816,8 @@ select option:not(:checked) { | ||
| 2816 | 2816 | } |
| 2817 | 2817 | |
| 2818 | 2818 | #instruct_enabled_label .menu_button:not(.toggleEnabled), |
| 2819 | 2819 | #sysprompt_enabled_label .menu_button:not(.toggleEnabled) {, |
| 2820 | +#bannedStringsKillSwitch_label .menu_button:not(.toggleEnabled) { | |
| 2820 | 2821 | color: Red; |
| 2821 | 2822 | } |
| 2822 | 2823 | |