UI: add UI to enable/disable auto-derived templates

50ffaeb06a3a996b97973e0fac46c250901d61d9

Karl-Johan Alm <karljohan-alm@garage.co.jp>

Signed
4 files changed, +40 -5Ignore whitespace
public/index.html+10 -0
@@ -3295,6 +3295,12 @@
32953295 <span class="fa-solid fa-circle-question note-link-span"></span>
32963296 </a>
32973297 </div>
3298+ <div class="flex-container">
3299+ <label for="context_derived" class="checkbox_label flex1" title="Derive from Model Metadata, if possible." data-i18n="[title]context_derived">
3300+ <input id="context_derived" type="checkbox" style="display:none;" />
3301+ <small><i class="fa-solid fa-tree menu_button margin0"></i></small>
3302+ </label>
3303+ </div>
32983304 </h4>
32993305 <div class="flex-container" title="Select your current Context Template" data-i18n="[title]Select your current Context Template">
33003306 <select id="context_presets" data-preset-manager-for="context" class="flex1 text_pole"></select>
@@ -3395,6 +3401,10 @@
33953401 </a>
33963402 </div>
33973403 <div class="flex-container">
3404+ <label for="instruct_derived" class="checkbox_label flex1" title="Derive from Model Metadata, if possible." data-i18n="[title]instruct_derived">
3405+ <input id="instruct_derived" type="checkbox" style="display:none;" />
3406+ <small><i class="fa-solid fa-tree menu_button margin0"></i></small>
3407+ </label>
33983408 <label for="instruct_bind_to_context" class="checkbox_label flex1" title="Bind to Context&#10If enabled, Context templates will be automatically selected based on selected Instruct template name or by preference." data-i18n="[title]instruct_bind_to_context">
33993409 <input id="instruct_bind_to_context" type="checkbox" style="display:none;" />
34003410 <small><i class="fa-solid fa-link menu_button margin0"></i></small>
public/script.js+10 -5
@@ -1236,9 +1236,10 @@ async function getStatusTextgen() {
12361236 const supportsTokenization = response.headers.get('x-supports-tokenization') === 'true';
12371237 supportsTokenization ? sessionStorage.setItem(TOKENIZER_SUPPORTED_KEY, 'true') : sessionStorage.removeItem(TOKENIZER_SUPPORTED_KEY);
12381238
1239+ const wantsInstructDerivation = (power_user.instruct.enabled && power_user.instruct.derived);
1240+ const wantsContextDerivation = power_user.context_derived;
12391241 const supportsChatTemplate = response.headers.get('x-supports-chat-template') === 'true';
1240-
1242+ if (supportsChatTemplate && (wantsInstructDerivation || wantsContextDerivation)) {
1241- if (supportsChatTemplate) {
12421243 const response = await fetch('/api/backends/text-completions/chat_template', {
12431244 method: 'POST',
12441245 headers: getRequestHeaders(),
@@ -1251,12 +1252,16 @@ async function getStatusTextgen() {
12511252 const data = await response.json();
12521253 if (data) {
12531254 const { chat_template, chat_template_hash } = data;
12541255 console.log(`${wantsContextDerivation} ${wantsInstructDerivation} We have chat template ${chat_template.split('\n')[0]}...`);
12551256 const templates = await deriveTemplatesFromChatTemplate(chat_template, chat_template_hash);
12561257 if (templates) {
12571258 const { context, instruct } = templates;
1258- selectContextPreset(context, { isAuto: true });
1259+ if (wantsContextDerivation) {
12591260 selectInstructPreset selectContextPreset(instructcontext, { isAuto: true });
1261+ }
1262+ if (wantsInstructDerivation) {
1263+ selectInstructPreset(instruct, { isAuto: true });
1264+ }
12601265 }
12611266 }
12621267 }
public/scripts/instruct-mode.js+6 -0
@@ -39,6 +39,7 @@ const controls = [
3939 { id: 'instruct_first_input_sequence', property: 'first_input_sequence', isCheckbox: false },
4040 { id: 'instruct_last_input_sequence', property: 'last_input_sequence', isCheckbox: false },
4141 { id: 'instruct_activation_regex', property: 'activation_regex', isCheckbox: false },
42+ { id: 'instruct_derived', property: 'derived', isCheckbox: true },
4243 { id: 'instruct_bind_to_context', property: 'bind_to_context', isCheckbox: true },
4344 { id: 'instruct_skip_examples', property: 'skip_examples', isCheckbox: true },
4445 { id: 'instruct_names_behavior', property: 'names_behavior', isCheckbox: false },
@@ -100,6 +101,7 @@ export async function loadInstructMode(data) {
100101
101102 $('#instruct_enabled').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.enabled);
102103 $('#instructSettingsBlock, #InstructSequencesColumn').toggleClass('disabled', !power_user.instruct.enabled);
104+ $('#instruct_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.derived);
103105 $('#instruct_bind_to_context').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.bind_to_context);
104106
105107 controls.forEach(control => {
@@ -715,6 +717,10 @@ jQuery(() => {
715717 }
716718 });
717719
720+ $('#instruct_derived').on('change', function () {
721+ $('#instruct_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.derived);
722+ });
723+
718724 $('#instruct_bind_to_context').on('change', function () {
719725 $('#instruct_bind_to_context').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.bind_to_context);
720726 });
public/scripts/power-user.js+14 -0
@@ -226,6 +226,7 @@ let power_user = {
226226 macro: true,
227227 names_behavior: names_behavior_types.FORCE,
228228 activation_regex: '',
229+ derived: false,
229230 bind_to_context: false,
230231 user_alignment_message: '',
231232 system_same_as_user: false,
@@ -243,6 +244,8 @@ let power_user = {
243244 names_as_stop_strings: true,
244245 },
245246
247+ context_derived: false,
248+
246249 sysprompt: {
247250 enabled: true,
248251 name: 'Neutral - Chat',
@@ -1472,6 +1475,7 @@ async function loadPowerUserSettings(settings, data) {
14721475 $('#encode_tags').prop('checked', power_user.encode_tags);
14731476 $('#example_messages_behavior').val(getExampleMessagesBehavior());
14741477 $(`#example_messages_behavior option[value="${getExampleMessagesBehavior()}"]`).prop('selected', true);
1478+ $('#context_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_derived);
14751479
14761480 $('#console_log_prompts').prop('checked', power_user.console_log_prompts);
14771481 $('#request_token_probabilities').prop('checked', power_user.request_token_probabilities);
@@ -3057,6 +3061,16 @@ $(document).ready(() => {
30573061 saveSettingsDebounced();
30583062 });
30593063
3064+ $('#context_derived').on('input', function () {
3065+ const value = !!$(this).prop('checked');
3066+ power_user.context_derived = value;
3067+ saveSettingsDebounced();
3068+ });
3069+
3070+ $('#context_derived').on('change', function () {
3071+ $('#context_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_derived);
3072+ });
3073+
30603074 $('#always-force-name2-checkbox').change(function () {
30613075 power_user.always_force_name2 = !!$(this).prop('checked');
30623076 saveSettingsDebounced();