Merge pull request #3477 from SillyTavern/tc-global-banlist Text Completion: Add global banned strings list

cc369d25c574e1989e535c0ce0e14746d3f6b6c7

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
5 files changed, +64 -12Showing whitespace changes
public/css/toggle-dependent.css+4 -0
@@ -493,3 +493,7 @@ label[for="trim_spaces"]:not(:has(input:checked)) small {
493493#mistralai_other_models:empty {
494494 display: none;
495495}
496+
497+#banned_tokens_block_ooba:not(:has(#send_banned_tokens_textgenerationwebui:checked)) #banned_tokens_controls_ooba {
498+ filter: brightness(0.5);
499+}
public/index.html+23 -6
@@ -1621,17 +1621,34 @@
16211621 </div>
16221622 <div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p">
16231623 <hr class="width100p">
16241624 <h4div class="range-block-title justifyCentertitle_restorable">
1625- <span data-i18n="Banned Tokens">Banned Tokens/Strings</span>
1625+ <div>
1626+ <strong data-i18n="Banned Tokens">Banned Tokens/Strings</strong>
16261627 <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>
16271628 </h4div>
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&#10;[420, 69, 1337]&#10;"Some verbatim string"'></textarea>
1640+ </div>
1641+ <div class="textAlignCenter">
1642+ <small data-i18n="Preset-specific list">Preset-specific list</small>
1643+ </div>
16281644 <div class="wide100p">
16291645 <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>
16301646 </div>
16311647 </div>
1648+ </div>
16321649 <div class="range-block wide100p">
16331650 <div id="logit_bias_textgenerationwebui" class="range-block-title title_restorable">
16341651 <spanstrong data-i18n="Logit Bias">Logit Bias</spanstrong>
16351652 <div id="textgen_logit_bias_new_entry" class="menu_button menu_button_icon">
16361653 <i class="fa-xs fa-solid fa-plus"></i>
16371654 <small data-i18n="Add">Add</small>
@@ -3517,7 +3534,7 @@
35173534 </label>
35183535 <label id="instruct_enabled_label"for="instruct_enabled" class="checkbox_label flex1" title="Enable Instruct Mode" data-i18n="[title]instruct_enabled">
35193536 <input id="instruct_enabled" type="checkbox" style="display:none;" />
35203537 <small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small>
35213538 </label>
35223539 </div>
35233540 </h4>
@@ -3695,7 +3712,7 @@
36953712 <div class="flex-container">
36963713 <label id="sysprompt_enabled_label" for="sysprompt_enabled" class="checkbox_label flex1" title="Enable System Prompt" data-i18n="[title]sysprompt_enabled">
36973714 <input id="sysprompt_enabled" type="checkbox" style="display:none;" />
36983715 <small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small>
36993716 </label>
37003717 </div>
37013718 </h4>
public/scripts/preset-manager.js+2 -0
@@ -587,6 +587,8 @@ class PresetManager {
587587 'derived',
588588 'generic_model',
589589 'include_reasoning',
590+ 'global_banned_tokens',
591+ 'send_banned_tokens',
590592 ];
591593 const settings = Object.assign({}, getSettingsByApiId(this.apiId));
592594
public/scripts/textgen-settings.js+33 -3
@@ -10,6 +10,7 @@ import {
1010 setOnlineStatus,
1111 substituteParams,
1212} from '../script.js';
13+import { t } from './i18n.js';
1314import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js';
1415
1516import { power_user, registerDebugFunction } from './power-user.js';
@@ -182,6 +183,8 @@ const settings = {
182183 grammar_string: '',
183184 json_schema: {},
184185 banned_tokens: '',
186+ global_banned_tokens: '',
187+ send_banned_tokens: true,
185188 sampler_priority: OOBA_DEFAULT_ORDER,
186189 samplers: LLAMACPP_DEFAULT_ORDER,
187190 samplers_priorities: APHRODITE_DEFAULT_ORDER,
@@ -274,6 +277,8 @@ export const setting_names = [
274277 'grammar_string',
275278 'json_schema',
276279 'banned_tokens',
280+ 'global_banned_tokens',
281+ 'send_banned_tokens',
277282 'ignore_eos_token',
278283 'spaces_between_special_tokens',
279284 'speculative_ngram',
@@ -394,7 +399,7 @@ function getTokenizerForTokenIds() {
394399 * @returns {TokenBanResult} String with comma-separated banned token IDs
395400 */
396401function getCustomTokenBans() {
397402 if (!settings.send_banned_tokens || (!settings.banned_tokens && !settings.global_banned_tokens && !textgenerationwebui_banned_in_macros.length)) {
398403 return {
399404 banned_tokens: '',
400405 banned_strings: [],
@@ -404,8 +409,9 @@ function getCustomTokenBans() {
404409 const tokenizer = getTokenizerForTokenIds();
405410 const banned_tokens = [];
406411 const banned_strings = [];
407412 const sequences = settings.banned_tokens[]
408413 .concat(settings.banned_tokens.split('\n'))
414+ .concat(settings.global_banned_tokens.split('\n'))
409415 .concat(textgenerationwebui_banned_in_macros)
410416 .filter(x => x.length > 0)
411417 .filter(onlyUnique);
@@ -453,6 +459,18 @@ function getCustomTokenBans() {
453459}
454460
455461/**
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+/**
456474 * Calculates logit bias object from the logit bias list.
457475 * @returns {object} Logit bias object
458476 */
@@ -594,6 +612,14 @@ function sortAphroditeItemsByOrder(orderArray) {
594612}
595613
596614jQuery(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+
597623 $('#koboldcpp_order').sortable({
598624 delay: getSortableDelay(),
599625 stop: function () {
@@ -932,6 +958,10 @@ function setSettingByName(setting, value, trigger) {
932958 if (isCheckbox) {
933959 const val = Boolean(value);
934960 $(`#${setting}_textgenerationwebui`).prop('checked', val);
961+
962+ if ('send_banned_tokens' === setting) {
963+ $(`#${setting}_textgenerationwebui`).trigger('change');
964+ }
935965 }
936966 else if (isText) {
937967 $(`#${setting}_textgenerationwebui`).val(value);
public/style.css+2 -3
@@ -2879,9 +2879,8 @@ select option:not(:checked) {
28792879 color: var(--active) !important;
28802880}
28812881
28822882#instruct_enabled_label .menu_button.togglable:not(.toggleEnabled), {
2883-#sysprompt_enabled_label .menu_button:not(.toggleEnabled) {
2883+ color: red;
2884- color: Red;
28852884}
28862885
28872886.displayBlock {