Merge branch 'Banned-Strings-Killswitch' into tc-global-banlist
| @@ -1622,6 +1622,10 @@ | |||
| 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 | <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> | ||
| 1625 | <span data-i18n="Banned Tokens">Banned Tokens/Strings</span> | 1629 | <span data-i18n="Banned Tokens">Banned Tokens/Strings</span> |
| 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> | 1630 | <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> | 1631 | </h4> |
| @@ -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'; |
| @@ -183,6 +184,7 @@ const settings = { | |||
| 183 | json_schema: {}, | 184 | json_schema: {}, |
| 184 | banned_tokens: '', | 185 | banned_tokens: '', |
| 185 | global_banned_tokens: '', | 186 | global_banned_tokens: '', |
| 187 | send_banned_tokens: true, | ||
| 186 | sampler_priority: OOBA_DEFAULT_ORDER, | 188 | sampler_priority: OOBA_DEFAULT_ORDER, |
| 187 | samplers: LLAMACPP_DEFAULT_ORDER, | 189 | samplers: LLAMACPP_DEFAULT_ORDER, |
| 188 | samplers_priorities: APHRODITE_DEFAULT_ORDER, | 190 | samplers_priorities: APHRODITE_DEFAULT_ORDER, |
| @@ -276,6 +278,7 @@ export const setting_names = [ | |||
| 276 | 'json_schema', | 278 | 'json_schema', |
| 277 | 'banned_tokens', | 279 | 'banned_tokens', |
| 278 | 'global_banned_tokens', | 280 | 'global_banned_tokens', |
| 281 | 'send_banned_tokens', | ||
| 279 | 'ignore_eos_token', | 282 | 'ignore_eos_token', |
| 280 | 'spaces_between_special_tokens', | 283 | 'spaces_between_special_tokens', |
| 281 | 'speculative_ngram', | 284 | 'speculative_ngram', |
| @@ -455,6 +458,22 @@ function getCustomTokenBans() { | |||
| 455 | }; | 458 | }; |
| 456 | } | 459 | } |
| 457 | 460 | ||
| 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 | |||
| 458 | /** | 477 | /** |
| 459 | * Calculates logit bias object from the logit bias list. | 478 | * Calculates logit bias object from the logit bias list. |
| 460 | * @returns {object} Logit bias object | 479 | * @returns {object} Logit bias object |
| @@ -597,6 +616,16 @@ function sortAphroditeItemsByOrder(orderArray) { | |||
| 597 | } | 616 | } |
| 598 | 617 | ||
| 599 | jQuery(function () { | 618 | jQuery(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 | |||
| 600 | $('#koboldcpp_order').sortable({ | 629 | $('#koboldcpp_order').sortable({ |
| 601 | delay: getSortableDelay(), | 630 | delay: getSortableDelay(), |
| 602 | stop: function () { | 631 | stop: function () { |
| @@ -935,6 +964,10 @@ function setSettingByName(setting, value, trigger) { | |||
| 935 | if (isCheckbox) { | 964 | if (isCheckbox) { |
| 936 | const val = Boolean(value); | 965 | const val = Boolean(value); |
| 937 | $(`#${setting}_textgenerationwebui`).prop('checked', val); | 966 | $(`#${setting}_textgenerationwebui`).prop('checked', val); |
| 967 | |||
| 968 | if ('send_banned_tokens' === setting) { | ||
| 969 | $('#send_banned_tokens_textgenerationwebui').trigger('change'); | ||
| 970 | } | ||
| 938 | } | 971 | } |
| 939 | else if (isText) { | 972 | else if (isText) { |
| 940 | $(`#${setting}_textgenerationwebui`).val(value); | 973 | $(`#${setting}_textgenerationwebui`).val(value); |
| @@ -2875,7 +2875,8 @@ select option:not(:checked) { | |||
| 2875 | } | 2875 | } |
| 2876 | 2876 | ||
| 2877 | #instruct_enabled_label .menu_button:not(.toggleEnabled), | 2877 | #instruct_enabled_label .menu_button:not(.toggleEnabled), |
| 2878 | #sysprompt_enabled_label .menu_button:not(.toggleEnabled) { | 2878 | #sysprompt_enabled_label .menu_button:not(.toggleEnabled), |
| 2879 | #bannedStringsKillSwitch_label .menu_button:not(.toggleEnabled) { | ||
| 2879 | color: Red; | 2880 | color: Red; |
| 2880 | } | 2881 | } |
| 2881 | 2882 | ||