mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
UI: add UI to enable/disable auto-derived templates
This commit is contained in:
@ -3295,6 +3295,12 @@
|
|||||||
<span class="fa-solid fa-circle-question note-link-span"></span>
|
<span class="fa-solid fa-circle-question note-link-span"></span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex-container">
|
||||||
|
<label for="context_derived" class="checkbox_label flex1" title="Derive from Model Metadata, if possible." data-i18n="[title]context_derived">
|
||||||
|
<input id="context_derived" type="checkbox" style="display:none;" />
|
||||||
|
<small><i class="fa-solid fa-tree menu_button margin0"></i></small>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</h4>
|
</h4>
|
||||||
<div class="flex-container" title="Select your current Context Template" data-i18n="[title]Select your current Context Template">
|
<div class="flex-container" title="Select your current Context Template" data-i18n="[title]Select your current Context Template">
|
||||||
<select id="context_presets" data-preset-manager-for="context" class="flex1 text_pole"></select>
|
<select id="context_presets" data-preset-manager-for="context" class="flex1 text_pole"></select>
|
||||||
@ -3395,6 +3401,10 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
|
<label for="instruct_derived" class="checkbox_label flex1" title="Derive from Model Metadata, if possible." data-i18n="[title]instruct_derived">
|
||||||
|
<input id="instruct_derived" type="checkbox" style="display:none;" />
|
||||||
|
<small><i class="fa-solid fa-tree menu_button margin0"></i></small>
|
||||||
|
</label>
|
||||||
<label for="instruct_bind_to_context" class="checkbox_label flex1" title="Bind to Context
If enabled, Context templates will be automatically selected based on selected Instruct template name or by preference." data-i18n="[title]instruct_bind_to_context">
|
<label for="instruct_bind_to_context" class="checkbox_label flex1" title="Bind to Context
If enabled, Context templates will be automatically selected based on selected Instruct template name or by preference." data-i18n="[title]instruct_bind_to_context">
|
||||||
<input id="instruct_bind_to_context" type="checkbox" style="display:none;" />
|
<input id="instruct_bind_to_context" type="checkbox" style="display:none;" />
|
||||||
<small><i class="fa-solid fa-link menu_button margin0"></i></small>
|
<small><i class="fa-solid fa-link menu_button margin0"></i></small>
|
||||||
|
@ -1236,9 +1236,10 @@ async function getStatusTextgen() {
|
|||||||
const supportsTokenization = response.headers.get('x-supports-tokenization') === 'true';
|
const supportsTokenization = response.headers.get('x-supports-tokenization') === 'true';
|
||||||
supportsTokenization ? sessionStorage.setItem(TOKENIZER_SUPPORTED_KEY, 'true') : sessionStorage.removeItem(TOKENIZER_SUPPORTED_KEY);
|
supportsTokenization ? sessionStorage.setItem(TOKENIZER_SUPPORTED_KEY, 'true') : sessionStorage.removeItem(TOKENIZER_SUPPORTED_KEY);
|
||||||
|
|
||||||
|
const wantsInstructDerivation = (power_user.instruct.enabled && power_user.instruct.derived);
|
||||||
|
const wantsContextDerivation = power_user.context_derived;
|
||||||
const supportsChatTemplate = response.headers.get('x-supports-chat-template') === 'true';
|
const supportsChatTemplate = response.headers.get('x-supports-chat-template') === 'true';
|
||||||
|
if (supportsChatTemplate && (wantsInstructDerivation || wantsContextDerivation)) {
|
||||||
if (supportsChatTemplate) {
|
|
||||||
const response = await fetch('/api/backends/text-completions/chat_template', {
|
const response = await fetch('/api/backends/text-completions/chat_template', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
@ -1251,15 +1252,19 @@ async function getStatusTextgen() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data) {
|
if (data) {
|
||||||
const { chat_template, chat_template_hash } = data;
|
const { chat_template, chat_template_hash } = data;
|
||||||
console.log(`We have chat template ${chat_template.split('\n')[0]}...`);
|
console.log(`${wantsContextDerivation} ${wantsInstructDerivation} We have chat template ${chat_template.split('\n')[0]}...`);
|
||||||
const templates = await deriveTemplatesFromChatTemplate(chat_template, chat_template_hash);
|
const templates = await deriveTemplatesFromChatTemplate(chat_template, chat_template_hash);
|
||||||
if (templates) {
|
if (templates) {
|
||||||
const { context, instruct } = templates;
|
const { context, instruct } = templates;
|
||||||
|
if (wantsContextDerivation) {
|
||||||
selectContextPreset(context, { isAuto: true });
|
selectContextPreset(context, { isAuto: true });
|
||||||
|
}
|
||||||
|
if (wantsInstructDerivation) {
|
||||||
selectInstructPreset(instruct, { isAuto: true });
|
selectInstructPreset(instruct, { isAuto: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress.
|
// We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress.
|
||||||
if (online_status === 'no_connection' && data.response) {
|
if (online_status === 'no_connection' && data.response) {
|
||||||
|
@ -39,6 +39,7 @@ const controls = [
|
|||||||
{ id: 'instruct_first_input_sequence', property: 'first_input_sequence', isCheckbox: false },
|
{ id: 'instruct_first_input_sequence', property: 'first_input_sequence', isCheckbox: false },
|
||||||
{ id: 'instruct_last_input_sequence', property: 'last_input_sequence', isCheckbox: false },
|
{ id: 'instruct_last_input_sequence', property: 'last_input_sequence', isCheckbox: false },
|
||||||
{ id: 'instruct_activation_regex', property: 'activation_regex', isCheckbox: false },
|
{ id: 'instruct_activation_regex', property: 'activation_regex', isCheckbox: false },
|
||||||
|
{ id: 'instruct_derived', property: 'derived', isCheckbox: true },
|
||||||
{ id: 'instruct_bind_to_context', property: 'bind_to_context', isCheckbox: true },
|
{ id: 'instruct_bind_to_context', property: 'bind_to_context', isCheckbox: true },
|
||||||
{ id: 'instruct_skip_examples', property: 'skip_examples', isCheckbox: true },
|
{ id: 'instruct_skip_examples', property: 'skip_examples', isCheckbox: true },
|
||||||
{ id: 'instruct_names_behavior', property: 'names_behavior', isCheckbox: false },
|
{ id: 'instruct_names_behavior', property: 'names_behavior', isCheckbox: false },
|
||||||
@ -100,6 +101,7 @@ export async function loadInstructMode(data) {
|
|||||||
|
|
||||||
$('#instruct_enabled').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.enabled);
|
$('#instruct_enabled').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.enabled);
|
||||||
$('#instructSettingsBlock, #InstructSequencesColumn').toggleClass('disabled', !power_user.instruct.enabled);
|
$('#instructSettingsBlock, #InstructSequencesColumn').toggleClass('disabled', !power_user.instruct.enabled);
|
||||||
|
$('#instruct_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.derived);
|
||||||
$('#instruct_bind_to_context').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.bind_to_context);
|
$('#instruct_bind_to_context').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.bind_to_context);
|
||||||
|
|
||||||
controls.forEach(control => {
|
controls.forEach(control => {
|
||||||
@ -715,6 +717,10 @@ jQuery(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#instruct_derived').on('change', function () {
|
||||||
|
$('#instruct_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.derived);
|
||||||
|
});
|
||||||
|
|
||||||
$('#instruct_bind_to_context').on('change', function () {
|
$('#instruct_bind_to_context').on('change', function () {
|
||||||
$('#instruct_bind_to_context').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.bind_to_context);
|
$('#instruct_bind_to_context').parent().find('i').toggleClass('toggleEnabled', !!power_user.instruct.bind_to_context);
|
||||||
});
|
});
|
||||||
|
@ -226,6 +226,7 @@ let power_user = {
|
|||||||
macro: true,
|
macro: true,
|
||||||
names_behavior: names_behavior_types.FORCE,
|
names_behavior: names_behavior_types.FORCE,
|
||||||
activation_regex: '',
|
activation_regex: '',
|
||||||
|
derived: false,
|
||||||
bind_to_context: false,
|
bind_to_context: false,
|
||||||
user_alignment_message: '',
|
user_alignment_message: '',
|
||||||
system_same_as_user: false,
|
system_same_as_user: false,
|
||||||
@ -243,6 +244,8 @@ let power_user = {
|
|||||||
names_as_stop_strings: true,
|
names_as_stop_strings: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
context_derived: false,
|
||||||
|
|
||||||
sysprompt: {
|
sysprompt: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
name: 'Neutral - Chat',
|
name: 'Neutral - Chat',
|
||||||
@ -1472,6 +1475,7 @@ async function loadPowerUserSettings(settings, data) {
|
|||||||
$('#encode_tags').prop('checked', power_user.encode_tags);
|
$('#encode_tags').prop('checked', power_user.encode_tags);
|
||||||
$('#example_messages_behavior').val(getExampleMessagesBehavior());
|
$('#example_messages_behavior').val(getExampleMessagesBehavior());
|
||||||
$(`#example_messages_behavior option[value="${getExampleMessagesBehavior()}"]`).prop('selected', true);
|
$(`#example_messages_behavior option[value="${getExampleMessagesBehavior()}"]`).prop('selected', true);
|
||||||
|
$('#context_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_derived);
|
||||||
|
|
||||||
$('#console_log_prompts').prop('checked', power_user.console_log_prompts);
|
$('#console_log_prompts').prop('checked', power_user.console_log_prompts);
|
||||||
$('#request_token_probabilities').prop('checked', power_user.request_token_probabilities);
|
$('#request_token_probabilities').prop('checked', power_user.request_token_probabilities);
|
||||||
@ -3057,6 +3061,16 @@ $(document).ready(() => {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#context_derived').on('input', function () {
|
||||||
|
const value = !!$(this).prop('checked');
|
||||||
|
power_user.context_derived = value;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#context_derived').on('change', function () {
|
||||||
|
$('#context_derived').parent().find('i').toggleClass('toggleEnabled', !!power_user.context_derived);
|
||||||
|
});
|
||||||
|
|
||||||
$('#always-force-name2-checkbox').change(function () {
|
$('#always-force-name2-checkbox').change(function () {
|
||||||
power_user.always_force_name2 = !!$(this).prop('checked');
|
power_user.always_force_name2 = !!$(this).prop('checked');
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
Reference in New Issue
Block a user