mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-03 12:47:35 +01:00
Migrate sysprompts from instruct
This commit is contained in:
parent
73ee869749
commit
2f7d694f54
@ -9,6 +9,21 @@ const $select = $('#sysprompt_select');
|
|||||||
const $content = $('#sysprompt_content');
|
const $content = $('#sysprompt_content');
|
||||||
const $contentBlock = $('#SystemPromptBlock');
|
const $contentBlock = $('#SystemPromptBlock');
|
||||||
|
|
||||||
|
function migrateSystemPromptFromInstructMode() {
|
||||||
|
if ('system_prompt' in power_user.instruct) {
|
||||||
|
power_user.sysprompt.enabled = power_user.instruct.enabled;
|
||||||
|
power_user.sysprompt.content = String(power_user.instruct.system_prompt);
|
||||||
|
delete power_user.instruct.system_prompt;
|
||||||
|
|
||||||
|
if (system_prompts.some(x => x.name === power_user.instruct.preset)) {
|
||||||
|
power_user.sysprompt.name = power_user.instruct.preset;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSettingsDebounced();
|
||||||
|
toastr.info('System prompt settings have been moved from the Instruct Mode.', 'Migration notice', { timeOut: 5000 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads sysprompt settings from the given data object.
|
* Loads sysprompt settings from the given data object.
|
||||||
* @param {object} data Settings data object.
|
* @param {object} data Settings data object.
|
||||||
@ -18,6 +33,7 @@ export async function loadSystemPrompts(data) {
|
|||||||
system_prompts = data.sysprompt;
|
system_prompts = data.sysprompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
migrateSystemPromptFromInstructMode();
|
||||||
toggleSyspromptDisabledControls();
|
toggleSyspromptDisabledControls();
|
||||||
|
|
||||||
for (const prompt of system_prompts) {
|
for (const prompt of system_prompts) {
|
||||||
|
@ -932,6 +932,7 @@ async function verifySecuritySettings() {
|
|||||||
userModule.initUserStorage(dataRoot)
|
userModule.initUserStorage(dataRoot)
|
||||||
.then(userModule.ensurePublicDirectoriesExist)
|
.then(userModule.ensurePublicDirectoriesExist)
|
||||||
.then(userModule.migrateUserData)
|
.then(userModule.migrateUserData)
|
||||||
|
.then(userModule.migrateSystemPrompts)
|
||||||
.then(verifySecuritySettings)
|
.then(verifySecuritySettings)
|
||||||
.then(preSetupTasks)
|
.then(preSetupTasks)
|
||||||
.finally(startServer);
|
.finally(startServer);
|
||||||
|
32
src/users.js
32
src/users.js
@ -9,6 +9,7 @@ const storage = require('node-persist');
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
const archiver = require('archiver');
|
const archiver = require('archiver');
|
||||||
|
const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||||
|
|
||||||
const { USER_DIRECTORY_TEMPLATE, DEFAULT_USER, PUBLIC_DIRECTORIES, DEFAULT_AVATAR, SETTINGS_FILE } = require('./constants');
|
const { USER_DIRECTORY_TEMPLATE, DEFAULT_USER, PUBLIC_DIRECTORIES, DEFAULT_AVATAR, SETTINGS_FILE } = require('./constants');
|
||||||
const { getConfigValue, color, delay, setConfigValue, generateTimestamp } = require('./util');
|
const { getConfigValue, color, delay, setConfigValue, generateTimestamp } = require('./util');
|
||||||
@ -323,6 +324,36 @@ async function migrateUserData() {
|
|||||||
console.log(color.green('Migration completed!'));
|
console.log(color.green('Migration completed!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function migrateSystemPrompts() {
|
||||||
|
const directories = await getUserDirectoriesList();
|
||||||
|
for (const directory of directories) {
|
||||||
|
try {
|
||||||
|
const migrateMarker = path.join(directory.sysprompt, '.migrated');
|
||||||
|
if (fs.existsSync(migrateMarker)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const instucts = fs.readdirSync(directory.instruct);
|
||||||
|
for (const instruct of instucts) {
|
||||||
|
const instructPath = path.join(directory.instruct, instruct);
|
||||||
|
const syspromptPath = path.join(directory.sysprompt, instruct);
|
||||||
|
if (path.extname(instruct) === '.json' && !fs.existsSync(syspromptPath)) {
|
||||||
|
const instructData = JSON.parse(fs.readFileSync(instructPath, 'utf8'));
|
||||||
|
if ('system_prompt' in instructData && 'name' in instructData) {
|
||||||
|
const syspromptData = { name: instructData.name, content: instructData.system_prompt };
|
||||||
|
writeFileAtomicSync(syspromptPath, JSON.stringify(syspromptData, null, 4));
|
||||||
|
delete instructData.system_prompt;
|
||||||
|
writeFileAtomicSync(instructPath, JSON.stringify(instructData, null, 4));
|
||||||
|
console.log(`Migrated system prompt ${instruct} for ${directory.root.split(path.sep).pop()}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeFileAtomicSync(migrateMarker, '');
|
||||||
|
} catch {
|
||||||
|
// Ignore errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a user handle to a storage key.
|
* Converts a user handle to a storage key.
|
||||||
* @param {string} handle User handle
|
* @param {string} handle User handle
|
||||||
@ -724,6 +755,7 @@ module.exports = {
|
|||||||
requireLoginMiddleware,
|
requireLoginMiddleware,
|
||||||
requireAdminMiddleware,
|
requireAdminMiddleware,
|
||||||
migrateUserData,
|
migrateUserData,
|
||||||
|
migrateSystemPrompts,
|
||||||
getPasswordSalt,
|
getPasswordSalt,
|
||||||
getPasswordHash,
|
getPasswordHash,
|
||||||
getCsrfSecret,
|
getCsrfSecret,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user