implement jank js + drag n drop sampler priority

This commit is contained in:
kalomaze 2024-02-10 16:32:46 -06:00
parent 818029288e
commit 70deb11d27
2 changed files with 63 additions and 6 deletions

View File

@ -1451,14 +1451,33 @@
<textarea id="banned_tokens_textgenerationwebui" class="text_pole textarea_compact" name="banned_tokens_textgenerationwebui" rows="3" placeholder="Example:&#10;some text&#10;[42, 69, 1337]"></textarea>
</div>
</div>
<div data-newbie-hidden class="wide100p">
<hr data-newbie-hidden class="width100p">
<div data-newbie-hidden class="range-block flexFlowColumn">
<hr class="wide100p">
<h4 class="range-block-title justifyCenter">
<span data-i18n="Sampler Priority">Sampler Priority</span>
<div class="margin5 fa-solid fa-circle-info opacity50p " title="Ooba only.&#13;Determines the order of samplers."></div>
<div class="margin5 fa-solid fa-circle-info opacity50p" title="Ooba only. Determines the order of samplers."></div>
</h4>
<div class="wide100p">
<textarea id="sampler_priority_textgenerationwebui" class="text_pole textarea_compact" name="sampler_priority_textgenerationwebui" rows="3" placeholder="temperature&#10;dynamic_temperature&#10;quadratic_sampling&#10;top_k&#10;top_p&#10;typical_p&#10;epsilon_cutoff&#10;eta_cutoff&#10;tfs&#10;top_a&#10;min_p&#10;mirostat"></textarea>
<div class="toggle-description widthUnset" data-i18n="Ooba only. Determines the order of samplers.">
Ooba only. Determines the order of samplers.
</div>
<div id="sampler_priority_container" class="prompt_order">
<div data-name="temperature" draggable="true"><span>Temperature</span><small></small></div>
<div data-name="dynamic_temperature" draggable="true"><span>Dynamic Temperature</span><small></small></div>
<div data-name="quadratic_sampling" draggable="true"><span>Quadratic / Smooth Sampling</span><small></small></div>
<div data-name="top_k" draggable="true"><span>Top K</span><small></small></div>
<div data-name="top_p" draggable="true"><span>Top P</span><small></small></div>
<div data-name="typical_p" draggable="true"><span>Typical P</span><small></small></div>
<div data-name="epsilon_cutoff" draggable="true"><span>Epsilon Cutoff</span><small></small></div>
<div data-name="eta_cutoff" draggable="true"><span>Eta Cutoff</span><small></small></div>
<div data-name="tfs" draggable="true"><span>Tail Free Sampling</span><small></small></div>
<div data-name="top_a" draggable="true"><span>Top A</span><small></small></div>
<div data-name="min_p" draggable="true"><span>Min P</span><small></small></div>
<div data-name="mirostat" draggable="true"><span>Mirostat</span><small></small></div>
</div>
<textarea id="sampler_priority_textgenerationwebui" name="sampler_priority_textgenerationwebui"
style="display: none;"></textarea>
<div id="textgenerationwebui_default_order" class="menu_button menu_button_icon">
<span data-i18n="Load default order">Load default order</span>
</div>
</div>
<div class="range-block wide100p">

View File

@ -435,6 +435,16 @@ function sortItemsByOrder(orderArray) {
}
}
function sortOobaItemsByOrder(orderArray) {
console.debug('Preset samplers order: ', orderArray);
const $container = $('#sampler_priority_container');
orderArray.forEach((name) => {
const $item = $container.find(`[data-name="${name}"]`).detach();
$container.append($item);
});
}
jQuery(function () {
$('#koboldcpp_order').sortable({
delay: getSortableDelay(),
@ -451,10 +461,38 @@ jQuery(function () {
$('#koboldcpp_default_order').on('click', function () {
settings.sampler_order = KOBOLDCPP_ORDER;
sortItemsByOrder(settings.sampler_order);
sortOobaItemsByOrder(settings.sampler_order);
saveSettingsDebounced();
});
jQuery(function($) {
$('#sampler_priority_container').sortable({
delay: getSortableDelay(),
stop: function() {
const order = [];
$('#sampler_priority_container').children().each(function() {
order.push($(this).data('name'));
});
settings.sampler_priority = order.join('\n');
console.log('Samplers reordered:', settings.sampler_priority);
saveSettingsDebounced();
$('#sampler_priority_textgenerationwebui').val(settings.sampler_priority);
}
});
$('#textgenerationwebui_default_order').on('click', function () {
const defaultOrder = ['temperature', 'dynamic_temperature', 'quadratic_sampling', 'top_k', 'top_p', 'typical_p', 'epsilon_cutoff', 'eta_cutoff', 'tfs', 'top_a', 'min_p', 'mirostat'];
sortOobaItemsByOrder(defaultOrder);
settings.sampler_priority = defaultOrder.join('\n');
console.log('Default samplers order loaded:', settings.sampler_priority);
saveSettingsDebounced();
$('#sampler_priority_textgenerationwebui').val(settings.sampler_priority);
});
});
$('#textgen_type').on('change', function () {
const type = String($(this).val());
settings.type = type;