mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-01 10:27:43 +01:00
Migrate system prompts from imported instruct template
This commit is contained in:
parent
0bc6a572c6
commit
b0c537d014
public/scripts
@ -25,7 +25,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashComma
|
|||||||
import { enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
import { enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';
|
import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';
|
||||||
import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
|
import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
|
||||||
import { system_prompts } from './sysprompt.js';
|
import { checkForSystemPromptInInstructTemplate, system_prompts } from './sysprompt.js';
|
||||||
import {
|
import {
|
||||||
textgenerationwebui_preset_names,
|
textgenerationwebui_preset_names,
|
||||||
textgenerationwebui_presets,
|
textgenerationwebui_presets,
|
||||||
@ -72,7 +72,7 @@ function autoSelectPreset() {
|
|||||||
* @param {string} apiId API id
|
* @param {string} apiId API id
|
||||||
* @returns {PresetManager} Preset manager
|
* @returns {PresetManager} Preset manager
|
||||||
*/
|
*/
|
||||||
function getPresetManager(apiId = '') {
|
export function getPresetManager(apiId = '') {
|
||||||
if (!apiId) {
|
if (!apiId) {
|
||||||
apiId = main_api == 'koboldhorde' ? 'kobold' : main_api;
|
apiId = main_api == 'koboldhorde' ? 'kobold' : main_api;
|
||||||
}
|
}
|
||||||
@ -183,6 +183,10 @@ class PresetManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async savePreset(name, settings) {
|
async savePreset(name, settings) {
|
||||||
|
if (this.apiId === 'instruct') {
|
||||||
|
await checkForSystemPromptInInstructTemplate(name, settings);
|
||||||
|
}
|
||||||
|
|
||||||
const preset = settings ?? this.getPresetSettings(name);
|
const preset = settings ?? this.getPresetSettings(name);
|
||||||
|
|
||||||
const response = await fetch('/api/presets/save', {
|
const response = await fetch('/api/presets/save', {
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import { saveSettingsDebounced } from '../script.js';
|
import { saveSettingsDebounced } from '../script.js';
|
||||||
|
import { callGenericPopup, POPUP_TYPE } from './popup.js';
|
||||||
import { power_user } from './power-user.js';
|
import { power_user } from './power-user.js';
|
||||||
|
import { getPresetManager } from './preset-manager.js';
|
||||||
import { SlashCommand } from './slash-commands/SlashCommand.js';
|
import { SlashCommand } from './slash-commands/SlashCommand.js';
|
||||||
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
|
||||||
import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
import { enumTypes, SlashCommandEnumValue } from './slash-commands/SlashCommandEnumValue.js';
|
import { enumTypes, SlashCommandEnumValue } from './slash-commands/SlashCommandEnumValue.js';
|
||||||
import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
|
import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
|
||||||
|
import { renderTemplateAsync } from './templates.js';
|
||||||
import { isTrueBoolean, resetScrollHeight } from './utils.js';
|
import { isTrueBoolean, resetScrollHeight } from './utils.js';
|
||||||
|
|
||||||
export let system_prompts = [];
|
export let system_prompts = [];
|
||||||
@ -39,7 +42,7 @@ export async function loadSystemPrompts(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
migrateSystemPromptFromInstructMode();
|
migrateSystemPromptFromInstructMode();
|
||||||
toggleSyspromptDisabledControls();
|
toggleSystemPromptDisabledControls();
|
||||||
|
|
||||||
for (const prompt of system_prompts) {
|
for (const prompt of system_prompts) {
|
||||||
$('<option>').val(prompt.name).text(prompt.name).appendTo($select);
|
$('<option>').val(prompt.name).text(prompt.name).appendTo($select);
|
||||||
@ -53,7 +56,29 @@ export async function loadSystemPrompts(data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleSyspromptDisabledControls() {
|
/**
|
||||||
|
* Checks if the instruct template has a system prompt and prompts the user to save it as a system prompt.
|
||||||
|
* @param {string} name Name of the instruct template
|
||||||
|
* @param {object} template Instruct template object
|
||||||
|
*/
|
||||||
|
export async function checkForSystemPromptInInstructTemplate(name, template) {
|
||||||
|
if ('system_prompt' in template && name && template.system_prompt && !system_prompts.some(x => x.name === name)) {
|
||||||
|
const html = await renderTemplateAsync('migrateInstructPrompt', { prompt: template.system_prompt });
|
||||||
|
const confirm = await callGenericPopup(html, POPUP_TYPE.CONFIRM);
|
||||||
|
if (confirm) {
|
||||||
|
const prompt = { name: name, content: template.system_prompt };
|
||||||
|
const presetManager = getPresetManager('sysprompt');
|
||||||
|
await presetManager.savePreset(prompt.name, prompt);
|
||||||
|
toastr.success(`System prompt "${prompt.name}" has been saved.`);
|
||||||
|
} else {
|
||||||
|
toastr.info('System prompt has been discarded.');
|
||||||
|
}
|
||||||
|
|
||||||
|
delete template.system_prompt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSystemPromptDisabledControls() {
|
||||||
$enabled.parent().find('i').toggleClass('toggleEnabled', !!power_user.sysprompt.enabled);
|
$enabled.parent().find('i').toggleClass('toggleEnabled', !!power_user.sysprompt.enabled);
|
||||||
$contentBlock.toggleClass('disabled', !power_user.sysprompt.enabled);
|
$contentBlock.toggleClass('disabled', !power_user.sysprompt.enabled);
|
||||||
}
|
}
|
||||||
@ -61,7 +86,7 @@ function toggleSyspromptDisabledControls() {
|
|||||||
function enableSystemPromptCallback() {
|
function enableSystemPromptCallback() {
|
||||||
power_user.sysprompt.enabled = true;
|
power_user.sysprompt.enabled = true;
|
||||||
$enabled.prop('checked', true);
|
$enabled.prop('checked', true);
|
||||||
toggleSyspromptDisabledControls();
|
toggleSystemPromptDisabledControls();
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -69,7 +94,7 @@ function enableSystemPromptCallback() {
|
|||||||
function disableSystemPromptCallback() {
|
function disableSystemPromptCallback() {
|
||||||
power_user.sysprompt.enabled = false;
|
power_user.sysprompt.enabled = false;
|
||||||
$enabled.prop('checked', false);
|
$enabled.prop('checked', false);
|
||||||
toggleSyspromptDisabledControls();
|
toggleSystemPromptDisabledControls();
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -112,7 +137,7 @@ function selectSystemPromptCallback(args, name) {
|
|||||||
jQuery(function () {
|
jQuery(function () {
|
||||||
$enabled.on('input', function () {
|
$enabled.on('input', function () {
|
||||||
power_user.sysprompt.enabled = !!$(this).prop('checked');
|
power_user.sysprompt.enabled = !!$(this).prop('checked');
|
||||||
toggleSyspromptDisabledControls();
|
toggleSystemPromptDisabledControls();
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
7
public/scripts/templates/migrateInstructPrompt.html
Normal file
7
public/scripts/templates/migrateInstructPrompt.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<h3>
|
||||||
|
This instruct template also contains a system prompt.
|
||||||
|
</h3>
|
||||||
|
<div class="marginBot10">
|
||||||
|
Would you like to migrate the system prompt from the template?
|
||||||
|
</div>
|
||||||
|
<textarea class="wide100p textarea_compact" rows="8">{{prompt}}</textarea>
|
Loading…
x
Reference in New Issue
Block a user