context template preset manager

This commit is contained in:
Stefan Daniel Schwarz 2023-08-26 12:09:47 +02:00
parent bca44ba682
commit 1d7165c047
6 changed files with 54 additions and 12 deletions

View File

@ -151,6 +151,7 @@
"names_force_groups": true,
"activation_regex": ""
},
"default_context": "Default",
"context": {
"preset": "Default",
"story_string": "{{#if system}}{{system}}\n{{/if}}{{#if wiBefore}}{{wiBefore}}\n{{/if}}{{#if description}}{{description}}\n{{/if}}{{#if personality}}{{char}}'s personality: {{personality}}\n{{/if}}{{#if scenario}}Scenario: {{scenario}}\n{{/if}}{{#if wiAfter}}{{wiAfter}}\n{{/if}}{{#if persona}}{{persona}}\n{{/if}}",

View File

@ -2090,9 +2090,15 @@
<h4 data-i18n="Context Template">
Context Template
</h4>
<div class="flex-container flexGap5">
<select id="context_presets" class="flex1 margin0">
</select>
<div class="preset_buttons">
<select id="context_presets" data-preset-manager-for="context" class="flex1"></select>
<input type="file" hidden data-preset-manager-file="context" accept=".json, .settings">
<i id="context_set_default" class="menu_button fa-solid fa-heart" title="Auto-select this preset on API connection."></i>
<i data-preset-manager-update="context" class="menu_button fa-solid fa-save" title="Update current preset" data-i18n="[title]Update current preset"></i>
<i data-preset-manager-new="context" class="menu_button fa-solid fa-plus" title="Create new preset" data-i18n="[title]Create new preset"></i>
<i data-preset-manager-import="context" class="menu_button fa-solid fa-file-import" title="Import preset" data-i18n="[title]Import preset"></i>
<i data-preset-manager-export="context" class="menu_button fa-solid fa-file-export" title="Export preset" data-i18n="[title]Export preset"></i>
<i data-preset-manager-delete="context" class="menu_button fa-solid fa-trash-can" title="Delete the preset" data-i18n="[title]Delete the preset"></i>
</div>
<div>
<label for="context_story_string">

View File

@ -90,7 +90,7 @@ function selectContextPreset(preset) {
}
// If instruct mode is disabled, enable it, except for default context template
if (!power_user.instruct.enabled && preset !== 'Default') {
if (!power_user.instruct.enabled && preset !== power_user.default_context) {
power_user.instruct.enabled = true;
$('#instruct_enabled').prop('checked', true).trigger('change');
toastr.info(`Instruct Mode enabled`);
@ -359,7 +359,7 @@ jQuery(() => {
$('#instruct_presets').trigger('change');
// When instruct mode gets disabled, select default context preset
} else {
selectContextPreset('Default');
selectContextPreset(power_user.default_context);
}
});
@ -397,7 +397,7 @@ jQuery(() => {
}
if (!foundMatch) {
// If no match was found, select default context preset
selectContextPreset('Default');
selectContextPreset(power_user.default_context);
}
highlightDefaultPreset();

View File

@ -176,6 +176,7 @@ let power_user = {
activation_regex: "",
},
default_context: 'Default',
context: {
preset: 'Default',
story_string: defaultStoryString,
@ -951,7 +952,29 @@ function loadContextSettings() {
break;
}
}
highlightDefaultContext();
saveSettingsDebounced();
});
$('#context_set_default').on('click', function () {
if (power_user.context.preset !== power_user.default_context) {
power_user.default_context = power_user.context.preset;
$(this).addClass('default');
toastr.info(`Default context template set to ${power_user.default_context}`);
highlightDefaultContext();
saveSettingsDebounced();
}
});
highlightDefaultContext();
}
function highlightDefaultContext() {
$('#context_set_default').toggleClass('default', power_user.default_context === power_user.context.preset);
}
export function fuzzySearchCharacters(searchValue) {

View File

@ -18,7 +18,7 @@ import {
import { groups, selected_group } from "./group-chats.js";
import { instruct_presets } from "./instruct-mode.js";
import { kai_settings } from "./kai-settings.js";
import { power_user } from "./power-user.js";
import { context_presets, power_user } from "./power-user.js";
import {
textgenerationwebui_preset_names,
textgenerationwebui_presets,
@ -167,6 +167,10 @@ class PresetManager {
presets = textgenerationwebui_presets;
preset_names = textgenerationwebui_preset_names;
break;
case "context":
presets = context_presets;
preset_names = context_presets.map(x => x.name);
break;
case "instruct":
presets = instruct_presets;
preset_names = instruct_presets.map(x => x.name);
@ -179,11 +183,11 @@ class PresetManager {
}
isKeyedApi() {
return this.apiId == "textgenerationwebui" || this.apiId == "instruct";
return this.apiId == "textgenerationwebui" || this.apiId == "context" || this.apiId == "instruct";
}
isNonGenericApi() {
return this.apiId == "instruct";
return this.apiId == "context" || this.apiId == "instruct";
}
updateList(name, preset) {
@ -231,10 +235,14 @@ class PresetManager {
return nai_settings;
case "textgenerationwebui":
return textgenerationwebui_settings;
case "context":
const context_preset = deepClone(power_user.context);
context_preset['name'] = name || power_user.context.preset;
return context_preset;
case "instruct":
const preset = deepClone(power_user.instruct);
preset['name'] = name || power_user.instruct.preset;
return preset;
const instruct_preset = deepClone(power_user.instruct);
instruct_preset['name'] = name || power_user.instruct.preset;
return instruct_preset;
default:
console.warn(`Unknown API ID ${apiId}`);
return {};

View File

@ -1291,6 +1291,10 @@ select option:not(:checked) {
color: var(--active) !important;
}
#context_set_default.default {
color: var(--preferred) !important;
}
#instruct_set_default.default {
color: var(--preferred) !important;
}