mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #3477 from SillyTavern/tc-global-banlist
Text Completion: Add global banned strings list
This commit is contained in:
@@ -493,3 +493,7 @@ label[for="trim_spaces"]:not(:has(input:checked)) small {
|
||||
#mistralai_other_models:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#banned_tokens_block_ooba:not(:has(#send_banned_tokens_textgenerationwebui:checked)) #banned_tokens_controls_ooba {
|
||||
filter: brightness(0.5);
|
||||
}
|
||||
|
@@ -1621,17 +1621,34 @@
|
||||
</div>
|
||||
<div data-tg-type-mode="except" data-tg-type="generic" id="banned_tokens_block_ooba" class="wide100p">
|
||||
<hr class="width100p">
|
||||
<h4 class="range-block-title justifyCenter">
|
||||
<span data-i18n="Banned Tokens">Banned Tokens/Strings</span>
|
||||
<div class="range-block-title title_restorable">
|
||||
<div>
|
||||
<strong data-i18n="Banned Tokens">Banned Tokens/Strings</strong>
|
||||
<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>
|
||||
</h4>
|
||||
</div>
|
||||
<label id="send_banned_tokens_label" for="send_banned_tokens_textgenerationwebui" class="checkbox_label">
|
||||
<input id="send_banned_tokens_textgenerationwebui" type="checkbox" style="display:none;" />
|
||||
<small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small>
|
||||
</label>
|
||||
</div>
|
||||
<div id="banned_tokens_controls_ooba">
|
||||
<div class="textAlignCenter">
|
||||
<small data-i18n="Global list">Global list</small>
|
||||
</div>
|
||||
<div class="wide100p marginBot10">
|
||||
<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 [420, 69, 1337] "Some verbatim string"'></textarea>
|
||||
</div>
|
||||
<div class="textAlignCenter">
|
||||
<small data-i18n="Preset-specific list">Preset-specific list</small>
|
||||
</div>
|
||||
<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 [420, 69, 1337] "Some verbatim string"'></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block wide100p">
|
||||
<div id="logit_bias_textgenerationwebui" class="range-block-title title_restorable">
|
||||
<span data-i18n="Logit Bias">Logit Bias</span>
|
||||
<strong data-i18n="Logit Bias">Logit Bias</strong>
|
||||
<div id="textgen_logit_bias_new_entry" class="menu_button menu_button_icon">
|
||||
<i class="fa-xs fa-solid fa-plus"></i>
|
||||
<small data-i18n="Add">Add</small>
|
||||
@@ -3517,7 +3534,7 @@
|
||||
</label>
|
||||
<label id="instruct_enabled_label"for="instruct_enabled" class="checkbox_label flex1" title="Enable Instruct Mode" data-i18n="[title]instruct_enabled">
|
||||
<input id="instruct_enabled" type="checkbox" style="display:none;" />
|
||||
<small><i class="fa-solid fa-power-off menu_button margin0"></i></small>
|
||||
<small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small>
|
||||
</label>
|
||||
</div>
|
||||
</h4>
|
||||
@@ -3695,7 +3712,7 @@
|
||||
<div class="flex-container">
|
||||
<label id="sysprompt_enabled_label" for="sysprompt_enabled" class="checkbox_label flex1" title="Enable System Prompt" data-i18n="[title]sysprompt_enabled">
|
||||
<input id="sysprompt_enabled" type="checkbox" style="display:none;" />
|
||||
<small><i class="fa-solid fa-power-off menu_button margin0"></i></small>
|
||||
<small><i class="fa-solid fa-power-off menu_button togglable margin0"></i></small>
|
||||
</label>
|
||||
</div>
|
||||
</h4>
|
||||
|
@@ -587,6 +587,8 @@ class PresetManager {
|
||||
'derived',
|
||||
'generic_model',
|
||||
'include_reasoning',
|
||||
'global_banned_tokens',
|
||||
'send_banned_tokens',
|
||||
];
|
||||
const settings = Object.assign({}, getSettingsByApiId(this.apiId));
|
||||
|
||||
|
@@ -10,6 +10,7 @@ import {
|
||||
setOnlineStatus,
|
||||
substituteParams,
|
||||
} from '../script.js';
|
||||
import { t } from './i18n.js';
|
||||
import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js';
|
||||
|
||||
import { power_user, registerDebugFunction } from './power-user.js';
|
||||
@@ -182,6 +183,8 @@ const settings = {
|
||||
grammar_string: '',
|
||||
json_schema: {},
|
||||
banned_tokens: '',
|
||||
global_banned_tokens: '',
|
||||
send_banned_tokens: true,
|
||||
sampler_priority: OOBA_DEFAULT_ORDER,
|
||||
samplers: LLAMACPP_DEFAULT_ORDER,
|
||||
samplers_priorities: APHRODITE_DEFAULT_ORDER,
|
||||
@@ -274,6 +277,8 @@ export const setting_names = [
|
||||
'grammar_string',
|
||||
'json_schema',
|
||||
'banned_tokens',
|
||||
'global_banned_tokens',
|
||||
'send_banned_tokens',
|
||||
'ignore_eos_token',
|
||||
'spaces_between_special_tokens',
|
||||
'speculative_ngram',
|
||||
@@ -394,7 +399,7 @@ function getTokenizerForTokenIds() {
|
||||
* @returns {TokenBanResult} String with comma-separated banned token IDs
|
||||
*/
|
||||
function getCustomTokenBans() {
|
||||
if (!settings.banned_tokens && !textgenerationwebui_banned_in_macros.length) {
|
||||
if (!settings.send_banned_tokens || (!settings.banned_tokens && !settings.global_banned_tokens && !textgenerationwebui_banned_in_macros.length)) {
|
||||
return {
|
||||
banned_tokens: '',
|
||||
banned_strings: [],
|
||||
@@ -404,8 +409,9 @@ function getCustomTokenBans() {
|
||||
const tokenizer = getTokenizerForTokenIds();
|
||||
const banned_tokens = [];
|
||||
const banned_strings = [];
|
||||
const sequences = settings.banned_tokens
|
||||
.split('\n')
|
||||
const sequences = []
|
||||
.concat(settings.banned_tokens.split('\n'))
|
||||
.concat(settings.global_banned_tokens.split('\n'))
|
||||
.concat(textgenerationwebui_banned_in_macros)
|
||||
.filter(x => x.length > 0)
|
||||
.filter(onlyUnique);
|
||||
@@ -452,6 +458,18 @@ function getCustomTokenBans() {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the banned strings kill switch toggle.
|
||||
* @param {boolean} isEnabled Kill switch state
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates logit bias object from the logit bias list.
|
||||
* @returns {object} Logit bias object
|
||||
@@ -594,6 +612,14 @@ function sortAphroditeItemsByOrder(orderArray) {
|
||||
}
|
||||
|
||||
jQuery(function () {
|
||||
$('#send_banned_tokens_textgenerationwebui').on('change', function () {
|
||||
const checked = !!$(this).prop('checked');
|
||||
toggleBannedStringsKillSwitch(checked,
|
||||
checked
|
||||
? t`Banned tokens/strings are being sent in the request.`
|
||||
: t`Banned tokens/strings are NOT being sent in the request.`);
|
||||
});
|
||||
|
||||
$('#koboldcpp_order').sortable({
|
||||
delay: getSortableDelay(),
|
||||
stop: function () {
|
||||
@@ -932,6 +958,10 @@ function setSettingByName(setting, value, trigger) {
|
||||
if (isCheckbox) {
|
||||
const val = Boolean(value);
|
||||
$(`#${setting}_textgenerationwebui`).prop('checked', val);
|
||||
|
||||
if ('send_banned_tokens' === setting) {
|
||||
$(`#${setting}_textgenerationwebui`).trigger('change');
|
||||
}
|
||||
}
|
||||
else if (isText) {
|
||||
$(`#${setting}_textgenerationwebui`).val(value);
|
||||
|
@@ -2879,9 +2879,8 @@ select option:not(:checked) {
|
||||
color: var(--active) !important;
|
||||
}
|
||||
|
||||
#instruct_enabled_label .menu_button:not(.toggleEnabled),
|
||||
#sysprompt_enabled_label .menu_button:not(.toggleEnabled) {
|
||||
color: Red;
|
||||
.menu_button.togglable:not(.toggleEnabled) {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.displayBlock {
|
||||
|
Reference in New Issue
Block a user