Fix instruct macros not using a proper enabled field

This commit is contained in:
Cohee 2024-11-02 16:34:21 +02:00
parent cfd1545b8a
commit 8c3ac0ac5a

View File

@ -570,36 +570,113 @@ function selectMatchingContextTemplate(name) {
* @returns {import('./macros.js').Macro[]} Macro objects.
*/
export function getInstructMacros(env) {
const instructMacros = {
/** @type {{ key: string,value: string, enabled: boolean }[]} */
const instructMacros = [
// Instruct template macros
'instructSystemPromptPrefix': power_user.instruct.system_sequence_prefix,
'instructSystemPromptSuffix': power_user.instruct.system_sequence_suffix,
'instructInput|instructUserPrefix': power_user.instruct.input_sequence,
'instructUserSuffix': power_user.instruct.input_suffix,
'instructOutput|instructAssistantPrefix': power_user.instruct.output_sequence,
'instructSeparator|instructAssistantSuffix': power_user.instruct.output_suffix,
'instructSystemPrefix': power_user.instruct.system_sequence,
'instructSystemSuffix': power_user.instruct.system_suffix,
'instructFirstOutput|instructFirstAssistantPrefix': power_user.instruct.first_output_sequence || power_user.instruct.output_sequence,
'instructLastOutput|instructLastAssistantPrefix': power_user.instruct.last_output_sequence || power_user.instruct.output_sequence,
'instructStop': power_user.instruct.stop_sequence,
'instructUserFiller': power_user.instruct.user_alignment_message,
'instructSystemInstructionPrefix': power_user.instruct.last_system_sequence,
'instructFirstInput|instructFirstUserPrefix': power_user.instruct.first_input_sequence || power_user.instruct.input_sequence,
'instructLastInput|instructLastUserPrefix': power_user.instruct.last_input_sequence || power_user.instruct.input_sequence,
{
key: 'instructSystemPromptPrefix',
value: power_user.instruct.system_sequence_prefix,
enabled: power_user.instruct.enabled,
},
{
key: 'instructSystemPromptSuffix',
value: power_user.instruct.system_sequence_suffix,
enabled: power_user.instruct.enabled,
},
{
key: 'instructInput|instructUserPrefix',
value: power_user.instruct.input_sequence,
enabled: power_user.instruct.enabled,
},
{
key: 'instructUserSuffix',
value: power_user.instruct.input_suffix,
enabled: power_user.instruct.enabled,
},
{
key: 'instructOutput|instructAssistantPrefix',
value: power_user.instruct.output_sequence,
enabled: power_user.instruct.enabled,
},
{
key: 'instructSeparator|instructAssistantSuffix',
value: power_user.instruct.output_suffix,
enabled: power_user.instruct.enabled,
},
{
key: 'instructSystemPrefix',
value: power_user.instruct.system_sequence,
enabled: power_user.instruct.enabled,
},
{
key: 'instructSystemSuffix',
value: power_user.instruct.system_suffix,
enabled: power_user.instruct.enabled,
},
{
key: 'instructFirstOutput|instructFirstAssistantPrefix',
value: power_user.instruct.first_output_sequence || power_user.instruct.output_sequence,
enabled: power_user.instruct.enabled,
},
{
key: 'instructLastOutput|instructLastAssistantPrefix',
value: power_user.instruct.last_output_sequence || power_user.instruct.output_sequence,
enabled: power_user.instruct.enabled,
},
{
key: 'instructStop',
value: power_user.instruct.stop_sequence,
enabled: power_user.instruct.enabled,
},
{
key: 'instructUserFiller',
value: power_user.instruct.user_alignment_message,
enabled: power_user.instruct.enabled,
},
{
key: 'instructSystemInstructionPrefix',
value: power_user.instruct.last_system_sequence,
enabled: power_user.instruct.enabled,
},
{
key: 'instructFirstInput|instructFirstUserPrefix',
value: power_user.instruct.first_input_sequence || power_user.instruct.input_sequence,
enabled: power_user.instruct.enabled,
},
{
key: 'instructLastInput|instructLastUserPrefix',
value: power_user.instruct.last_input_sequence || power_user.instruct.input_sequence,
enabled: power_user.instruct.enabled,
},
// System prompt macros
'systemPrompt': (power_user.prefer_character_prompt && env.charPrompt ? env.charPrompt : power_user.sysprompt.content),
'defaultSystemPrompt|instructSystem|instructSystemPrompt': power_user.sysprompt.content,
{
key: 'systemPrompt',
value: power_user.prefer_character_prompt && env.charPrompt ? env.charPrompt : power_user.sysprompt.content,
enabled: power_user.sysprompt.enabled,
},
{
key: 'defaultSystemPrompt|instructSystem|instructSystemPrompt',
value: power_user.sysprompt.content,
enabled: power_user.sysprompt.enabled,
},
// Context template macros
'chatSeparator': power_user.context.example_separator,
'chatStart': power_user.context.chat_start,
};
{
key: 'chatSeparator',
value: power_user.context.example_separator,
enabled: true,
},
{
key: 'chatStart',
value: power_user.context.chat_start,
enabled: true,
},
];
const macros = [];
for (const [placeholder, value] of Object.entries(instructMacros)) {
const regex = new RegExp(`{{(${placeholder})}}`, 'gi');
const replace = () => power_user.instruct.enabled ? value : '';
for (const { key, value, enabled } of instructMacros) {
const regex = new RegExp(`{{(${key})}}`, 'gi');
const replace = () => enabled ? value : '';
macros.push({ regex, replace });
}