Fix preset migration
This commit is contained in:
parent
5a92f72703
commit
a999d6e171
|
@ -6,26 +6,25 @@ import {power_user} from "./power-user.js";
|
|||
* Register migrations for the prompt manager when settings are loaded or an Open AI preset is loaded.
|
||||
*/
|
||||
const registerPromptManagerMigration = (saveSettingsCallback) => {
|
||||
const migrate = (settings) => {
|
||||
const migrate = (settings, preset) => {
|
||||
// If any of the specified settings exist, run the migration
|
||||
if (settings.main_prompt || settings.nsfw_prompt || settings.jailbreak_prompt) {
|
||||
if (preset.main_prompt || preset.nsfw_prompt || preset.jailbreak_prompt) {
|
||||
console.log('Running one-time configuration migration for prompt manager.')
|
||||
if (settings.prompts === undefined || settings.prompts.length === 0) settings.prompts = chatCompletionDefaultPrompts.prompts;
|
||||
|
||||
const findPrompt = (identifier) => settings.prompts.find(prompt => identifier === prompt.identifier);
|
||||
|
||||
if (settings.main_prompt) {
|
||||
findPrompt('main').content = settings.main_prompt
|
||||
if (preset.main_prompt) {
|
||||
findPrompt('main').content = preset.main_prompt
|
||||
delete settings.main_prompt;
|
||||
}
|
||||
|
||||
if (settings.nsfw_prompt) {
|
||||
findPrompt('nsfw').content = settings.nsfw_prompt
|
||||
if (preset.nsfw_prompt) {
|
||||
findPrompt('nsfw').content = preset.nsfw_prompt
|
||||
delete settings.nsfw_prompt;
|
||||
}
|
||||
|
||||
if (settings.jailbreak_prompt) {
|
||||
findPrompt('jailbreak').content = settings.jailbreak_prompt
|
||||
if (preset.jailbreak_prompt) {
|
||||
findPrompt('jailbreak').content = preset.jailbreak_prompt
|
||||
delete settings.jailbreak_prompt;
|
||||
}
|
||||
|
||||
|
@ -33,8 +32,14 @@ const registerPromptManagerMigration = (saveSettingsCallback) => {
|
|||
}
|
||||
};
|
||||
|
||||
eventSource.on(event_types.SETTINGS_LOADED_BEFORE, settings => migrate(settings));
|
||||
eventSource.on(event_types.OAI_PRESET_CHANGED, settings => migrate(settings));
|
||||
const migrateSettings = (settings) => migrate(settings, settings);
|
||||
const migratePreset = (event) => {
|
||||
migrate(event.settings, event.preset);
|
||||
event.callback(event.presetName, event.settings, false);
|
||||
}
|
||||
|
||||
eventSource.on(event_types.SETTINGS_LOADED_BEFORE, settings => migrateSettings(settings));
|
||||
eventSource.on(event_types.OAI_PRESET_CHANGED, settings => migratePreset(settings));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue