Merge branch 'Banned-Strings-Killswitch' into tc-global-banlist

a2a15b9978090925c9f52843cac3e77d26b8eca4

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

3 files changed, +39 -1Showing whitespace changes
public/index.html+4 -0
@@ -1622,6 +1622,10 @@
16221622 <div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p">
16231623 <hr class="width100p">
16241624 <h4 class="range-block-title justifyCenter">
1625+ <label id="send_banned_tokens_label" for="send_banned_tokens_textgenerationwebui" class="checkbox_label">
1626+ <input id="send_banned_tokens_textgenerationwebui" type="checkbox" style="display:none;" />
1627+ <small><i class="fa-solid fa-power-off menu_button margin0"></i></small>
1628+ </label>
16251629 <span data-i18n="Banned Tokens">Banned Tokens/Strings</span>
16261630 <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>
16271631 </h4>
public/scripts/textgen-settings.js+33 -0
@@ -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';
@@ -183,6 +184,7 @@ const settings = {
183184 json_schema: {},
184185 banned_tokens: '',
185186 global_banned_tokens: '',
187+ send_banned_tokens: true,
186188 sampler_priority: OOBA_DEFAULT_ORDER,
187189 samplers: LLAMACPP_DEFAULT_ORDER,
188190 samplers_priorities: APHRODITE_DEFAULT_ORDER,
@@ -276,6 +278,7 @@ export const setting_names = [
276278 'json_schema',
277279 'banned_tokens',
278280 'global_banned_tokens',
281+ 'send_banned_tokens',
279282 'ignore_eos_token',
280283 'spaces_between_special_tokens',
281284 'speculative_ngram',
@@ -455,6 +458,22 @@ function getCustomTokenBans() {
455458 };
456459}
457460
461+async function enableBannedStringsKillSwitch() {
462+ $('#send_banned_tokens_textgenerationwebui').prop('checked', true);
463+ $('#send_banned_tokens_label').find('.menu_button').addClass('toggleEnabled').prop('title', t`Banned tokens/strings are being sent into the request.`);
464+ settings.send_banned_tokens = true;
465+ saveSettingsDebounced();
466+ return '';
467+}
468+
469+async function disableBannedStringsKillSwitch() {
470+ $('#send_banned_tokens_textgenerationwebui').prop('checked', false);
471+ $('#send_banned_tokens_label').find('.menu_button').removeClass('toggleEnabled').prop('title', t`Banned tokens/strings are NOT being sent into the request.`);
472+ settings.send_banned_tokens = false;
473+ saveSettingsDebounced();
474+ return '';
475+}
476+
458477/**
459478 * Calculates logit bias object from the logit bias list.
460479 * @returns {object} Logit bias object
@@ -597,6 +616,16 @@ function sortAphroditeItemsByOrder(orderArray) {
597616}
598617
599618jQuery(function () {
619+
620+ $('#bannedStringsKillSwitch_textgenerationwebui').on('change', function () {
621+ const checked = $(this).prop('checked');
622+ if (checked) {
623+ enableBannedStringsKillSwitch();
624+ } else {
625+ disableBannedStringsKillSwitch();
626+ }
627+ });
628+
600629 $('#koboldcpp_order').sortable({
601630 delay: getSortableDelay(),
602631 stop: function () {
@@ -935,6 +964,10 @@ function setSettingByName(setting, value, trigger) {
935964 if (isCheckbox) {
936965 const val = Boolean(value);
937966 $(`#${setting}_textgenerationwebui`).prop('checked', val);
967+
968+ if ('send_banned_tokens' === setting) {
969+ $('#send_banned_tokens_textgenerationwebui').trigger('change');
970+ }
938971 }
939972 else if (isText) {
940973 $(`#${setting}_textgenerationwebui`).val(value);
public/style.css+2 -1
@@ -2875,7 +2875,8 @@ select option:not(:checked) {
28752875}
28762876
28772877#instruct_enabled_label .menu_button:not(.toggleEnabled),
28782878#sysprompt_enabled_label .menu_button:not(.toggleEnabled) {,
2879+#bannedStringsKillSwitch_label .menu_button:not(.toggleEnabled) {
28792880 color: Red;
28802881}
28812882