Merge pull request #2742 from SillyTavern/xtc-ooba Enable XTC for TextGen WebUI

c47e19866420b9d67239312d47beea072850800c

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
2 files changed, +35 -1Ignore whitespace
public/index.html+8 -1
@@ -1310,7 +1310,7 @@
13101310 </div>
13111311 </div>
13121312
13131313 <div data-tg-type="koboldcpp, aphrodite, tabby, ooba" id="xtc_block" class="wide100p">
13141314 <h4 class="wide100p textAlignCenter">
13151315 <label data-i18n="Exclude Top Choices (XTC)">Exclude Top Choices (XTC)</label>
13161316 <a href="https://github.com/oobabooga/text-generation-webui/pull/6335" target="_blank">
@@ -1679,6 +1679,10 @@
16791679 Ooba only. Determines the order of samplers.
16801680 </div>
16811681 <div id="sampler_priority_container" class="prompt_order">
1682+ <div data-name="repetition_penalty" draggable="true"><span>Repetition Penalty</span><small></small></div>
1683+ <div data-name="presence_penalty" draggable="true"><span>Presence Penalty</span><small></small></div>
1684+ <div data-name="frequency_penalty" draggable="true"><span>Frequency Penalty</span><small></small></div>
1685+ <div data-name="dry" draggable="true"><span>DRY</span><small></small></div>
16821686 <div data-name="temperature" draggable="true"><span>Temperature</span><small></small></div>
16831687 <div data-name="dynamic_temperature" draggable="true"><span>Dynamic Temperature</span><small></small></div>
16841688 <div data-name="quadratic_sampling" draggable="true"><span>Quadratic / Smooth Sampling</span><small></small></div>
@@ -1691,6 +1695,9 @@
16911695 <div data-name="top_a" draggable="true"><span>Top A</span><small></small></div>
16921696 <div data-name="min_p" draggable="true"><span>Min P</span><small></small></div>
16931697 <div data-name="mirostat" draggable="true"><span>Mirostat</span><small></small></div>
1698+ <div data-name="xtc" draggable="true"><span>XTC</span><small></small></div>
1699+ <div data-name="encoder_repetition_penalty" draggable="true"><span>Encoder Repetition Penalty</span><small></small></div>
1700+ <div data-name="no_repeat_ngram" draggable="true"><span>No Repeat Ngram</span><small></small></div>
16941701 </div>
16951702 <div id="textgenerationwebui_default_order" class="menu_button menu_button_icon">
16961703 <span data-i18n="Load default order">Load default order</span>
public/scripts/textgen-settings.js+27 -0
@@ -68,6 +68,10 @@ const LLAMACPP_DEFAULT_ORDER = [
6868 'temperature',
6969];
7070const OOBA_DEFAULT_ORDER = [
71+ 'repetition_penalty',
72+ 'presence_penalty',
73+ 'frequency_penalty',
74+ 'dry',
7175 'temperature',
7276 'dynamic_temperature',
7377 'quadratic_sampling',
@@ -80,6 +84,9 @@ const OOBA_DEFAULT_ORDER = [
8084 'top_a',
8185 'min_p',
8286 'mirostat',
87+ 'xtc',
88+ 'encoder_repetition_penalty',
89+ 'no_repeat_ngram',
8390];
8491const BIAS_KEY = '#textgenerationwebui_api-settings';
8592
@@ -798,6 +805,25 @@ function showTypeSpecificControls(type) {
798805 });
799806}
800807
808+/**
809+ * Inserts missing items from the source array into the target array.
810+ * @param {any[]} source - Source array
811+ * @param {any[]} target - Target array
812+ * @returns {void}
813+ */
814+function insertMissingArrayItems(source, target) {
815+ if (source === target || !Array.isArray(source) || !Array.isArray(target)) {
816+ return;
817+ }
818+
819+ for (const item of source) {
820+ if (!target.includes(item)) {
821+ const index = source.indexOf(item);
822+ target.splice(index, 0, item);
823+ }
824+ }
825+}
826+
801827function setSettingByName(setting, value, trigger) {
802828 if (value === null || value === undefined) {
803829 return;
@@ -812,6 +838,7 @@ function setSettingByName(setting, value, trigger) {
812838
813839 if ('sampler_priority' === setting) {
814840 value = Array.isArray(value) ? value : OOBA_DEFAULT_ORDER;
841+ insertMissingArrayItems(OOBA_DEFAULT_ORDER, value);
815842 sortOobaItemsByOrder(value);
816843 settings.sampler_priority = value;
817844 return;