Refactor banned strings kill switch functions into a single toggle function

This commit is contained in:
Cohee
2025-02-15 12:37:48 +02:00
parent c37c9051a6
commit c87e203b4a

View File

@ -458,22 +458,18 @@ function getCustomTokenBans() {
}; };
} }
async function enableBannedStringsKillSwitch() { /**
$('#send_banned_tokens_textgenerationwebui').prop('checked', true); * Sets the banned strings kill switch toggle.
$('#send_banned_tokens_label').find('.menu_button').addClass('toggleEnabled').prop('title', t`Banned tokens/strings are being sent in the request.`); * @param {boolean} isEnabled Kill switch state
settings.send_banned_tokens = true; * @param {string} title Label title
*/
function toggleBannedStringsKillSwitch(isEnabled, title) {
$('#send_banned_tokens_textgenerationwebui').prop('checked', isEnabled);
$('#send_banned_tokens_label').find('.menu_button').toggleClass('toggleEnabled', isEnabled).prop('title', title);
settings.send_banned_tokens = isEnabled;
saveSettingsDebounced(); saveSettingsDebounced();
return ''; return '';
} }
async function disableBannedStringsKillSwitch() {
$('#send_banned_tokens_textgenerationwebui').prop('checked', false);
$('#send_banned_tokens_label').find('.menu_button').removeClass('toggleEnabled').prop('title', t`Banned tokens/strings are NOT being sent in the request.`);
settings.send_banned_tokens = 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
@ -618,11 +614,10 @@ function sortAphroditeItemsByOrder(orderArray) {
jQuery(function () { jQuery(function () {
$('#send_banned_tokens_textgenerationwebui').on('change', function () { $('#send_banned_tokens_textgenerationwebui').on('change', function () {
const checked = !!$(this).prop('checked'); const checked = !!$(this).prop('checked');
if (checked) { toggleBannedStringsKillSwitch(checked,
enableBannedStringsKillSwitch(); checked
} else { ? t`Banned tokens/strings are being sent in the request.`
disableBannedStringsKillSwitch(); : t`Banned tokens/strings are NOT being sent in the request.`);
}
}); });
$('#koboldcpp_order').sortable({ $('#koboldcpp_order').sortable({