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 | #mistralai_other_models:empty { | 493 | #mistralai_other_models:empty { |
| 494 | display: none; | 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 | </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 | <div class="range-block-title title_restorable"> |
| 1625 | <span data-i18n="Banned Tokens">Banned Tokens/Strings</span> | 1625 | <div> |
| 1626 | <strong data-i18n="Banned Tokens">Banned Tokens/Strings</strong> | ||
| 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> | 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> |
| 1627 | </h4> | 1628 | </div> |
| 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> | ||
| 1628 | <div class="wide100p"> | 1644 | <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 [420, 69, 1337] "Some verbatim string"'></textarea> | 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> |
| 1630 | </div> | 1646 | </div> |
| 1631 | </div> | 1647 | </div> |
| 1648 | </div> | ||
| 1632 | <div class="range-block wide100p"> | 1649 | <div class="range-block wide100p"> |
| 1633 | <div id="logit_bias_textgenerationwebui" class="range-block-title title_restorable"> | 1650 | <div id="logit_bias_textgenerationwebui" class="range-block-title title_restorable"> |
| 1634 | <span data-i18n="Logit Bias">Logit Bias</span> | 1651 | <strong data-i18n="Logit Bias">Logit Bias</strong> |
| 1635 | <div id="textgen_logit_bias_new_entry" class="menu_button menu_button_icon"> | 1652 | <div id="textgen_logit_bias_new_entry" class="menu_button menu_button_icon"> |
| 1636 | <i class="fa-xs fa-solid fa-plus"></i> | 1653 | <i class="fa-xs fa-solid fa-plus"></i> |
| 1637 | <small data-i18n="Add">Add</small> | 1654 | <small data-i18n="Add">Add</small> |
| @@ -3517,7 +3534,7 @@ | |||
| 3517 | </label> | 3534 | </label> |
| 3518 | <label id="instruct_enabled_label"for="instruct_enabled" class="checkbox_label flex1" title="Enable Instruct Mode" data-i18n="[title]instruct_enabled"> | 3535 | <label id="instruct_enabled_label"for="instruct_enabled" class="checkbox_label flex1" title="Enable Instruct Mode" data-i18n="[title]instruct_enabled"> |
| 3519 | <input id="instruct_enabled" type="checkbox" style="display:none;" /> | 3536 | <input id="instruct_enabled" type="checkbox" style="display:none;" /> |
| 3520 | <small><i class="fa-solid fa-power-off menu_button margin0"></i></small> | 3537 | <small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small> |
| 3521 | </label> | 3538 | </label> |
| 3522 | </div> | 3539 | </div> |
| 3523 | </h4> | 3540 | </h4> |
| @@ -3695,7 +3712,7 @@ | |||
| 3695 | <div class="flex-container"> | 3712 | <div class="flex-container"> |
| 3696 | <label id="sysprompt_enabled_label" for="sysprompt_enabled" class="checkbox_label flex1" title="Enable System Prompt" data-i18n="[title]sysprompt_enabled"> | 3713 | <label id="sysprompt_enabled_label" for="sysprompt_enabled" class="checkbox_label flex1" title="Enable System Prompt" data-i18n="[title]sysprompt_enabled"> |
| 3697 | <input id="sysprompt_enabled" type="checkbox" style="display:none;" /> | 3714 | <input id="sysprompt_enabled" type="checkbox" style="display:none;" /> |
| 3698 | <small><i class="fa-solid fa-power-off menu_button margin0"></i></small> | 3715 | <small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small> |
| 3699 | </label> | 3716 | </label> |
| 3700 | </div> | 3717 | </div> |
| 3701 | </h4> | 3718 | </h4> |
| @@ -587,6 +587,8 @@ class PresetManager { | |||
| 587 | 'derived', | 587 | 'derived', |
| 588 | 'generic_model', | 588 | 'generic_model', |
| 589 | 'include_reasoning', | 589 | 'include_reasoning', |
| 590 | 'global_banned_tokens', | ||
| 591 | 'send_banned_tokens', | ||
| 590 | ]; | 592 | ]; |
| 591 | const settings = Object.assign({}, getSettingsByApiId(this.apiId)); | 593 | const settings = Object.assign({}, getSettingsByApiId(this.apiId)); |
| 592 | 594 | ||
| @@ -10,6 +10,7 @@ import { | |||
| 10 | setOnlineStatus, | 10 | setOnlineStatus, |
| 11 | substituteParams, | 11 | substituteParams, |
| 12 | } from '../script.js'; | 12 | } from '../script.js'; |
| 13 | import { t } from './i18n.js'; | ||
| 13 | import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js'; | 14 | import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js'; |
| 14 | 15 | ||
| 15 | import { power_user, registerDebugFunction } from './power-user.js'; | 16 | import { power_user, registerDebugFunction } from './power-user.js'; |
| @@ -182,6 +183,8 @@ const settings = { | |||
| 182 | grammar_string: '', | 183 | grammar_string: '', |
| 183 | json_schema: {}, | 184 | json_schema: {}, |
| 184 | banned_tokens: '', | 185 | banned_tokens: '', |
| 186 | global_banned_tokens: '', | ||
| 187 | send_banned_tokens: true, | ||
| 185 | sampler_priority: OOBA_DEFAULT_ORDER, | 188 | sampler_priority: OOBA_DEFAULT_ORDER, |
| 186 | samplers: LLAMACPP_DEFAULT_ORDER, | 189 | samplers: LLAMACPP_DEFAULT_ORDER, |
| 187 | samplers_priorities: APHRODITE_DEFAULT_ORDER, | 190 | samplers_priorities: APHRODITE_DEFAULT_ORDER, |
| @@ -274,6 +277,8 @@ export const setting_names = [ | |||
| 274 | 'grammar_string', | 277 | 'grammar_string', |
| 275 | 'json_schema', | 278 | 'json_schema', |
| 276 | 'banned_tokens', | 279 | 'banned_tokens', |
| 280 | 'global_banned_tokens', | ||
| 281 | 'send_banned_tokens', | ||
| 277 | 'ignore_eos_token', | 282 | 'ignore_eos_token', |
| 278 | 'spaces_between_special_tokens', | 283 | 'spaces_between_special_tokens', |
| 279 | 'speculative_ngram', | 284 | 'speculative_ngram', |
| @@ -394,7 +399,7 @@ function getTokenizerForTokenIds() { | |||
| 394 | * @returns {TokenBanResult} String with comma-separated banned token IDs | 399 | * @returns {TokenBanResult} String with comma-separated banned token IDs |
| 395 | */ | 400 | */ |
| 396 | function getCustomTokenBans() { | 401 | function getCustomTokenBans() { |
| 397 | if (!settings.banned_tokens && !textgenerationwebui_banned_in_macros.length) { | 402 | if (!settings.send_banned_tokens || (!settings.banned_tokens && !settings.global_banned_tokens && !textgenerationwebui_banned_in_macros.length)) { |
| 398 | return { | 403 | return { |
| 399 | banned_tokens: '', | 404 | banned_tokens: '', |
| 400 | banned_strings: [], | 405 | banned_strings: [], |
| @@ -404,8 +409,9 @@ function getCustomTokenBans() { | |||
| 404 | const tokenizer = getTokenizerForTokenIds(); | 409 | const tokenizer = getTokenizerForTokenIds(); |
| 405 | const banned_tokens = []; | 410 | const banned_tokens = []; |
| 406 | const banned_strings = []; | 411 | const banned_strings = []; |
| 407 | const sequences = settings.banned_tokens | 412 | const sequences = [] |
| 408 | .split('\n') | 413 | .concat(settings.banned_tokens.split('\n')) |
| 414 | .concat(settings.global_banned_tokens.split('\n')) | ||
| 409 | .concat(textgenerationwebui_banned_in_macros) | 415 | .concat(textgenerationwebui_banned_in_macros) |
| 410 | .filter(x => x.length > 0) | 416 | .filter(x => x.length > 0) |
| 411 | .filter(onlyUnique); | 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 | * Calculates logit bias object from the logit bias list. | 474 | * Calculates logit bias object from the logit bias list. |
| 457 | * @returns {object} Logit bias object | 475 | * @returns {object} Logit bias object |
| 458 | */ | 476 | */ |
| @@ -594,6 +612,14 @@ function sortAphroditeItemsByOrder(orderArray) { | |||
| 594 | } | 612 | } |
| 595 | 613 | ||
| 596 | jQuery(function () { | 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 | $('#koboldcpp_order').sortable({ | 623 | $('#koboldcpp_order').sortable({ |
| 598 | delay: getSortableDelay(), | 624 | delay: getSortableDelay(), |
| 599 | stop: function () { | 625 | stop: function () { |
| @@ -932,6 +958,10 @@ function setSettingByName(setting, value, trigger) { | |||
| 932 | if (isCheckbox) { | 958 | if (isCheckbox) { |
| 933 | const val = Boolean(value); | 959 | const val = Boolean(value); |
| 934 | $(`#${setting}_textgenerationwebui`).prop('checked', val); | 960 | $(`#${setting}_textgenerationwebui`).prop('checked', val); |
| 961 | |||
| 962 | if ('send_banned_tokens' === setting) { | ||
| 963 | $(`#${setting}_textgenerationwebui`).trigger('change'); | ||
| 964 | } | ||
| 935 | } | 965 | } |
| 936 | else if (isText) { | 966 | else if (isText) { |
| 937 | $(`#${setting}_textgenerationwebui`).val(value); | 967 | $(`#${setting}_textgenerationwebui`).val(value); |
| @@ -2879,9 +2879,8 @@ select option:not(:checked) { | |||
| 2879 | color: var(--active) !important; | 2879 | color: var(--active) !important; |
| 2880 | } | 2880 | } |
| 2881 | 2881 | ||
| 2882 | #instruct_enabled_label .menu_button:not(.toggleEnabled), | 2882 | .menu_button.togglable:not(.toggleEnabled) { |
| 2883 | #sysprompt_enabled_label .menu_button:not(.toggleEnabled) { | 2883 | color: red; |
| 2884 | color: Red; | ||
| 2885 | } | 2884 | } |
| 2886 | 2885 | ||
| 2887 | .displayBlock { | 2886 | .displayBlock { |