embetterify Sampler Select function

7acc78db0ac4fe81b8a97c8018ab2b61c990686d

RossAscends <124905043+RossAscends@users.noreply.github.com>

2 files changed, +144 -148Ignore whitespace
public/index.html+10 -10
@@ -1273,7 +1273,7 @@
12731273 <input class="neo-range-slider" type="range" id="max_tokens_second_textgenerationwebui" name="volume" min="0" max="20" step="1" />
12741274 <input class="neo-range-input" type="number" min="0" max="20" step="1" data-for="max_tokens_second_textgenerationwebui" id="max_tokens_second_counter_textgenerationwebui">
12751275 </div>
12761276 <div data-newbie-hidden data-tg-type="mancer, ooba, koboldcpp, aphrodite, tabby" id="smoothingBlock" name="smoothingBlock" class="wide100p">
12771277 <h4 class="wide100p textAlignCenter">
12781278 <label data-i18n="Smooth Sampling">Smooth Sampling</label>
12791279 <div class=" fa-solid fa-circle-info opacity50p " data-i18n="[title]Smooth_Sampling_desc" title="Allows you to use quadratic/cubic transformations to adjust the distribution. Lower Smoothing Factor values will be more creative, usually between 0.2-0.3 is the sweetspot (assuming the curve = 1). Higher Smoothing Curve values will make the curve steeper, which will punish low probability choices more aggressively. 1.0 curve is equivalent to only using Smoothing Factor."></div>
@@ -1387,7 +1387,7 @@
13871387 </div>
13881388 </div>
13891389 </div>
13901390 <div data-newbie-hidden data-tg-type="ooba, vllm" id="beamSearchBlock" name="beamSearchBlock" class="wide100p">
13911391 <h4 class="wide100p textAlignCenter">
13921392 <label>
13931393 <span data-i18n="Beam search">Beam Search</span>
@@ -1413,7 +1413,7 @@
14131413 </div>
14141414 </div>
14151415 </div>
14161416 <div data-tg-type="ooba" data-newbie-hidden id="contrastiveSearchBlock" name="contrastiveSearchBlock" class="alignitemscenter flex-container flexFlowColumn flexBasis48p flexGrow flexShrink gap0">
14171417 <h4 class="textAlignCenter" data-i18n="Contrastive search">Contrastive Search
14181418 <div class=" fa-solid fa-circle-info opacity50p " data-i18n="Contrastive_search_txt" title="A sampler that encourages diversity while maintaining coherence, by exploiting the isotropicity of the representation space of most LLMs. For details, see the paper A Contrastive Framework for Neural Text Generation by Su et al. (2022)."></div>
14191419 </h4>
@@ -1554,13 +1554,13 @@
15541554 </h4>
15551555 <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>
15561556 </div>
15571557 <div id="sampler_order_blocksampler_order_block_kcpp" data-newbie-hidden data-tg-type="koboldcpp" class="range-block flexFlowColumn wide100p">
15581558 <hr class="wide100p">
15591559 <div class="range-block-title">
15601560 <span data-i18n="Samplers Order">Samplers Order</span>
15611561 </div>
15621562 <div class="toggle-description widthUnset" data-i18n="Samplers will be applied in a top-down order. Use with caution.">
15631563 kcpp only. Samplers will be applied in a top-down order.
15641564 Use with caution.
15651565 </div>
15661566 <div id="koboldcpp_order" class="prompt_order">
@@ -1597,10 +1597,10 @@
15971597 <span data-i18n="Load default order">Load default order</span>
15981598 </div>
15991599 </div>
16001600 <div id="sampler_order_block_lcpp" data-newbie-hidden data-tg-type="llamacpp" class="range-block flexFlowColumn wide100p">
16011601 <hr class="wide100p">
16021602 <h4 class="range-block-title justifyCenter">
16031603 <span data-i18n="SamplersSampler Order">SamplersSampler Order</span>
16041604 <div class="margin5 fa-solid fa-circle-info opacity50p" data-i18n="[title]llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored." title="llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored."></div>
16051605 </h4>
16061606 <div class="toggle-description widthUnset" data-i18n="llama.cpp only. Determines the order of samplers. If Mirostat mode is not 0, sampler order is ignored.">
@@ -1618,7 +1618,7 @@
16181618 <span data-i18n="Load default order">Load default order</span>
16191619 </div>
16201620 </div>
16211621 <div id="sampler_priority_block_ooba" data-newbie-hidden data-tg-type="ooba" class="range-block flexFlowColumn wide100p">
16221622 <hr class="wide100p">
16231623 <h4 class="range-block-title justifyCenter">
16241624 <span data-i18n="Sampler Priority">Sampler Priority</span>
@@ -1776,7 +1776,7 @@
17761776 <span data-i18n="Send inline images">Send inline images</span>
17771777 <div id="image_inlining_hint" class="flexBasis100p toggle-description justifyLeft">
17781778 <span data-i18n="image_inlining_hint_1">Sends images in prompts if the model supports it (e.g. GPT-4V, Claude 3 or Llava 13B).
17791779 Use the</span> <code><i class="fa-solid fa-paperclip"></i></code> <span data-i18n="image_inlining_hint_2">action on any message or the</span>
17801780 <code><i class="fa-solid fa-wand-magic-sparkles"></i></code> <span data-i18n="image_inlining_hint_3">menu to attach an image file to the chat.</span>
17811781 </div>
17821782 </label>
@@ -6542,4 +6542,4 @@
65426542 </script>
65436543</body>
65446544
65456545</html>
6545 \ No newline at end of file
public/scripts/samplerSelect.js+134 -138
@@ -1,9 +1,7 @@
11import {
22 main_api,
33 saveSettingsDebounced,
4- novelai_setting_names,
54 callPopup,
6- settings,
75} from '../script.js';
86import { power_user } from './power-user.js';
97//import { BIAS_CACHE, displayLogitBias, getLogitBiasListResult } from './logit-bias.js';
@@ -20,132 +18,6 @@ const forcedOffColoring = 'filter: sepia(1) hue-rotate(308deg) contrast(0.7) sat
2018
2119let userDisabledSamplers, userShownSamplers;
2220
23-/*
24-
25-for reference purposes:
26-
27-//NAI
28-const nai_settings = {
29- temperature: 1.5,
30- repetition_penalty: 2.25,
31- repetition_penalty_range: 2048,
32- repetition_penalty_slope: 0.09,
33- repetition_penalty_frequency: 0,
34- repetition_penalty_presence: 0.005,
35- tail_free_sampling: 0.975,
36- top_k: 10,
37- top_p: 0.75,
38- top_a: 0.08,
39- typical_p: 0.975,
40- min_length: 1,
41- model_novel: 'clio-v1',
42- preset_settings_novel: 'Talker-Chat-Clio',
43- streaming_novel: false,
44- preamble: default_preamble,
45- prefix: '',
46- cfg_uc: '',
47- banned_tokens: '',
48- order: default_order,
49- logit_bias: [],
50-};
51-
52-// TG Types
53-export const textgen_types = {
54- OOBA: 'ooba',
55- MANCER: 'mancer',
56- VLLM: 'vllm',
57- APHRODITE: 'aphrodite',
58- TABBY: 'tabby',
59- KOBOLDCPP: 'koboldcpp',
60- TOGETHERAI: 'togetherai',
61- LLAMACPP: 'llamacpp',
62- OLLAMA: 'ollama',
63- INFERMATICAI: 'infermaticai',
64- DREAMGEN: 'dreamgen',
65- OPENROUTER: 'openrouter',
66-};
67-
68-//KAI and TextGen
69-const setting_names = [
70- 'temp',
71- 'temperature_last',
72- 'rep_pen',
73- 'rep_pen_range',
74- 'no_repeat_ngram_size',
75- 'top_k',
76- 'top_p',
77- 'top_a',
78- 'tfs',
79- 'epsilon_cutoff',
80- 'eta_cutoff',
81- 'typical_p',
82- 'min_p',
83- 'penalty_alpha',
84- 'num_beams',
85- 'length_penalty',
86- 'min_length',
87- 'dynatemp',
88- 'min_temp',
89- 'max_temp',
90- 'dynatemp_exponent',
91- 'smoothing_factor',
92- 'smoothing_curve',
93- 'max_tokens_second',
94- 'encoder_rep_pen',
95- 'freq_pen',
96- 'presence_pen',
97- 'do_sample',
98- 'early_stopping',
99- 'seed',
100- 'add_bos_token',
101- 'ban_eos_token',
102- 'skip_special_tokens',
103- 'streaming',
104- 'mirostat_mode',
105- 'mirostat_tau',
106- 'mirostat_eta',
107- 'guidance_scale',
108- 'negative_prompt',
109- 'grammar_string',
110- 'json_schema',
111- 'banned_tokens',
112- 'legacy_api',
113- //'n_aphrodite',
114- //'best_of_aphrodite',
115- 'ignore_eos_token',
116- 'spaces_between_special_tokens',
117- //'logits_processors_aphrodite',
118- //'log_probs_aphrodite',
119- //'prompt_log_probs_aphrodite'
120- 'sampler_order',
121- 'sampler_priority',
122- 'samplers',
123- 'n',
124- 'logit_bias',
125- 'custom_model',
126- 'bypass_status_check',
127-];
128-
129-//OAI settings
130-
131-const default_settings = {
132- preset_settings_openai: 'Default',
133- temp_openai: 1.0,
134- freq_pen_openai: 0,
135- pres_pen_openai: 0,
136- count_pen: 0.0,
137- top_p_openai: 1.0,
138- top_k_openai: 0,
139- min_p_openai: 0,
140- top_a_openai: 1,
141- repetition_penalty_openai: 1,
142- stream_openai: false,
143- //...
144-}
145-
146-
147-*/
148-
14921// Goal 1: show popup with all samplers for active API
15022async function showSamplerSelectPopup() {
15123 const popup = $('#dialogue_popup');
@@ -190,6 +62,15 @@ async function showSamplerSelectPopup() {
19062 power_user.selectSamplers.forceHidden = [];
19163 await validateDisabledSamplers(true);
19264 });
65+
66+ $('#textgen_type').on('change', async function () {
67+ console.log('changed TG Type, resetting custom samplers'); //unfortunate, but necessary unless we save custom samplers for each TGTytpe
68+ userDisabledSamplers = [];
69+ userShownSamplers = [];
70+ power_user.selectSamplers.forceShown = [];
71+ power_user.selectSamplers.forceHidden = [];
72+ await validateDisabledSamplers();
73+ });
19374}
19475
19576function setSamplerListListeners() {
@@ -221,6 +102,11 @@ function setSamplerListListeners() {
221102 targetDisplayType = 'block';
222103 }
223104
105+ if (samplerName === 'dry_multiplier') {
106+ relatedDOMElement = $('#dryBlock');
107+ targetDisplayType = 'block';
108+ }
109+
224110 if (samplerName === 'dynatemp') {
225111 relatedDOMElement = $('#dynatemp_block_ooba');
226112 targetDisplayType = 'block';
@@ -231,9 +117,30 @@ function setSamplerListListeners() {
231117 targetDisplayType = 'block';
232118 }
233119
234120 if (samplerName === 'sampler_order') { //this is for kcpp sampler order
235121 relatedDOMElement = $('#sampler_order_blocksampler_order_block_kcpp');
236- targetDisplayType = 'flex';
122+ }
123+
124+ if (samplerName === 'samplers') { //this is for lcpp sampler order
125+ relatedDOMElement = $('#sampler_order_block_lcpp');
126+ }
127+
128+ if (samplerName === 'sampler_priority') { //this is for ooba's sampler priority
129+ relatedDOMElement = $('#sampler_priority_block_ooba');
130+ }
131+
132+ if (samplerName === 'penalty_alpha') { //contrastive search only has one sampler, does it need its own block?
133+ relatedDOMElement = $('#contrastiveSearchBlock');
134+ }
135+
136+ if (samplerName === 'num_beams') { // num_beams is the killswitch for Beam Search
137+ relatedDOMElement = $('#beamSearchBlock');
138+ targetDisplayType = 'block';
139+ }
140+
141+ if (samplerName === 'smoothing_factor') { // num_beams is the killswitch for Beam Search
142+ relatedDOMElement = $('#smoothingBlock');
143+ targetDisplayType = 'block';
237144 }
238145
239146 // Get the current state of the custom data attribute
@@ -301,7 +208,7 @@ async function listSamplers(main_api, arrayOnly = false) {
301208 let availableSamplers;
302209 if (main_api === 'textgenerationwebui') {
303210 availableSamplers = TGsamplerNames;
304211 const valuesToRemove = new Set(['streaming', 'seed', 'bypass_status_check', 'custom_model', 'legacy_api', 'samplers']);
305212 availableSamplers = availableSamplers.filter(sampler => !valuesToRemove.has(sampler));
306213 availableSamplers.sort();
307214 }
@@ -312,8 +219,70 @@ async function listSamplers(main_api, arrayOnly = false) {
312219 }
313220
314221 const samplersListHTML = availableSamplers.reduce((html, sampler) => {
315222 let customColor, displayname;
316223 constlet targetDOMelement = $(`#${sampler}_${main_api}`);
224+
225+ if (sampler === 'sampler_order') { //this is for kcpp sampler order
226+ targetDOMelement = $('#sampler_order_block_kcpp');
227+ displayname = 'KCPP Sampler Order Block';
228+ }
229+
230+ if (sampler === 'samplers') { //this is for lcpp sampler order
231+ targetDOMelement = $('#sampler_order_block_lcpp');
232+ displayname = 'LCPP Sampler Order Block';
233+ }
234+
235+ if (sampler === 'sampler_priority') { //this is for ooba's sampler priority
236+ targetDOMelement = $('#sampler_priority_block_ooba');
237+ displayname = 'Ooba Sampler Priority Block';
238+ }
239+
240+ if (sampler === 'penalty_alpha') { //contrastive search only has one sampler, does it need its own block?
241+ targetDOMelement = $('#contrastiveSearchBlock');
242+ displayname = 'Contrast Search Block';
243+ }
244+
245+ if (sampler === 'num_beams') { // num_beams is the killswitch for Beam Search
246+ targetDOMelement = $('#beamSearchBlock');
247+ displayname = 'Beam Search Block';
248+ }
249+
250+ if (sampler === 'smoothing_factor') { // num_beams is the killswitch for Beam Search
251+ targetDOMelement = $('#smoothingBlock');
252+ displayname = 'Smoothing Block';
253+ }
254+
255+ if (sampler === 'dry_multiplier') {
256+ targetDOMelement = $('#dryBlock');
257+ displayname = 'DRY Rep Pen Block';
258+ }
259+
260+ if (sampler === 'dynatemp') {
261+ targetDOMelement = $('#dynatemp_block_ooba');
262+ displayname = 'DynaTemp Block';
263+ }
264+
265+ if (sampler === 'json_schema') {
266+ targetDOMelement = $('#json_schema_block');
267+ displayname = 'JSON Schema Block';
268+ }
269+
270+ if (sampler === 'grammar_string') {
271+ targetDOMelement = $('#grammar_block_ooba');
272+ displayname = 'Grammar Block';
273+ }
274+
275+ if (sampler === 'guidance_scale') {
276+ targetDOMelement = $('#cfg_block_ooba');
277+ displayname = 'CFG Block';
278+ }
279+
280+ if (sampler === 'mirostat_mode') {
281+ targetDOMelement = $('#mirostat_block_ooba');
282+ displayname = 'Mirostat Block';
283+ }
284+
285+
317286
318287 const isInForceHiddenArray = userDisabledSamplers.includes(sampler);
319288 const isInForceShownArray = userShownSamplers.includes(sampler);
@@ -335,11 +304,12 @@ async function listSamplers(main_api, arrayOnly = false) {
335304 }
336305 else { return isVisibleInDOM; }
337306 };
338307 console.log(sampler, targetDOMelement.prop('id'), isInDefaultState(), isInForceShownArray, isInForceHiddenArray, shouldBeChecked());
308+ if (displayname === undefined) { displayname = sampler; }
339309 return html + `
340310 <div class="sampler_view_list_item wide50p flex-container">
341311 <input type="checkbox" name="${sampler}_checkbox" ${shouldBeChecked() ? 'checked' : ''}>
342312 <small class="sampler_name" style="${customColor}">${samplerdisplayname}</small>
343313 </div>
344314 `;
345315 }, '');
@@ -391,8 +361,33 @@ export async function validateDisabledSamplers(redraw = false) {
391361 targetDisplayType = 'block';
392362 }
393363
394364 if (sampler === 'sampler_order') { //this is for kcpp sampler order
395365 relatedDOMElement = $('#sampler_order_blocksampler_order_block_kcpp');
366+ }
367+
368+ if (sampler === 'samplers') { //this is for lcpp sampler order
369+ relatedDOMElement = $('#sampler_order_block_lcpp');
370+ }
371+
372+ if (sampler === 'sampler_priority') { //this is for ooba's sampler priority
373+ relatedDOMElement = $('#sampler_priority_block_ooba');
374+ }
375+
376+ if (sampler === 'dry_multiplier') {
377+ relatedDOMElement = $('#dryBlock');
378+ targetDisplayType = 'block';
379+ }
380+
381+ if (sampler === 'penalty_alpha') { //contrastive search only has one sampler, does it need its own block?
382+ relatedDOMElement = $('#contrastiveSearchBlock');
383+ }
384+
385+ if (sampler === 'num_beams') { // num_beams is the killswitch for Beam Search
386+ relatedDOMElement = $('#beamSearchBlock');
387+ }
388+
389+ if (sampler === 'smoothing_factor') { // num_beams is the killswitch for Beam Search
390+ relatedDOMElement = $('#smoothingBlock');
396391 }
397392
398393 if (power_user?.selectSamplers?.forceHidden.includes(sampler)) {
@@ -418,6 +413,7 @@ export async function validateDisabledSamplers(redraw = false) {
418413 setSamplerListListeners();
419414 }
420415
416+ await saveSettingsDebounced();
421417
422418 }
423419}