Feat/Link sampler selection lock to TC API Type (#4782)

* Update - Revert connection profile change TC commands load order

This change was made to prevent preset tied samplers from breaking, such thing doesn't exist anymore.

* Update - Unlink preset renaming logic from sampler selection lock

* Update - Link TC sampler selection lock to API Type

* Fix - Clean comments

* Update - Use localforage selectedSamplers and data selectsampler as main sampler selection storage

* Fix - ESLint errors

* Update - Change lock tooltip with correct description

* Fix - Move and await sampler select localforage initializer to finish

Tried to move it to the most reasonable place possible that allowed to make an await.

* Fix - Make loadTextGenSettings async to load API selected samplers
This commit is contained in:
Leandro Jofré
2025-11-20 20:57:23 -03:00
committed by GitHub
parent 35949cac01
commit e8a75c3329
6 changed files with 216 additions and 394 deletions
+13 -18
View File
@@ -20,7 +20,7 @@ import { autoSelectInstructPreset, selectContextPreset, selectInstructPreset } f
import { BIAS_CACHE, createNewLogitBiasEntry, displayLogitBias, getLogitBiasListResult } from './logit-bias.js';
import { power_user, registerDebugFunction } from './power-user.js';
import { getManualActivePresetSamplers, isSamplerManualPriorityEnabled, loadPresetSelectedSamplers } from './samplerSelect.js';
import { getActiveManualApiSamplers, loadApiSelectedSamplers, isSamplerManualPriorityEnabled } from './samplerSelect.js';
import { SECRET_KEYS, writeSecret } from './secrets.js';
import { getEventSourceStream } from './sse-stream.js';
import { getCurrentDreamGenModelTokenizer, getCurrentOpenRouterModelTokenizer, loadAphroditeModels, loadDreamGenModels, loadFeatherlessModels, loadGenericModels, loadInfermaticAIModels, loadMancerModels, loadOllamaModels, loadOpenRouterModels, loadTabbyModels, loadTogetherAIModels, loadVllmModels } from './textgen-models.js';
@@ -372,7 +372,6 @@ async function selectPreset(name) {
setSettingByName(name, value, true);
}
setGenerationParamsFromPreset(preset);
showSamplerControls(null, true);
BIAS_CACHE.delete(BIAS_KEY);
displayLogitBias(preset.logit_bias, BIAS_KEY);
saveSettingsDebounced();
@@ -530,7 +529,8 @@ function calculateLogitBias() {
return result;
}
export function loadTextGenSettings(data, loadedSettings) {
export async function loadTextGenSettings(data, loadedSettings) {
await loadApiSelectedSamplers();
textgenerationwebui_presets = convertPresets(data.textgenerationwebui_presets);
textgenerationwebui_preset_names = data.textgenerationwebui_preset_names ?? [];
Object.assign(settings, loadedSettings.textgenerationwebui_settings ?? {});
@@ -572,8 +572,7 @@ export function loadTextGenSettings(data, loadedSettings) {
$('#textgen_type').val(settings.type);
$('#openrouter_providers_text').val(settings.openrouter_providers).trigger('change');
loadPresetSelectedSamplers();
showSamplerControls();
showSamplerControls(settings.type);
BIAS_CACHE.delete(BIAS_KEY);
displayLogitBias(settings.logit_bias, BIAS_KEY);
@@ -779,8 +778,6 @@ async function getStatusTextgen() {
}
export function initTextGenSettings() {
loadPresetSelectedSamplers();
$('#send_banned_tokens_textgenerationwebui').on('change', function () {
const checked = !!$(this).prop('checked');
toggleBannedStringsKillSwitch(checked,
@@ -1078,21 +1075,19 @@ export function initTextGenSettings() {
/**
* Hides and shows preset samplers from the left panel.
* @param {string?} apiType API Type selected in API Connections - Currently selected one by default
* @param {boolean?} isPresetSwitch Wheter the trigger comes from a preset switch - false by default
* @returns void
*/
function showSamplerControls(apiType = null, isPresetSwitch = false) {
const prioritizeManualSamplerSelect = isSamplerManualPriorityEnabled();
function showSamplerControls(apiType = null) {
$('#textgenerationwebui_api-settings [data-tg-samplers]').each(function(idx, elem) {
const typeSpecificControlled = $(elem).data('tg-type') !== undefined;
if (isPresetSwitch && !prioritizeManualSamplerSelect) return;
$('#textgenerationwebui_api-settings [data-tg-samplers]:not([data-tg-type])').each(function() {
$(this).show();
if (!typeSpecificControlled) $(this).show();
});
showTypeSpecificControls(apiType ?? settings.type);
const samplersActivatedManually = getManualActivePresetSamplers();
const prioritizeManualSamplerSelect = isSamplerManualPriorityEnabled(apiType ?? settings.type);
const samplersActivatedManually = getActiveManualApiSamplers(apiType ?? settings.type);
if (!samplersActivatedManually?.length || !prioritizeManualSamplerSelect) return;
@@ -1110,18 +1105,18 @@ function showSamplerControls(apiType = null, isPresetSwitch = false) {
});
}
function showTypeSpecificControls(type) {
function showTypeSpecificControls(apiType) {
$('[data-tg-type]').each(function () {
const mode = String($(this).attr('data-tg-type-mode') ?? '').toLowerCase().trim();
const tgTypes = $(this).attr('data-tg-type').split(',').map(x => x.trim());
if (mode === 'except') {
$(this)[tgTypes.includes(type) ? 'hide' : 'show']();
$(this)[tgTypes.includes(apiType) ? 'hide' : 'show']();
return;
}
for (const tgType of tgTypes) {
if (tgType === type || tgType == 'all') {
if (tgType === apiType || tgType == 'all') {
$(this).show();
return;
} else {