Merge pull request #3718 from SillyTavern/feat/an-macro Add macros for Author's Notes
Signed| @@ -2746,6 +2746,7 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re | ||
| 2746 | 2746 | environment.mesExamplesRaw = fields.mesExamples || ''; |
| 2747 | 2747 | environment.charVersion = fields.version || ''; |
| 2748 | 2748 | environment.char_version = fields.version || ''; |
| 2749 | + environment.charDepthPrompt = fields.charDepthPrompt || ''; | |
| 2749 | 2750 | } |
| 2750 | 2751 | |
| 2751 | 2752 | // Must be substituted last so that they're replaced inside {{description}} |
| @@ -3097,10 +3098,30 @@ export function baseChatReplace(value, name1, name2) { | ||
| 3097 | 3098 | |
| 3098 | 3099 | /** |
| 3099 | 3100 | * Returns the character card fields for the current character. |
| 3100 | - * @returns {{system: string, mesExamples: string, description: string, personality: string, persona: string, scenario: string, jailbreak: string, version: string}} | |
| 3101 | + * @typedef {object} CharacterCardFields | |
| 3102 | + * @property {string} system System prompt | |
| 3103 | + * @property {string} mesExamples Message examples | |
| 3104 | + * @property {string} description Description | |
| 3105 | + * @property {string} personality Personality | |
| 3106 | + * @property {string} persona Persona | |
| 3107 | + * @property {string} scenario Scenario | |
| 3108 | + * @property {string} jailbreak Jailbreak instructions | |
| 3109 | + * @property {string} version Character version | |
| 3110 | + * @property {string} charDepthPrompt Character depth note | |
| 3111 | + * @returns {CharacterCardFields} Character card fields | |
| 3101 | 3112 | */ |
| 3102 | 3113 | export function getCharacterCardFields() { |
| 3103 | - const result = { system: '', mesExamples: '', description: '', personality: '', persona: '', scenario: '', jailbreak: '', version: '' }; | |
| 3114 | + const result = { | |
| 3115 | + system: '', | |
| 3116 | + mesExamples: '', | |
| 3117 | + description: '', | |
| 3118 | + personality: '', | |
| 3119 | + persona: '', | |
| 3120 | + scenario: '', | |
| 3121 | + jailbreak: '', | |
| 3122 | + version: '', | |
| 3123 | + charDepthPrompt: '', | |
| 3124 | + }; | |
| 3104 | 3125 | result.persona = baseChatReplace(power_user.persona_description?.trim(), name1, name2); |
| 3105 | 3126 | |
| 3106 | 3127 | const character = characters[this_chid]; |
| @@ -3117,6 +3138,7 @@ export function getCharacterCardFields() { | ||
| 3117 | 3138 | result.system = power_user.prefer_character_prompt ? baseChatReplace(character.data?.system_prompt?.trim(), name1, name2) : ''; |
| 3118 | 3139 | result.jailbreak = power_user.prefer_character_jailbreak ? baseChatReplace(character.data?.post_history_instructions?.trim(), name1, name2) : ''; |
| 3119 | 3140 | result.version = character.data?.character_version ?? ''; |
| 3141 | + result.charDepthPrompt = baseChatReplace(character.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2); | |
| 3120 | 3142 | |
| 3121 | 3143 | if (selected_group) { |
| 3122 | 3144 | const groupCards = getGroupCharacterCards(selected_group, Number(this_chid)); |
| @@ -3922,6 +3944,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 3922 | 3944 | mesExamples, |
| 3923 | 3945 | system, |
| 3924 | 3946 | jailbreak, |
| 3947 | + charDepthPrompt, | |
| 3925 | 3948 | } = getCharacterCardFields(); |
| 3926 | 3949 | |
| 3927 | 3950 | if (main_api !== 'openai') { |
| @@ -3944,7 +3967,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 3944 | 3967 | setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth, extension_settings.note.allowWIScan, role); |
| 3945 | 3968 | }); |
| 3946 | 3969 | } else { |
| 3947 | - const depthPromptText = baseChatReplace(characters[this_chid]?.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || ''; | |
| 3970 | + const depthPromptText = charDepthPrompt || ''; | |
| 3948 | 3971 | const depthPromptDepth = characters[this_chid]?.data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default; |
| 3949 | 3972 | const depthPromptRole = getExtensionPromptRoleByName(characters[this_chid]?.data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default); |
| 3950 | 3973 | setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth, extension_settings.note.allowWIScan, depthPromptRole); |
| @@ -17,6 +17,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js'; | ||
| 17 | 17 | import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js'; |
| 18 | 18 | export { MODULE_NAME as NOTE_MODULE_NAME }; |
| 19 | 19 | import { t } from './i18n.js'; |
| 20 | +import { MacrosParser } from './macros.js'; | |
| 20 | 21 | |
| 21 | 22 | const MODULE_NAME = '2_floating_prompt'; // <= Deliberate, for sorting lower than memory |
| 22 | 23 | |
| @@ -576,4 +577,8 @@ export function initAuthorsNote() { | ||
| 576 | 577 | `, |
| 577 | 578 | })); |
| 578 | 579 | eventSource.on(event_types.CHAT_CHANGED, onChatChanged); |
| 580 | + | |
| 581 | + MacrosParser.registerMacro('authorsNote', () => chat_metadata[metadata_keys.prompt] ?? '', t`The contents of the Author's Note`); | |
| 582 | + 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`); | |
| 583 | + MacrosParser.registerMacro('defaultAuthorsNote', () => extension_settings.note.default ?? '', t`The contents of the Default Author's Note`); | |
| 579 | 584 | } |
| @@ -20,7 +20,8 @@ | ||
| 20 | 20 | <li><tt>{{summary}}</tt> – <span data-i18n="help_macros_summary">the latest chat summary generated by the "Summarize" extension (if available).</span></li> |
| 21 | 21 | <li><tt>{{user}}</tt> – <span data-i18n="help_macros_15">your current Persona username</span></li> |
| 22 | 22 | <li><tt>{{char}}</tt> – <span data-i18n="help_macros_16">the Character's name</span></li> |
| 23 | 23 | <li><tt>{{char_versionversion}}</tt> – <span data-i18n="help_macros_17">the Character's version number</span></li> |
| 24 | + <li><tt>{{charDepthPrompt}}</tt> – <span data-i18n="help_macros_charDepthPrompt">the Character's @ Depth Note</span></li> | |
| 24 | 25 | <li><tt>{{group}}</tt> – <span data-i18n="help_macros_18">a comma-separated list of group member names (including muted) or the character name in solo chats. Alias: {{charIfNotGroup}}</span></li> |
| 25 | 26 | <li><tt>{{groupNotMuted}}</tt> – <span data-i18n="help_groupNotMuted">the same as {{group}}, but excludes muted members</span></li> |
| 26 | 27 | <li><tt>{{model}}</tt> – <span data-i18n="help_macros_19">a text generation model name for the currently selected API. </span><b data-i18n="Can be inaccurate!">Can be inaccurate!</b></li> |