WIP textgen API custom sampler display
This commit is contained in:
parent
4e9a113a35
commit
c7232ae23c
|
@ -942,7 +942,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="range-block">
|
||||
<div class="range-block-title title_restorable">
|
||||
<div id="logit_bias_novel" class="range-block-title title_restorable">
|
||||
<span data-i18n="Logit Bias">Logit Bias</span>
|
||||
<div id="novelai_logit_bias_new_entry" class="menu_button menu_button_icon">
|
||||
<i class="fa-xs fa-solid fa-plus"></i>
|
||||
|
@ -1131,6 +1131,11 @@
|
|||
<div id="samplerResetButton" class="menu_button whitespacenowrap" data-i18n="Neutralize Samplers">Neutralize Samplers</div>
|
||||
<div class="fa-solid fa-circle-info opacity50p" title="Set all samplers to their neutral/disabled state." data-i18n="[title]Set all samplers to their neutral/disabled state."></div>
|
||||
</small>
|
||||
|
||||
<small class="flex-container alignitemscenter">
|
||||
<div id="samplerSelectButton" class="menu_button whitespacenowrap" data-i18n="Sampler Select">Sampler Select</div>
|
||||
<div class="fa-solid fa-circle-info opacity50p" title="Customize displayed samplers or add custom samplers." data-i18n="[title]Customize displayed samplers or add custom samplers."></div>
|
||||
</small>
|
||||
</div>
|
||||
<div data-newbie-hidden data-tg-type="mancer, vllm, aphrodite" class="flex-container flexFlowColumn alignitemscenter flexBasis100p flexGrow flexShrink gap0">
|
||||
<small data-i18n="Multiple swipes per generation">Multiple swipes per generation</small>
|
||||
|
@ -1267,7 +1272,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-newbie-hidden data-tg-type="ooba, mancer, koboldcpp, tabby, llamacpp, aphrodite" name="dynaTempBlock" class="wide100p">
|
||||
<div data-newbie-hidden data-tg-type="ooba, mancer, koboldcpp, tabby, llamacpp, aphrodite" id="dynatemp_block_ooba" class="wide100p">
|
||||
<h4 class="wide100p textAlignCenter">
|
||||
<div class="flex-container alignitemscenter justifyCenter">
|
||||
<div class="checkbox_label" for="dynatemp_textgenerationwebui">
|
||||
|
@ -1295,7 +1300,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-newbie-hidden name="miroStatBlock" class="wide100p">
|
||||
<div data-newbie-hidden id="mirostat_block_ooba" class="wide100p">
|
||||
<h4 class="wide100p textAlignCenter">
|
||||
<label data-i18n="Mirostat (mode=1 is only for llama.cpp)">Mirostat</label>
|
||||
<div class=" fa-solid fa-circle-info opacity50p " data-i18n="[title]Mirostat is a thermostat for output perplexity" title="Mirostat is a thermostat for output perplexity. Mirostat matches the output perplexity to that of the input, thus avoiding the repetition trap (where, as the autoregressive inference produces text, the perplexity of the output tends toward zero) and the confusion trap (where the perplexity diverges). For details, see the paper Mirostat: A Neural Text Decoding Algorithm that Directly Controls Perplexity by Basu et al. (2020). Mode chooses the Mirostat version. 0=disable, 1=Mirostat 1.0 (llama.cpp only), 2=Mirostat 2.0."></div>
|
||||
|
@ -1411,7 +1416,7 @@
|
|||
<small data-i18n="Seed" class="textAlignCenter">Seed</small>
|
||||
<input type="number" id="seed_textgenerationwebui" class="text_pole textAlignCenter" min="-1" value="-1" maxlength="100" />
|
||||
</div>
|
||||
<div data-newbie-hidden class="wide100p">
|
||||
<div id="banned_tokens_block_ooba" data-newbie-hidden class="wide100p">
|
||||
<hr data-newbie-hidden class="width100p">
|
||||
<h4 class="range-block-title justifyCenter">
|
||||
<span data-i18n="Banned Tokens">Banned Tokens</span>
|
||||
|
@ -1422,7 +1427,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="range-block wide100p">
|
||||
<div class="range-block-title title_restorable">
|
||||
<div id="logit_bias_textgenerationwebui" class="range-block-title title_restorable">
|
||||
<span data-i18n="Logit Bias">Logit Bias</span>
|
||||
<div id="textgen_logit_bias_new_entry" class="menu_button menu_button_icon">
|
||||
<i class="fa-xs fa-solid fa-plus"></i>
|
||||
|
@ -1436,7 +1441,7 @@
|
|||
<div class="logit_bias_list"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-newbie-hidden data-tg-type="ooba, tabby" class="wide100p">
|
||||
<div id="cfg_block_ooba" data-newbie-hidden data-tg-type="ooba, tabby" class="wide100p">
|
||||
<hr class="width100p">
|
||||
<h4 data-i18n="CFG" class="textAlignCenter">CFG
|
||||
<div class="margin5 fa-solid fa-circle-info opacity50p " data-i18n="[title]Classifier Free Guidance. More helpful tip coming soon" title="Classifier Free Guidance. More helpful tip coming soon."></div>
|
||||
|
@ -1484,7 +1489,7 @@
|
|||
</h4>
|
||||
<textarea id="grammar_string_textgenerationwebui" rows="4" class="text_pole textarea_compact monospace" data-i18n="[placeholder]Type in the desired custom grammar" placeholder="Type in the desired custom grammar"></textarea>
|
||||
</div>
|
||||
<div data-newbie-hidden data-tg-type="koboldcpp" class="range-block flexFlowColumn wide100p">
|
||||
<div id="sampler_order_block" data-newbie-hidden data-tg-type="koboldcpp" class="range-block flexFlowColumn wide100p">
|
||||
<hr class="wide100p">
|
||||
<div class="range-block-title">
|
||||
<span data-i18n="Samplers Order">Samplers Order</span>
|
||||
|
@ -1759,7 +1764,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div data-newbie-hidden class="range-block m-t-1" data-source="openai,openrouter,scale">
|
||||
<div class="range-block-title openai_restorable" data-i18n="Logit Bias">
|
||||
<div id="logit_bias_openai" class="range-block-title openai_restorable" data-i18n="Logit Bias">
|
||||
Logit Bias
|
||||
</div>
|
||||
<div class="toggle-description justifyLeft" data-i18n="Helps to ban or reenforce the usage of certain words">
|
||||
|
@ -6376,4 +6381,4 @@
|
|||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
|
@ -231,6 +231,7 @@ import { SlashCommandParser } from './scripts/slash-commands/SlashCommandParser.
|
|||
import { SlashCommand } from './scripts/slash-commands/SlashCommand.js';
|
||||
import { ARGUMENT_TYPE, SlashCommandArgument } from './scripts/slash-commands/SlashCommandArgument.js';
|
||||
import { SlashCommandBrowser } from './scripts/slash-commands/SlashCommandBrowser.js';
|
||||
import { initCustomSelectedSamplers, validateDisabledSamplers } from './scripts/samplerSelect.js';
|
||||
|
||||
//exporting functions and vars for mods
|
||||
export {
|
||||
|
@ -2718,7 +2719,7 @@ class StreamingProcessor {
|
|||
let messageId = -1;
|
||||
|
||||
if (this.type == 'impersonate') {
|
||||
$('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles:true }));
|
||||
$('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
else {
|
||||
await saveReply(this.type, text, true);
|
||||
|
@ -2754,7 +2755,7 @@ class StreamingProcessor {
|
|||
}
|
||||
|
||||
if (isImpersonate) {
|
||||
$('#send_textarea').val(processedText)[0].dispatchEvent(new Event('input', { bubbles:true }));
|
||||
$('#send_textarea').val(processedText)[0].dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
else {
|
||||
let currentTime = new Date();
|
||||
|
@ -3133,7 +3134,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||
|
||||
if (!pingResult) {
|
||||
unblockGeneration(type);
|
||||
toastr.error('Verify that the server is running and accessible.', 'ST Server cannot be reached' );
|
||||
toastr.error('Verify that the server is running and accessible.', 'ST Server cannot be reached');
|
||||
throw new Error('Server unreachable');
|
||||
}
|
||||
|
||||
|
@ -3196,7 +3197,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||
if (type !== 'regenerate' && type !== 'swipe' && type !== 'quiet' && !isImpersonate && !dryRun) {
|
||||
is_send_press = true;
|
||||
textareaText = String($('#send_textarea').val());
|
||||
$('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles:true }));
|
||||
$('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
|
||||
} else {
|
||||
textareaText = '';
|
||||
if (chat.length && chat[chat.length - 1]['is_user']) {
|
||||
|
@ -4158,7 +4159,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||
|
||||
if (getMessage.length > 0) {
|
||||
if (isImpersonate) {
|
||||
$('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles:true }));
|
||||
$('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true }));
|
||||
generatedPromptCache = '';
|
||||
await eventSource.emit(event_types.IMPERSONATE_READY, getMessage);
|
||||
}
|
||||
|
@ -5933,7 +5934,7 @@ export function changeMainAPI() {
|
|||
getStatusHorde();
|
||||
getHordeModels(true);
|
||||
}
|
||||
|
||||
validateDisabledSamplers()
|
||||
setupChatCompletionPromptManager(oai_settings);
|
||||
forceCharacterEditorTokenize();
|
||||
}
|
||||
|
@ -6087,6 +6088,7 @@ export async function getSettings() {
|
|||
// TextGen
|
||||
loadTextGenSettings(data, settings);
|
||||
|
||||
|
||||
// OpenAI
|
||||
loadOpenAISettings(data, settings.oai_settings ?? settings);
|
||||
|
||||
|
@ -6132,6 +6134,7 @@ export async function getSettings() {
|
|||
);
|
||||
changeMainAPI();
|
||||
|
||||
|
||||
//Load User's Name and Avatar
|
||||
initUserAvatar(settings.user_avatar);
|
||||
setPersonaDescription();
|
||||
|
@ -6162,7 +6165,7 @@ export async function getSettings() {
|
|||
firstRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
await validateDisabledSamplers()
|
||||
settingsReady = true;
|
||||
eventSource.emit(event_types.SETTINGS_LOADED);
|
||||
}
|
||||
|
@ -8564,11 +8567,13 @@ jQuery(async function () {
|
|||
toastr.success('Chat and settings saved.');
|
||||
}
|
||||
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'dupe',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'dupe',
|
||||
callback: DupeChar,
|
||||
helpString: 'Duplicates the currently selected character.',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'api',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'api',
|
||||
callback: connectAPISlash,
|
||||
namedArgumentList: [],
|
||||
unnamedArgumentList: [
|
||||
|
@ -8591,7 +8596,8 @@ jQuery(async function () {
|
|||
</div>
|
||||
`,
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'impersonate',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'impersonate',
|
||||
callback: doImpersonate,
|
||||
aliases: ['imp'],
|
||||
unnamedArgumentList: [
|
||||
|
@ -8613,7 +8619,8 @@ jQuery(async function () {
|
|||
</div>
|
||||
`,
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'delchat',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'delchat',
|
||||
callback: doDeleteChat,
|
||||
helpString: 'Deletes the current chat.',
|
||||
}));
|
||||
|
@ -8627,25 +8634,30 @@ jQuery(async function () {
|
|||
],
|
||||
helpString: 'Renames the current chat.',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'getchatname',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'getchatname',
|
||||
callback: doGetChatName,
|
||||
returns: 'chat file name',
|
||||
helpString: 'Returns the name of the current chat file into the pipe.',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'closechat',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'closechat',
|
||||
callback: doCloseChat,
|
||||
helpString: 'Closes the current chat.',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'panels',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'panels',
|
||||
callback: doTogglePanels,
|
||||
aliases: ['togglepanels'],
|
||||
helpString: 'Toggle UI panels on/off',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'forcesave',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'forcesave',
|
||||
callback: doForceSave,
|
||||
helpString: 'Forces a save of the current chat and settings',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'instruct',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'instruct',
|
||||
callback: selectInstructCallback,
|
||||
returns: 'current preset',
|
||||
namedArgumentList: [],
|
||||
|
@ -8668,15 +8680,18 @@ jQuery(async function () {
|
|||
</div>
|
||||
`,
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'instruct-on',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'instruct-on',
|
||||
callback: enableInstructCallback,
|
||||
helpString: 'Enables instruct mode.',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'instruct-off',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'instruct-off',
|
||||
callback: disableInstructCallback,
|
||||
helpString: 'Disables instruct mode',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'context',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'context',
|
||||
callback: selectContextCallback,
|
||||
returns: 'template name',
|
||||
unnamedArgumentList: [
|
||||
|
@ -8686,7 +8701,8 @@ jQuery(async function () {
|
|||
],
|
||||
helpString: 'Selects context template by name. Gets the current template if no name is provided',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'chat-manager',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'chat-manager',
|
||||
callback: () => $('#option_select_chat').trigger('click'),
|
||||
aliases: ['chat-history', 'manage-chats'],
|
||||
helpString: 'Opens the chat manager for the current character/group.',
|
||||
|
@ -10338,7 +10354,7 @@ jQuery(async function () {
|
|||
$('#character_replace_file').off('change').on('change', uploadReplacementCard).trigger('click');
|
||||
}
|
||||
} break;
|
||||
case 'import_tags':{
|
||||
case 'import_tags': {
|
||||
await importTags(characters[this_chid]);
|
||||
} break;
|
||||
/*case 'delete_button':
|
||||
|
@ -10546,4 +10562,6 @@ jQuery(async function () {
|
|||
eventSource.on(event_types.GROUP_CHAT_DELETED, async (name) => {
|
||||
await deleteItemizedPrompts(name);
|
||||
});
|
||||
|
||||
initCustomSelectedSamplers();
|
||||
});
|
||||
|
|
|
@ -0,0 +1,438 @@
|
|||
import {
|
||||
main_api,
|
||||
saveSettingsDebounced,
|
||||
novelai_setting_names,
|
||||
callPopup,
|
||||
settings,
|
||||
} from '../script.js';
|
||||
import { power_user } from './power-user.js';
|
||||
//import { BIAS_CACHE, displayLogitBias, getLogitBiasListResult } from './logit-bias.js';
|
||||
//import { getEventSourceStream } from './sse-stream.js';
|
||||
//import { getSortableDelay, onlyUnique } from './utils.js';
|
||||
//import { getCfgPrompt } from './cfg-scale.js';
|
||||
import { setting_names } from './textgen-settings.js';
|
||||
|
||||
|
||||
const TGsamplerNames = setting_names;
|
||||
|
||||
const forcedOnColoring = 'filter: sepia(1) hue-rotate(59deg) contrast(1.5) saturate(3.5)';
|
||||
const forcedOffColoring = 'filter: sepia(1) hue-rotate(308deg) contrast(0.7) saturate(10)';
|
||||
|
||||
let userDisabledSamplers, userShownSamplers;
|
||||
|
||||
/*
|
||||
|
||||
for reference purposes:
|
||||
|
||||
//NAI
|
||||
const nai_settings = {
|
||||
temperature: 1.5,
|
||||
repetition_penalty: 2.25,
|
||||
repetition_penalty_range: 2048,
|
||||
repetition_penalty_slope: 0.09,
|
||||
repetition_penalty_frequency: 0,
|
||||
repetition_penalty_presence: 0.005,
|
||||
tail_free_sampling: 0.975,
|
||||
top_k: 10,
|
||||
top_p: 0.75,
|
||||
top_a: 0.08,
|
||||
typical_p: 0.975,
|
||||
min_length: 1,
|
||||
model_novel: 'clio-v1',
|
||||
preset_settings_novel: 'Talker-Chat-Clio',
|
||||
streaming_novel: false,
|
||||
preamble: default_preamble,
|
||||
prefix: '',
|
||||
cfg_uc: '',
|
||||
banned_tokens: '',
|
||||
order: default_order,
|
||||
logit_bias: [],
|
||||
};
|
||||
|
||||
// TG Types
|
||||
export const textgen_types = {
|
||||
OOBA: 'ooba',
|
||||
MANCER: 'mancer',
|
||||
VLLM: 'vllm',
|
||||
APHRODITE: 'aphrodite',
|
||||
TABBY: 'tabby',
|
||||
KOBOLDCPP: 'koboldcpp',
|
||||
TOGETHERAI: 'togetherai',
|
||||
LLAMACPP: 'llamacpp',
|
||||
OLLAMA: 'ollama',
|
||||
INFERMATICAI: 'infermaticai',
|
||||
DREAMGEN: 'dreamgen',
|
||||
OPENROUTER: 'openrouter',
|
||||
};
|
||||
|
||||
//KAI and TextGen
|
||||
const setting_names = [
|
||||
'temp',
|
||||
'temperature_last',
|
||||
'rep_pen',
|
||||
'rep_pen_range',
|
||||
'no_repeat_ngram_size',
|
||||
'top_k',
|
||||
'top_p',
|
||||
'top_a',
|
||||
'tfs',
|
||||
'epsilon_cutoff',
|
||||
'eta_cutoff',
|
||||
'typical_p',
|
||||
'min_p',
|
||||
'penalty_alpha',
|
||||
'num_beams',
|
||||
'length_penalty',
|
||||
'min_length',
|
||||
'dynatemp',
|
||||
'min_temp',
|
||||
'max_temp',
|
||||
'dynatemp_exponent',
|
||||
'smoothing_factor',
|
||||
'smoothing_curve',
|
||||
'max_tokens_second',
|
||||
'encoder_rep_pen',
|
||||
'freq_pen',
|
||||
'presence_pen',
|
||||
'do_sample',
|
||||
'early_stopping',
|
||||
'seed',
|
||||
'add_bos_token',
|
||||
'ban_eos_token',
|
||||
'skip_special_tokens',
|
||||
'streaming',
|
||||
'mirostat_mode',
|
||||
'mirostat_tau',
|
||||
'mirostat_eta',
|
||||
'guidance_scale',
|
||||
'negative_prompt',
|
||||
'grammar_string',
|
||||
'json_schema',
|
||||
'banned_tokens',
|
||||
'legacy_api',
|
||||
//'n_aphrodite',
|
||||
//'best_of_aphrodite',
|
||||
'ignore_eos_token',
|
||||
'spaces_between_special_tokens',
|
||||
//'logits_processors_aphrodite',
|
||||
//'log_probs_aphrodite',
|
||||
//'prompt_log_probs_aphrodite'
|
||||
'sampler_order',
|
||||
'sampler_priority',
|
||||
'samplers',
|
||||
'n',
|
||||
'logit_bias',
|
||||
'custom_model',
|
||||
'bypass_status_check',
|
||||
];
|
||||
|
||||
//OAI settings
|
||||
|
||||
const default_settings = {
|
||||
preset_settings_openai: 'Default',
|
||||
temp_openai: 1.0,
|
||||
freq_pen_openai: 0,
|
||||
pres_pen_openai: 0,
|
||||
count_pen: 0.0,
|
||||
top_p_openai: 1.0,
|
||||
top_k_openai: 0,
|
||||
min_p_openai: 0,
|
||||
top_a_openai: 1,
|
||||
repetition_penalty_openai: 1,
|
||||
stream_openai: false,
|
||||
//...
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// Goal 1: show popup with all samplers for active API
|
||||
async function showSamplerSelectPopup() {
|
||||
const popup = $('#dialogue_popup');
|
||||
popup.addClass('large_dialogue_popup');
|
||||
const html = $(document.createElement('div'));
|
||||
html.attr('id', 'sampler_view_list')
|
||||
.addClass('flex-container flexFlowColumn');
|
||||
html.append(`
|
||||
<div class="title_restorable flexFlowColumn alignItemsBaseline">
|
||||
<div class="flex-container justifyCenter">
|
||||
<h3>Sampler Select</h3>
|
||||
<div class="flex-container alignItemsBaseline">
|
||||
<div id="resetSelectedSamplers" class="menu_button menu_button_icon tag_view_create" title="Reset custom sampler selection">
|
||||
<i class="fa-solid fa-recycle"></i>
|
||||
</div>
|
||||
</div>
|
||||
<!--<div class="flex-container alignItemsBaseline">
|
||||
<div class="menu_button menu_button_icon tag_view_create" title="Create a new sampler">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
<span data-i18n="Create">Create</span>
|
||||
</div>
|
||||
</div>-->
|
||||
</div>
|
||||
<small>Here you can toggle the display of individual samplers. (WIP)</small>
|
||||
</div>
|
||||
<hr>`);
|
||||
|
||||
const listContainer = $('<div id="apiSamplersList" class="flex-container flexNoGap"></div>');
|
||||
const APISamplers = await listSamplers(main_api);
|
||||
listContainer.append(APISamplers);
|
||||
html.append(listContainer);
|
||||
|
||||
callPopup(html, 'text', null, { allowVerticalScrolling: true });
|
||||
|
||||
setSamplerListListeners();
|
||||
|
||||
$('#resetSelectedSamplers').off('click').on('click', async function () {
|
||||
console.log('saw sampler select reset click');
|
||||
userDisabledSamplers = [];
|
||||
userShownSamplers = [];
|
||||
power_user.selectSamplers.forceShown = [];
|
||||
power_user.selectSamplers.forceHidden = [];
|
||||
await validateDisabledSamplers(true);
|
||||
});
|
||||
}
|
||||
|
||||
function setSamplerListListeners() {
|
||||
// Goal 2: hide unchecked samplers from DOM
|
||||
let listContainer = $('#apiSamplersList')
|
||||
listContainer.find('input').off('change').on('change', async function () {
|
||||
|
||||
const samplerName = this.name.replace('_checkbox', '');
|
||||
let relatedDOMElement = $(`#${samplerName}_${main_api}`).parent();
|
||||
let targetDisplayType = 'flex';
|
||||
|
||||
if (samplerName === 'json_schema') {
|
||||
relatedDOMElement = $('#json_schema_block');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (samplerName === 'grammar_string') {
|
||||
relatedDOMElement = $('#grammar_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (samplerName === 'guidance_scale') {
|
||||
relatedDOMElement = $('#cfg_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (samplerName === 'mirostat_mode') {
|
||||
relatedDOMElement = $('#mirostat_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (samplerName === 'dynatemp') {
|
||||
relatedDOMElement = $('#dynatemp_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (samplerName === 'banned_tokens') {
|
||||
relatedDOMElement = $('#banned_tokens_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (samplerName === 'sampler_order') {
|
||||
relatedDOMElement = $('#sampler_order_block');
|
||||
targetDisplayType = 'flex';
|
||||
}
|
||||
|
||||
// Get the current state of the custom data attribute
|
||||
const previousState = relatedDOMElement.data('selectsampler');
|
||||
|
||||
if ($(this).prop('checked') === false) {
|
||||
//console.log('saw clicking checkbox from on to off...');
|
||||
if (previousState === 'shown') {
|
||||
console.log('saw previously custom shown sampler');
|
||||
//console.log('removing from custom force show list');
|
||||
relatedDOMElement.removeData('selectsampler');
|
||||
$(this).parent().find('.sampler_name').removeAttr('style');
|
||||
power_user?.selectSamplers?.forceShown.splice(power_user?.selectSamplers?.forceShown.indexOf(samplerName), 1);
|
||||
console.log(power_user?.selectSamplers?.forceShown);
|
||||
} else {
|
||||
console.log('saw previous untouched sampler');
|
||||
//console.log(`adding ${samplerName} to force hide list`);
|
||||
relatedDOMElement.data('selectsampler', 'hidden');
|
||||
console.log(relatedDOMElement.data('selectsampler'));
|
||||
power_user.selectSamplers.forceHidden.push(samplerName);
|
||||
$(this).parent().find('.sampler_name').attr('style', forcedOffColoring);
|
||||
console.log(power_user.selectSamplers.forceHidden);
|
||||
}
|
||||
} else { // going from unchecked to checked
|
||||
//console.log('saw clicking checkbox from off to on...');
|
||||
if (previousState === 'hidden') {
|
||||
console.log('saw previously custom hidden sampler');
|
||||
//console.log('removing from custom force hide list');
|
||||
relatedDOMElement.removeData('selectsampler');
|
||||
$(this).parent().find('.sampler_name').removeAttr('style');
|
||||
power_user?.selectSamplers?.forceHidden.splice(power_user?.selectSamplers?.forceHidden.indexOf(samplerName), 1);
|
||||
console.log(power_user?.selectSamplers?.forceHidden);
|
||||
} else {
|
||||
console.log('saw previous untouched sampler');
|
||||
//console.log(`adding ${samplerName} to force shown list`);
|
||||
relatedDOMElement.data('selectsampler', 'shown');
|
||||
console.log(relatedDOMElement.data('selectsampler'));
|
||||
power_user.selectSamplers.forceShown.push(samplerName);
|
||||
$(this).parent().find('.sampler_name').attr('style', forcedOnColoring);
|
||||
console.log(power_user.selectSamplers.forceShown);
|
||||
}
|
||||
}
|
||||
await saveSettingsDebounced();
|
||||
|
||||
const shouldDisplay = $(this).prop('checked') ? targetDisplayType : 'none';
|
||||
relatedDOMElement.css('display', shouldDisplay);
|
||||
|
||||
console.log(samplerName, relatedDOMElement.data('selectsampler'), shouldDisplay);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function isElementVisibleInDOM(element) {
|
||||
while (element && element !== document.body) {
|
||||
if (window.getComputedStyle(element).display === 'none') {
|
||||
return false;
|
||||
}
|
||||
element = element.parentElement;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
async function listSamplers(main_api, arrayOnly = false) {
|
||||
let availableSamplers;
|
||||
if (main_api === 'textgenerationwebui') {
|
||||
availableSamplers = TGsamplerNames;
|
||||
const valuesToRemove = new Set(['streaming', 'seed', 'bypass_status_check', 'custom_model', 'legacy_api', 'samplers']);
|
||||
availableSamplers = availableSamplers.filter(sampler => !valuesToRemove.has(sampler));
|
||||
availableSamplers.sort();
|
||||
}
|
||||
|
||||
if (arrayOnly) {
|
||||
console.log('returning full samplers array');
|
||||
return availableSamplers;
|
||||
}
|
||||
|
||||
const samplersListHTML = availableSamplers.reduce((html, sampler) => {
|
||||
let customColor;
|
||||
const targetDOMelement = $(`#${sampler}_${main_api}`);
|
||||
|
||||
const isInForceHiddenArray = userDisabledSamplers.includes(sampler);
|
||||
const isInForceShownArray = userShownSamplers.includes(sampler);
|
||||
let isVisibleInDOM = isElementVisibleInDOM(targetDOMelement[0]);
|
||||
const isInDefaultState = () => {
|
||||
if (isVisibleInDOM && isInForceShownArray) { return false; }
|
||||
else if (!isVisibleInDOM && isInForceHiddenArray) { return false; }
|
||||
else { return true; }
|
||||
};
|
||||
|
||||
const shouldBeChecked = () => {
|
||||
if (isInForceHiddenArray) {
|
||||
customColor = forcedOffColoring;
|
||||
return false;
|
||||
}
|
||||
else if (isInForceShownArray) {
|
||||
customColor = forcedOnColoring;
|
||||
return true;
|
||||
}
|
||||
else { return isVisibleInDOM; }
|
||||
};
|
||||
console.log(sampler, isInDefaultState(), isInForceHiddenArray, shouldBeChecked());
|
||||
return html + `
|
||||
<div class="sampler_view_list_item wide50p flex-container">
|
||||
<input type="checkbox" name="${sampler}_checkbox" ${shouldBeChecked() ? 'checked' : ''}>
|
||||
<small class="sampler_name" style="${customColor}">${sampler}</small>
|
||||
</div>
|
||||
`;
|
||||
}, '');
|
||||
|
||||
return samplersListHTML;
|
||||
}
|
||||
|
||||
// Goal 3: make "sampler is hidden/disabled" status persistent (save settings)
|
||||
// this runs on initial getSettings as well as after API changes
|
||||
|
||||
export async function validateDisabledSamplers(redraw = false) {
|
||||
const APISamplers = await listSamplers(main_api, true);
|
||||
|
||||
|
||||
for (const sampler of APISamplers) {
|
||||
let relatedDOMElement = $(`#${sampler}_${main_api}`).parent();
|
||||
let targetDisplayType = 'flex';
|
||||
|
||||
if (sampler === 'json_schema') {
|
||||
relatedDOMElement = $('#json_schema_block');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (sampler === 'grammar_string') {
|
||||
relatedDOMElement = $('#grammar_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (sampler === 'guidance_scale') {
|
||||
relatedDOMElement = $('#cfg_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (sampler === 'mirostat_mode') {
|
||||
relatedDOMElement = $('#mirostat_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (sampler === 'dynatemp') {
|
||||
relatedDOMElement = $('#dynatemp_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (sampler === 'banned_tokens') {
|
||||
relatedDOMElement = $('#banned_tokens_block_ooba');
|
||||
targetDisplayType = 'block';
|
||||
}
|
||||
|
||||
if (sampler === 'sampler_order') {
|
||||
relatedDOMElement = $('#sampler_order_block');
|
||||
}
|
||||
|
||||
if (power_user?.selectSamplers?.forceHidden.includes(sampler)) {
|
||||
//default handling for standard sliders
|
||||
relatedDOMElement.data('selectsampler', 'hidden');
|
||||
relatedDOMElement.css('display', 'none');
|
||||
} else if (power_user?.selectSamplers?.forceShown.includes(sampler)) {
|
||||
relatedDOMElement.data('selectsampler', 'shown');
|
||||
relatedDOMElement.css('display', targetDisplayType);
|
||||
} else {
|
||||
if (relatedDOMElement.data('selectsampler') === 'hidden') {
|
||||
relatedDOMElement.removeAttr('selectsampler');
|
||||
relatedDOMElement.css('display', targetDisplayType);
|
||||
}
|
||||
if (relatedDOMElement.data('selectsampler') === 'shown') {
|
||||
relatedDOMElement.removeAttr('selectsampler');
|
||||
relatedDOMElement.css('display', 'none');
|
||||
}
|
||||
}
|
||||
if (redraw) {
|
||||
let samplersHTML = await listSamplers(main_api);
|
||||
$('#apiSamplersList').empty().append(samplersHTML);
|
||||
setSamplerListListeners();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function initCustomSelectedSamplers() {
|
||||
|
||||
userDisabledSamplers = power_user?.selectSamplers?.forceHidden || [];
|
||||
userShownSamplers = power_user?.selectSamplers?.forceShown || [];
|
||||
power_user.selectSamplers = {};
|
||||
power_user.selectSamplers.forceHidden = userDisabledSamplers;
|
||||
power_user.selectSamplers.forceShown = userShownSamplers;
|
||||
await saveSettingsDebounced();
|
||||
$('#samplerSelectButton').off('click').on('click', showSamplerSelectPopup);
|
||||
|
||||
}
|
||||
|
||||
// Goal 4: filter hidden samplers from API output
|
||||
|
||||
// Goal 5: allow addition of custom samplers to be displayed
|
||||
// Goal 6: send custom sampler values into prompt
|
|
@ -166,7 +166,7 @@ export let textgenerationwebui_banned_in_macros = [];
|
|||
export let textgenerationwebui_presets = [];
|
||||
export let textgenerationwebui_preset_names = [];
|
||||
|
||||
const setting_names = [
|
||||
export const setting_names = [
|
||||
'temp',
|
||||
'temperature_last',
|
||||
'rep_pen',
|
||||
|
|
Loading…
Reference in New Issue