embetterify Sampler Select function
| @@ -1273,7 +1273,7 @@ | ||
| 1273 | 1273 | <input class="neo-range-slider" type="range" id="max_tokens_second_textgenerationwebui" name="volume" min="0" max="20" step="1" /> |
| 1274 | 1274 | <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"> |
| 1275 | 1275 | </div> |
| 1276 | 1276 | <div data-newbie-hidden data-tg-type="mancer, ooba, koboldcpp, aphrodite, tabby" id="smoothingBlock" name="smoothingBlock" class="wide100p"> |
| 1277 | 1277 | <h4 class="wide100p textAlignCenter"> |
| 1278 | 1278 | <label data-i18n="Smooth Sampling">Smooth Sampling</label> |
| 1279 | 1279 | <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 @@ | ||
| 1387 | 1387 | </div> |
| 1388 | 1388 | </div> |
| 1389 | 1389 | </div> |
| 1390 | 1390 | <div data-newbie-hidden data-tg-type="ooba, vllm" id="beamSearchBlock" name="beamSearchBlock" class="wide100p"> |
| 1391 | 1391 | <h4 class="wide100p textAlignCenter"> |
| 1392 | 1392 | <label> |
| 1393 | 1393 | <span data-i18n="Beam search">Beam Search</span> |
| @@ -1413,7 +1413,7 @@ | ||
| 1413 | 1413 | </div> |
| 1414 | 1414 | </div> |
| 1415 | 1415 | </div> |
| 1416 | 1416 | <div data-tg-type="ooba" data-newbie-hidden id="contrastiveSearchBlock" name="contrastiveSearchBlock" class="alignitemscenter flex-container flexFlowColumn flexBasis48p flexGrow flexShrink gap0"> |
| 1417 | 1417 | <h4 class="textAlignCenter" data-i18n="Contrastive search">Contrastive Search |
| 1418 | 1418 | <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> |
| 1419 | 1419 | </h4> |
| @@ -1554,13 +1554,13 @@ | ||
| 1554 | 1554 | </h4> |
| 1555 | 1555 | <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> |
| 1556 | 1556 | </div> |
| 1557 | 1557 | <div id="sampler_order_blocksampler_order_block_kcpp" data-newbie-hidden data-tg-type="koboldcpp" class="range-block flexFlowColumn wide100p"> |
| 1558 | 1558 | <hr class="wide100p"> |
| 1559 | 1559 | <div class="range-block-title"> |
| 1560 | 1560 | <span data-i18n="Samplers Order">Samplers Order</span> |
| 1561 | 1561 | </div> |
| 1562 | 1562 | <div class="toggle-description widthUnset" data-i18n="Samplers will be applied in a top-down order. Use with caution."> |
| 1563 | 1563 | kcpp only. Samplers will be applied in a top-down order. |
| 1564 | 1564 | Use with caution. |
| 1565 | 1565 | </div> |
| 1566 | 1566 | <div id="koboldcpp_order" class="prompt_order"> |
| @@ -1597,10 +1597,10 @@ | ||
| 1597 | 1597 | <span data-i18n="Load default order">Load default order</span> |
| 1598 | 1598 | </div> |
| 1599 | 1599 | </div> |
| 1600 | 1600 | <div id="sampler_order_block_lcpp" data-newbie-hidden data-tg-type="llamacpp" class="range-block flexFlowColumn wide100p"> |
| 1601 | 1601 | <hr class="wide100p"> |
| 1602 | 1602 | <h4 class="range-block-title justifyCenter"> |
| 1603 | 1603 | <span data-i18n="SamplersSampler Order">SamplersSampler Order</span> |
| 1604 | 1604 | <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> |
| 1605 | 1605 | </h4> |
| 1606 | 1606 | <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 @@ | ||
| 1618 | 1618 | <span data-i18n="Load default order">Load default order</span> |
| 1619 | 1619 | </div> |
| 1620 | 1620 | </div> |
| 1621 | 1621 | <div id="sampler_priority_block_ooba" data-newbie-hidden data-tg-type="ooba" class="range-block flexFlowColumn wide100p"> |
| 1622 | 1622 | <hr class="wide100p"> |
| 1623 | 1623 | <h4 class="range-block-title justifyCenter"> |
| 1624 | 1624 | <span data-i18n="Sampler Priority">Sampler Priority</span> |
| @@ -1776,7 +1776,7 @@ | ||
| 1776 | 1776 | <span data-i18n="Send inline images">Send inline images</span> |
| 1777 | 1777 | <div id="image_inlining_hint" class="flexBasis100p toggle-description justifyLeft"> |
| 1778 | 1778 | <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). |
| 1779 | 1779 | 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> |
| 1780 | 1780 | <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> |
| 1781 | 1781 | </div> |
| 1782 | 1782 | </label> |
| @@ -6542,4 +6542,4 @@ | ||
| 6542 | 6542 | </script> |
| 6543 | 6543 | </body> |
| 6544 | 6544 | |
| 6545 | 6545 | </html> |
| 6545 | \ No newline at end of file | |
| @@ -1,9 +1,7 @@ | ||
| 1 | 1 | import { |
| 2 | 2 | main_api, |
| 3 | 3 | saveSettingsDebounced, |
| 4 | - novelai_setting_names, | |
| 5 | 4 | callPopup, |
| 6 | - settings, | |
| 7 | 5 | } from '../script.js'; |
| 8 | 6 | import { power_user } from './power-user.js'; |
| 9 | 7 | //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 | ||
| 20 | 18 | |
| 21 | 19 | let userDisabledSamplers, userShownSamplers; |
| 22 | 20 | |
| 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 | - | |
| 149 | 21 | // Goal 1: show popup with all samplers for active API |
| 150 | 22 | async function showSamplerSelectPopup() { |
| 151 | 23 | const popup = $('#dialogue_popup'); |
| @@ -190,6 +62,15 @@ async function showSamplerSelectPopup() { | ||
| 190 | 62 | power_user.selectSamplers.forceHidden = []; |
| 191 | 63 | await validateDisabledSamplers(true); |
| 192 | 64 | }); |
| 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 | + }); | |
| 193 | 74 | } |
| 194 | 75 | |
| 195 | 76 | function setSamplerListListeners() { |
| @@ -221,6 +102,11 @@ function setSamplerListListeners() { | ||
| 221 | 102 | targetDisplayType = 'block'; |
| 222 | 103 | } |
| 223 | 104 | |
| 105 | + if (samplerName === 'dry_multiplier') { | |
| 106 | + relatedDOMElement = $('#dryBlock'); | |
| 107 | + targetDisplayType = 'block'; | |
| 108 | + } | |
| 109 | + | |
| 224 | 110 | if (samplerName === 'dynatemp') { |
| 225 | 111 | relatedDOMElement = $('#dynatemp_block_ooba'); |
| 226 | 112 | targetDisplayType = 'block'; |
| @@ -231,9 +117,30 @@ function setSamplerListListeners() { | ||
| 231 | 117 | targetDisplayType = 'block'; |
| 232 | 118 | } |
| 233 | 119 | |
| 234 | 120 | if (samplerName === 'sampler_order') { //this is for kcpp sampler order |
| 235 | 121 | 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'; | |
| 237 | 144 | } |
| 238 | 145 | |
| 239 | 146 | // Get the current state of the custom data attribute |
| @@ -301,7 +208,7 @@ async function listSamplers(main_api, arrayOnly = false) { | ||
| 301 | 208 | let availableSamplers; |
| 302 | 209 | if (main_api === 'textgenerationwebui') { |
| 303 | 210 | availableSamplers = TGsamplerNames; |
| 304 | 211 | const valuesToRemove = new Set(['streaming', 'seed', 'bypass_status_check', 'custom_model', 'legacy_api', 'samplers']); |
| 305 | 212 | availableSamplers = availableSamplers.filter(sampler => !valuesToRemove.has(sampler)); |
| 306 | 213 | availableSamplers.sort(); |
| 307 | 214 | } |
| @@ -312,8 +219,70 @@ async function listSamplers(main_api, arrayOnly = false) { | ||
| 312 | 219 | } |
| 313 | 220 | |
| 314 | 221 | const samplersListHTML = availableSamplers.reduce((html, sampler) => { |
| 315 | 222 | let customColor, displayname; |
| 316 | 223 | 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 | + | |
| 317 | 286 | |
| 318 | 287 | const isInForceHiddenArray = userDisabledSamplers.includes(sampler); |
| 319 | 288 | const isInForceShownArray = userShownSamplers.includes(sampler); |
| @@ -335,11 +304,12 @@ async function listSamplers(main_api, arrayOnly = false) { | ||
| 335 | 304 | } |
| 336 | 305 | else { return isVisibleInDOM; } |
| 337 | 306 | }; |
| 338 | 307 | console.log(sampler, targetDOMelement.prop('id'), isInDefaultState(), isInForceShownArray, isInForceHiddenArray, shouldBeChecked()); |
| 308 | + if (displayname === undefined) { displayname = sampler; } | |
| 339 | 309 | return html + ` |
| 340 | 310 | <div class="sampler_view_list_item wide50p flex-container"> |
| 341 | 311 | <input type="checkbox" name="${sampler}_checkbox" ${shouldBeChecked() ? 'checked' : ''}> |
| 342 | 312 | <small class="sampler_name" style="${customColor}">${samplerdisplayname}</small> |
| 343 | 313 | </div> |
| 344 | 314 | `; |
| 345 | 315 | }, ''); |
| @@ -391,8 +361,33 @@ export async function validateDisabledSamplers(redraw = false) { | ||
| 391 | 361 | targetDisplayType = 'block'; |
| 392 | 362 | } |
| 393 | 363 | |
| 394 | 364 | if (sampler === 'sampler_order') { //this is for kcpp sampler order |
| 395 | 365 | 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'); | |
| 396 | 391 | } |
| 397 | 392 | |
| 398 | 393 | if (power_user?.selectSamplers?.forceHidden.includes(sampler)) { |
| @@ -418,6 +413,7 @@ export async function validateDisabledSamplers(redraw = false) { | ||
| 418 | 413 | setSamplerListListeners(); |
| 419 | 414 | } |
| 420 | 415 | |
| 416 | + await saveSettingsDebounced(); | |
| 421 | 417 | |
| 422 | 418 | } |
| 423 | 419 | } |