DRY

48c3e81f429dbd3094b8c37c10029c9510f869d2

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +7 -14Showing whitespace changes
public/scripts/instruct-mode.js+7 -14
@@ -570,12 +570,8 @@ function selectMatchingContextTemplate(name) {
570570 * @returns {import('./macros.js').Macro[]} Macro objects.
571571 */
572572export function getInstructMacros(env) {
573- const syspromptMacros = {
574- 'systemPrompt': (power_user.prefer_character_prompt && env.charPrompt ? env.charPrompt : power_user.sysprompt.content),
575- 'defaultSystemPrompt|instructSystem|instructSystemPrompt': power_user.sysprompt.content,
576- };
577-
578573 const instructMacros = {
574+ // Instruct template macros
579575 'instructSystemPromptPrefix': power_user.instruct.system_sequence_prefix,
580576 'instructSystemPromptSuffix': power_user.instruct.system_sequence_suffix,
581577 'instructInput|instructUserPrefix': power_user.instruct.input_sequence,
@@ -591,6 +587,12 @@ export function getInstructMacros(env) {
591587 'instructSystemInstructionPrefix': power_user.instruct.last_system_sequence,
592588 'instructFirstInput|instructFirstUserPrefix': power_user.instruct.first_input_sequence || power_user.instruct.input_sequence,
593589 'instructLastInput|instructLastUserPrefix': power_user.instruct.last_input_sequence || power_user.instruct.input_sequence,
590+ // System prompt macros
591+ 'systemPrompt': (power_user.prefer_character_prompt && env.charPrompt ? env.charPrompt : power_user.sysprompt.content),
592+ 'defaultSystemPrompt|instructSystem|instructSystemPrompt': power_user.sysprompt.content,
593+ // Context template macros
594+ 'chatSeparator': power_user.context.example_separator,
595+ 'chatStart': power_user.context.chat_start,
594596 };
595597
596598 const macros = [];
@@ -601,15 +603,6 @@ export function getInstructMacros(env) {
601603 macros.push({ regex, replace });
602604 }
603605
604- for (const [placeholder, value] of Object.entries(syspromptMacros)) {
605- const regex = new RegExp(`{{(${placeholder})}}`, 'gi');
606- const replace = () => power_user.sysprompt.enabled ? value : '';
607- macros.push({ regex, replace });
608- }
609-
610- macros.push({ regex: /{{exampleSeparator}}/gi, replace: () => power_user.context.example_separator });
611- macros.push({ regex: /{{chatStart}}/gi, replace: () => power_user.context.chat_start });
612-
613606 return macros;
614607}
615608