From 3c61074d780280e907bac6ae4a78d88fdb1a2081 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 18 Mar 2025 18:15:59 +0200 Subject: [PATCH 1/2] Add macros for Author's Notes Closes #3716 --- public/scripts/authors-note.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/public/scripts/authors-note.js b/public/scripts/authors-note.js index 6d0aedfb3..12efed7eb 100644 --- a/public/scripts/authors-note.js +++ b/public/scripts/authors-note.js @@ -17,6 +17,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js'; import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js'; export { MODULE_NAME as NOTE_MODULE_NAME }; import { t } from './i18n.js'; +import { MacrosParser } from './macros.js'; const MODULE_NAME = '2_floating_prompt'; // <= Deliberate, for sorting lower than memory @@ -576,4 +577,8 @@ export function initAuthorsNote() { `, })); eventSource.on(event_types.CHAT_CHANGED, onChatChanged); + + MacrosParser.registerMacro('authorsNote', () => chat_metadata[metadata_keys.prompt] ?? '', t`The contents of the Author's Note`); + MacrosParser.registerMacro('charAuthorsNote', () => this_chid !== undefined ? (extension_settings.note.chara.find((e) => e.name === getCharaFilename())?.prompt ?? '') : '', t`The contents of the Character Author's Note`); + MacrosParser.registerMacro('defaultAuthorsNote', () => extension_settings.note.default ?? '', t`The contents of the Default Author's Note`); } From 4df98b034185de05b15bfd6ae33a604c8f887549 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 18 Mar 2025 20:27:15 +0200 Subject: [PATCH 2/2] Add macro for charDepthPrompt --- public/script.js | 35 ++++++++++++++++++++++++---- public/scripts/templates/macros.html | 3 ++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/public/script.js b/public/script.js index d623793d7..fefe91fd1 100644 --- a/public/script.js +++ b/public/script.js @@ -2746,6 +2746,7 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re environment.mesExamplesRaw = fields.mesExamples || ''; environment.charVersion = fields.version || ''; environment.char_version = fields.version || ''; + environment.charDepthPrompt = fields.charDepthPrompt || ''; } // Must be substituted last so that they're replaced inside {{description}} @@ -3097,10 +3098,30 @@ export function baseChatReplace(value, name1, name2) { /** * Returns the character card fields for the current character. - * @returns {{system: string, mesExamples: string, description: string, personality: string, persona: string, scenario: string, jailbreak: string, version: string}} + * @typedef {object} CharacterCardFields + * @property {string} system System prompt + * @property {string} mesExamples Message examples + * @property {string} description Description + * @property {string} personality Personality + * @property {string} persona Persona + * @property {string} scenario Scenario + * @property {string} jailbreak Jailbreak instructions + * @property {string} version Character version + * @property {string} charDepthPrompt Character depth note + * @returns {CharacterCardFields} Character card fields */ export function getCharacterCardFields() { - const result = { system: '', mesExamples: '', description: '', personality: '', persona: '', scenario: '', jailbreak: '', version: '' }; + const result = { + system: '', + mesExamples: '', + description: '', + personality: '', + persona: '', + scenario: '', + jailbreak: '', + version: '', + charDepthPrompt: '', + }; result.persona = baseChatReplace(power_user.persona_description?.trim(), name1, name2); const character = characters[this_chid]; @@ -3117,6 +3138,7 @@ export function getCharacterCardFields() { result.system = power_user.prefer_character_prompt ? baseChatReplace(character.data?.system_prompt?.trim(), name1, name2) : ''; result.jailbreak = power_user.prefer_character_jailbreak ? baseChatReplace(character.data?.post_history_instructions?.trim(), name1, name2) : ''; result.version = character.data?.character_version ?? ''; + result.charDepthPrompt = baseChatReplace(character.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2); if (selected_group) { const groupCards = getGroupCharacterCards(selected_group, Number(this_chid)); @@ -3612,7 +3634,8 @@ export async function generateRaw(prompt, api, instructOverride, quietToLoud, sy throw new Error(data.response); } - const message = cleanUpMessage(extractMessageFromData(data), false, false, true); + // format result, exclude user prompt bias + const message = cleanUpMessage(extractMessageFromData(data), false, false, true, null, false); if (!message) { throw new Error('No message generated'); @@ -3921,6 +3944,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro mesExamples, system, jailbreak, + charDepthPrompt, } = getCharacterCardFields(); if (main_api !== 'openai') { @@ -3943,7 +3967,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth, extension_settings.note.allowWIScan, role); }); } else { - const depthPromptText = baseChatReplace(characters[this_chid]?.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || ''; + const depthPromptText = charDepthPrompt || ''; const depthPromptDepth = characters[this_chid]?.data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default; const depthPromptRole = getExtensionPromptRoleByName(characters[this_chid]?.data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default); setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth, extension_settings.note.allowWIScan, depthPromptRole); @@ -5884,13 +5908,14 @@ function extractMultiSwipes(data, type) { return swipes; } -export function cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncompleteSentences = false, stoppingStrings = null) { +export function cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncompleteSentences = false, stoppingStrings = null, includeUserPromptBias = true) { if (!getMessage) { return ''; } // Add the prompt bias before anything else if ( + includeUserPromptBias && power_user.user_prompt_bias && !isImpersonate && !isContinue && diff --git a/public/scripts/templates/macros.html b/public/scripts/templates/macros.html index b7db29dec..faee3c949 100644 --- a/public/scripts/templates/macros.html +++ b/public/scripts/templates/macros.html @@ -20,7 +20,8 @@