diff --git a/public/script.js b/public/script.js index add7da3d5..27ce9a3ba 100644 --- a/public/script.js +++ b/public/script.js @@ -165,6 +165,7 @@ import { formatInstructModeExamples, getInstructStoppingSequences, autoSelectInstructPreset, + formatInstructModeSystemPrompt, } from "./scripts/instruct-mode.js"; import { applyLocale } from "./scripts/i18n.js"; import { getTokenCount, getTokenizerModel, saveTokenCache } from "./scripts/tokenizers.js"; @@ -2360,6 +2361,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, if (isInstruct) { systemPrompt = power_user.prefer_character_prompt && systemPrompt ? systemPrompt : baseChatReplace(power_user.instruct.system_prompt, name1, name2); + systemPrompt = formatInstructModeSystemPrompt(substituteParams(systemPrompt, name1, name2, power_user.instruct.system_prompt)); } // Parse example messages diff --git a/public/scripts/instruct-mode.js b/public/scripts/instruct-mode.js index bc75e266d..d15274d2f 100644 --- a/public/scripts/instruct-mode.js +++ b/public/scripts/instruct-mode.js @@ -189,6 +189,20 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata return text; } +/** + * Formats instruct mode system prompt. + * @param {string} systemPrompt System prompt string. + * @returns {string} Formatted instruct mode system prompt. + */ +export function formatInstructModeSystemPrompt(systemPrompt){ + if (power_user.instruct.system_sequence) { + const separator = power_user.instruct.wrap ? '\n' : ''; + return power_user.instruct.system_sequence + separator + systemPrompt; + } + + return systemPrompt; +} + /** * Formats example messages according to instruct mode settings. * @param {string} mesExamples Example messages string.