Merge pull request #3477 from SillyTavern/tc-global-banlist Text Completion: Add global banned strings list
Signed| @@ -493,3 +493,7 @@ label[for="trim_spaces"]:not(:has(input:checked)) small { | ||
| 493 | 493 | #mistralai_other_models:empty { |
| 494 | 494 | display: none; |
| 495 | 495 | } |
| 496 | + | |
| 497 | +#banned_tokens_block_ooba:not(:has(#send_banned_tokens_textgenerationwebui:checked)) #banned_tokens_controls_ooba { | |
| 498 | + filter: brightness(0.5); | |
| 499 | +} | |
| @@ -1621,17 +1621,34 @@ | ||
| 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 | 1624 | <h4div class="range-block-title justifyCentertitle_restorable"> |
| 1625 | - <span data-i18n="Banned Tokens">Banned Tokens/Strings</span> | |
| 1625 | + <div> | |
| 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. 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> | |
| 1626 | + <strong data-i18n="Banned Tokens">Banned Tokens/Strings</strong> | |
| 1627 | - </h4> | |
| 1627 | + <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> | |
| 1628 | - <div class="wide100p"> | |
| 1628 | + </div> | |
| 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 [420, 69, 1337] "Some verbatim string"'></textarea> | |
| 1629 | + <label id="send_banned_tokens_label" for="send_banned_tokens_textgenerationwebui" class="checkbox_label"> | |
| 1630 | + <input id="send_banned_tokens_textgenerationwebui" type="checkbox" style="display:none;" /> | |
| 1631 | + <small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small> | |
| 1632 | + </label> | |
| 1633 | + </div> | |
| 1634 | + <div id="banned_tokens_controls_ooba"> | |
| 1635 | + <div class="textAlignCenter"> | |
| 1636 | + <small data-i18n="Global list">Global list</small> | |
| 1637 | + </div> | |
| 1638 | + <div class="wide100p marginBot10"> | |
| 1639 | + <textarea id="global_banned_tokens_textgenerationwebui" class="text_pole textarea_compact" name="global_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> | |
| 1640 | + </div> | |
| 1641 | + <div class="textAlignCenter"> | |
| 1642 | + <small data-i18n="Preset-specific list">Preset-specific list</small> | |
| 1643 | + </div> | |
| 1644 | + <div class="wide100p"> | |
| 1645 | + <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> | |
| 1646 | + </div> | |
| 1630 | 1647 | </div> |
| 1631 | 1648 | </div> |
| 1632 | 1649 | <div class="range-block wide100p"> |
| 1633 | 1650 | <div id="logit_bias_textgenerationwebui" class="range-block-title title_restorable"> |
| 1634 | 1651 | <spanstrong data-i18n="Logit Bias">Logit Bias</spanstrong> |
| 1635 | 1652 | <div id="textgen_logit_bias_new_entry" class="menu_button menu_button_icon"> |
| 1636 | 1653 | <i class="fa-xs fa-solid fa-plus"></i> |
| 1637 | 1654 | <small data-i18n="Add">Add</small> |
| @@ -3517,7 +3534,7 @@ | ||
| 3517 | 3534 | </label> |
| 3518 | 3535 | <label id="instruct_enabled_label"for="instruct_enabled" class="checkbox_label flex1" title="Enable Instruct Mode" data-i18n="[title]instruct_enabled"> |
| 3519 | 3536 | <input id="instruct_enabled" type="checkbox" style="display:none;" /> |
| 3520 | 3537 | <small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small> |
| 3521 | 3538 | </label> |
| 3522 | 3539 | </div> |
| 3523 | 3540 | </h4> |
| @@ -3695,7 +3712,7 @@ | ||
| 3695 | 3712 | <div class="flex-container"> |
| 3696 | 3713 | <label id="sysprompt_enabled_label" for="sysprompt_enabled" class="checkbox_label flex1" title="Enable System Prompt" data-i18n="[title]sysprompt_enabled"> |
| 3697 | 3714 | <input id="sysprompt_enabled" type="checkbox" style="display:none;" /> |
| 3698 | 3715 | <small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small> |
| 3699 | 3716 | </label> |
| 3700 | 3717 | </div> |
| 3701 | 3718 | </h4> |
| @@ -587,6 +587,8 @@ class PresetManager { | ||
| 587 | 587 | 'derived', |
| 588 | 588 | 'generic_model', |
| 589 | 589 | 'include_reasoning', |
| 590 | + 'global_banned_tokens', | |
| 591 | + 'send_banned_tokens', | |
| 590 | 592 | ]; |
| 591 | 593 | const settings = Object.assign({}, getSettingsByApiId(this.apiId)); |
| 592 | 594 | |
| @@ -10,6 +10,7 @@ import { | ||
| 10 | 10 | setOnlineStatus, |
| 11 | 11 | substituteParams, |
| 12 | 12 | } from '../script.js'; |
| 13 | +import { t } from './i18n.js'; | |
| 13 | 14 | import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js'; |
| 14 | 15 | |
| 15 | 16 | import { power_user, registerDebugFunction } from './power-user.js'; |
| @@ -182,6 +183,8 @@ const settings = { | ||
| 182 | 183 | grammar_string: '', |
| 183 | 184 | json_schema: {}, |
| 184 | 185 | banned_tokens: '', |
| 186 | + global_banned_tokens: '', | |
| 187 | + send_banned_tokens: true, | |
| 185 | 188 | sampler_priority: OOBA_DEFAULT_ORDER, |
| 186 | 189 | samplers: LLAMACPP_DEFAULT_ORDER, |
| 187 | 190 | samplers_priorities: APHRODITE_DEFAULT_ORDER, |
| @@ -274,6 +277,8 @@ export const setting_names = [ | ||
| 274 | 277 | 'grammar_string', |
| 275 | 278 | 'json_schema', |
| 276 | 279 | 'banned_tokens', |
| 280 | + 'global_banned_tokens', | |
| 281 | + 'send_banned_tokens', | |
| 277 | 282 | 'ignore_eos_token', |
| 278 | 283 | 'spaces_between_special_tokens', |
| 279 | 284 | 'speculative_ngram', |
| @@ -394,7 +399,7 @@ function getTokenizerForTokenIds() { | ||
| 394 | 399 | * @returns {TokenBanResult} String with comma-separated banned token IDs |
| 395 | 400 | */ |
| 396 | 401 | function getCustomTokenBans() { |
| 397 | 402 | if (!settings.send_banned_tokens || (!settings.banned_tokens && !settings.global_banned_tokens && !textgenerationwebui_banned_in_macros.length)) { |
| 398 | 403 | return { |
| 399 | 404 | banned_tokens: '', |
| 400 | 405 | banned_strings: [], |
| @@ -404,8 +409,9 @@ function getCustomTokenBans() { | ||
| 404 | 409 | const tokenizer = getTokenizerForTokenIds(); |
| 405 | 410 | const banned_tokens = []; |
| 406 | 411 | const banned_strings = []; |
| 407 | 412 | const sequences = settings.banned_tokens[] |
| 408 | 413 | .concat(settings.banned_tokens.split('\n')) |
| 414 | + .concat(settings.global_banned_tokens.split('\n')) | |
| 409 | 415 | .concat(textgenerationwebui_banned_in_macros) |
| 410 | 416 | .filter(x => x.length > 0) |
| 411 | 417 | .filter(onlyUnique); |
| @@ -453,6 +459,18 @@ function getCustomTokenBans() { | ||
| 453 | 459 | } |
| 454 | 460 | |
| 455 | 461 | /** |
| 462 | + * Sets the banned strings kill switch toggle. | |
| 463 | + * @param {boolean} isEnabled Kill switch state | |
| 464 | + * @param {string} title Label title | |
| 465 | + */ | |
| 466 | +function toggleBannedStringsKillSwitch(isEnabled, title) { | |
| 467 | + $('#send_banned_tokens_textgenerationwebui').prop('checked', isEnabled); | |
| 468 | + $('#send_banned_tokens_label').find('.menu_button').toggleClass('toggleEnabled', isEnabled).prop('title', title); | |
| 469 | + settings.send_banned_tokens = isEnabled; | |
| 470 | + saveSettingsDebounced(); | |
| 471 | +} | |
| 472 | + | |
| 473 | +/** | |
| 456 | 474 | * Calculates logit bias object from the logit bias list. |
| 457 | 475 | * @returns {object} Logit bias object |
| 458 | 476 | */ |
| @@ -594,6 +612,14 @@ function sortAphroditeItemsByOrder(orderArray) { | ||
| 594 | 612 | } |
| 595 | 613 | |
| 596 | 614 | jQuery(function () { |
| 615 | + $('#send_banned_tokens_textgenerationwebui').on('change', function () { | |
| 616 | + const checked = !!$(this).prop('checked'); | |
| 617 | + toggleBannedStringsKillSwitch(checked, | |
| 618 | + checked | |
| 619 | + ? t`Banned tokens/strings are being sent in the request.` | |
| 620 | + : t`Banned tokens/strings are NOT being sent in the request.`); | |
| 621 | + }); | |
| 622 | + | |
| 597 | 623 | $('#koboldcpp_order').sortable({ |
| 598 | 624 | delay: getSortableDelay(), |
| 599 | 625 | stop: function () { |
| @@ -932,6 +958,10 @@ function setSettingByName(setting, value, trigger) { | ||
| 932 | 958 | if (isCheckbox) { |
| 933 | 959 | const val = Boolean(value); |
| 934 | 960 | $(`#${setting}_textgenerationwebui`).prop('checked', val); |
| 961 | + | |
| 962 | + if ('send_banned_tokens' === setting) { | |
| 963 | + $(`#${setting}_textgenerationwebui`).trigger('change'); | |
| 964 | + } | |
| 935 | 965 | } |
| 936 | 966 | else if (isText) { |
| 937 | 967 | $(`#${setting}_textgenerationwebui`).val(value); |
| @@ -2879,9 +2879,8 @@ select option:not(:checked) { | ||
| 2879 | 2879 | color: var(--active) !important; |
| 2880 | 2880 | } |
| 2881 | 2881 | |
| 2882 | 2882 | #instruct_enabled_label .menu_button.togglable:not(.toggleEnabled), { |
| 2883 | -#sysprompt_enabled_label .menu_button:not(.toggleEnabled) { | |
| 2883 | + color: red; | |
| 2884 | - color: Red; | |
| 2885 | 2884 | } |
| 2886 | 2885 | |
| 2887 | 2886 | .displayBlock { |