Better customized sysprompt migration

This commit is contained in:
Cohee 2024-09-22 12:20:07 +03:00
parent 6179c361dc
commit ade6ef8af8
2 changed files with 14 additions and 7 deletions

View File

@ -934,6 +934,7 @@ async function firstLoadInit() {
initDefaultSlashCommands(); initDefaultSlashCommands();
initTextGenModels(); initTextGenModels();
initSystemPrompts(); initSystemPrompts();
await initPresetManager();
await getSystemMessages(); await getSystemMessages();
sendSystemMessage(system_message_types.WELCOME); sendSystemMessage(system_message_types.WELCOME);
sendSystemMessage(system_message_types.WELCOME_PROMPT); sendSystemMessage(system_message_types.WELCOME_PROMPT);
@ -947,7 +948,6 @@ async function firstLoadInit() {
await getCharacters(); await getCharacters();
await getBackgrounds(); await getBackgrounds();
await initTokenizers(); await initTokenizers();
await initPresetManager();
initBackgrounds(); initBackgrounds();
initAuthorsNote(); initAuthorsNote();
initPersonas(); initPersonas();

View File

@ -17,14 +17,21 @@ const $select = $('#sysprompt_select');
const $content = $('#sysprompt_content'); const $content = $('#sysprompt_content');
const $contentBlock = $('#SystemPromptBlock'); const $contentBlock = $('#SystemPromptBlock');
function migrateSystemPromptFromInstructMode() { async function migrateSystemPromptFromInstructMode() {
if ('system_prompt' in power_user.instruct) { if ('system_prompt' in power_user.instruct) {
power_user.sysprompt.enabled = power_user.instruct.enabled; const prompt = String(power_user.instruct.system_prompt);
power_user.sysprompt.content = String(power_user.instruct.system_prompt);
delete power_user.instruct.system_prompt; delete power_user.instruct.system_prompt;
power_user.sysprompt.enabled = power_user.instruct.enabled;
power_user.sysprompt.content = prompt;
if (system_prompts.some(x => x.name === power_user.instruct.preset)) { const existingPromptName = system_prompts.find(x => x.content === prompt)?.name;
power_user.sysprompt.name = power_user.instruct.preset;
if (existingPromptName) {
power_user.sysprompt.name = existingPromptName;
} else {
const data = { name: `${power_user.instruct.preset} (Migrated)`, content: prompt };
await getPresetManager('sysprompt')?.savePreset(data.name, data);
power_user.sysprompt.name = data.name;
} }
saveSettingsDebounced(); saveSettingsDebounced();
@ -41,7 +48,7 @@ export async function loadSystemPrompts(data) {
system_prompts = data.sysprompt; system_prompts = data.sysprompt;
} }
migrateSystemPromptFromInstructMode(); await migrateSystemPromptFromInstructMode();
toggleSystemPromptDisabledControls(); toggleSystemPromptDisabledControls();
for (const prompt of system_prompts) { for (const prompt of system_prompts) {