add killswitch for banned strings

This commit is contained in:
RossAscends
2025-02-02 12:00:01 +09:00
parent 890c0c4723
commit c5dad20fc4
3 changed files with 56 additions and 5 deletions

View File

@ -1621,10 +1621,23 @@
</div> </div>
<div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p"> <div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p">
<hr class="width100p"> <hr class="width100p">
<h4 class="range-block-title justifyCenter">
<span data-i18n="Banned Tokens">Banned Tokens/Strings</span> <span class="flex-container flexnowrap">
<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>
</h4>
<h4 class="range-block-title justifyCenter flex-container">
<label id="bannedStringsKillSwitch_label" for="bannedStringsKillSwitch_textgenerationwebui" class="checkbox_label">
<input id="bannedStringsKillSwitch_textgenerationwebui" type="checkbox" style="display:none;" />
<small><i class="fa-solid fa-power-off menu_button margin0"></i></small>
</label>
<span data-i18n="Banned Tokens">
Banned Tokens/Strings
</span>
<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>
</h4>
</span>
<div class="wide100p"> <div class="wide100p">
<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> <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>
</div> </div>

View File

@ -182,6 +182,7 @@ const settings = {
grammar_string: '', grammar_string: '',
json_schema: {}, json_schema: {},
banned_tokens: '', banned_tokens: '',
sendBannedTokens: true,
sampler_priority: OOBA_DEFAULT_ORDER, sampler_priority: OOBA_DEFAULT_ORDER,
samplers: LLAMACPP_DEFAULT_ORDER, samplers: LLAMACPP_DEFAULT_ORDER,
samplers_priorities: APHRODITE_DEFAULT_ORDER, samplers_priorities: APHRODITE_DEFAULT_ORDER,
@ -274,6 +275,7 @@ export const setting_names = [
'grammar_string', 'grammar_string',
'json_schema', 'json_schema',
'banned_tokens', 'banned_tokens',
'sendBannedTokens',
'ignore_eos_token', 'ignore_eos_token',
'spaces_between_special_tokens', 'spaces_between_special_tokens',
'speculative_ngram', 'speculative_ngram',
@ -452,6 +454,22 @@ function getCustomTokenBans() {
}; };
} }
async function enableBannedStringsKillSwitch() {
$('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', true);
$('#bannedStringsKillSwitch_label').find('.menu_button').addClass('toggleEnabled').prop('title', 'Banned tokens/strings are being sent into the request.');
settings.sendBannedTokens = true;
saveSettingsDebounced();
return '';
}
async function disableBannedStringsKillSwitch() {
$('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', false);
$('#bannedStringsKillSwitch_label').find('.menu_button').removeClass('toggleEnabled').prop('title', 'Banned tokens/strings are NOT being sent into the request.');
settings.sendBannedTokens = false;
saveSettingsDebounced();
return '';
}
/** /**
* Calculates logit bias object from the logit bias list. * Calculates logit bias object from the logit bias list.
* @returns {object} Logit bias object * @returns {object} Logit bias object
@ -594,6 +612,16 @@ function sortAphroditeItemsByOrder(orderArray) {
} }
jQuery(function () { jQuery(function () {
$('#bannedStringsKillSwitch_textgenerationwebui').on('change', function () {
const checked = $(this).prop('checked');
if (checked) {
enableBannedStringsKillSwitch();
} else {
disableBannedStringsKillSwitch();
}
});
$('#koboldcpp_order').sortable({ $('#koboldcpp_order').sortable({
delay: getSortableDelay(), delay: getSortableDelay(),
stop: function () { stop: function () {
@ -927,6 +955,11 @@ function setSettingByName(setting, value, trigger) {
return; return;
} }
if ('sendBannedTokens' === setting) {
$('#bannedStringsKillSwitch_textgenerationwebui').prop('checked', value).trigger('change');
return;
}
const isCheckbox = $(`#${setting}_textgenerationwebui`).attr('type') == 'checkbox'; const isCheckbox = $(`#${setting}_textgenerationwebui`).attr('type') == 'checkbox';
const isText = $(`#${setting}_textgenerationwebui`).attr('type') == 'text' || $(`#${setting}_textgenerationwebui`).is('textarea'); const isText = $(`#${setting}_textgenerationwebui`).attr('type') == 'text' || $(`#${setting}_textgenerationwebui`).is('textarea');
if (isCheckbox) { if (isCheckbox) {
@ -1461,5 +1494,9 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
} }
} }
//last check before sending sampler params, strip banned strings if toggled off.
const sendBannedStrings = $('#bannedStringsKillSwitch_textgenerationwebui').prop('checked');
if (!sendBannedStrings) { delete params.banned_strings; }
return params; return params;
} }

View File

@ -2816,7 +2816,8 @@ select option:not(:checked) {
} }
#instruct_enabled_label .menu_button:not(.toggleEnabled), #instruct_enabled_label .menu_button:not(.toggleEnabled),
#sysprompt_enabled_label .menu_button:not(.toggleEnabled) { #sysprompt_enabled_label .menu_button:not(.toggleEnabled),
#bannedStringsKillSwitch_label .menu_button:not(.toggleEnabled) {
color: Red; color: Red;
} }