Merge pull request #3718 from SillyTavern/feat/an-macro Add macros for Author's Notes

283edd94b9c3f0c6ef3de05cd250683fce9a9a19

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

Signed
3 files changed, +33 -4Ignore whitespace
public/script.js+26 -3
@@ -2746,6 +2746,7 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re
27462746 environment.mesExamplesRaw = fields.mesExamples || '';
27472747 environment.charVersion = fields.version || '';
27482748 environment.char_version = fields.version || '';
2749+ environment.charDepthPrompt = fields.charDepthPrompt || '';
27492750 }
27502751
27512752 // Must be substituted last so that they're replaced inside {{description}}
@@ -3097,10 +3098,30 @@ export function baseChatReplace(value, name1, name2) {
30973098
30983099/**
30993100 * 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
31013112 */
31023113export 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+ };
31043125 result.persona = baseChatReplace(power_user.persona_description?.trim(), name1, name2);
31053126
31063127 const character = characters[this_chid];
@@ -3117,6 +3138,7 @@ export function getCharacterCardFields() {
31173138 result.system = power_user.prefer_character_prompt ? baseChatReplace(character.data?.system_prompt?.trim(), name1, name2) : '';
31183139 result.jailbreak = power_user.prefer_character_jailbreak ? baseChatReplace(character.data?.post_history_instructions?.trim(), name1, name2) : '';
31193140 result.version = character.data?.character_version ?? '';
3141+ result.charDepthPrompt = baseChatReplace(character.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2);
31203142
31213143 if (selected_group) {
31223144 const groupCards = getGroupCharacterCards(selected_group, Number(this_chid));
@@ -3922,6 +3944,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
39223944 mesExamples,
39233945 system,
39243946 jailbreak,
3947+ charDepthPrompt,
39253948 } = getCharacterCardFields();
39263949
39273950 if (main_api !== 'openai') {
@@ -3944,7 +3967,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
39443967 setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth, extension_settings.note.allowWIScan, role);
39453968 });
39463969 } else {
3947- const depthPromptText = baseChatReplace(characters[this_chid]?.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || '';
3970+ const depthPromptText = charDepthPrompt || '';
39483971 const depthPromptDepth = characters[this_chid]?.data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
39493972 const depthPromptRole = getExtensionPromptRoleByName(characters[this_chid]?.data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default);
39503973 setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth, extension_settings.note.allowWIScan, depthPromptRole);
public/scripts/authors-note.js+5 -0
@@ -17,6 +17,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js';
1717import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js';
1818export { MODULE_NAME as NOTE_MODULE_NAME };
1919import { t } from './i18n.js';
20+import { MacrosParser } from './macros.js';
2021
2122const MODULE_NAME = '2_floating_prompt'; // <= Deliberate, for sorting lower than memory
2223
@@ -576,4 +577,8 @@ export function initAuthorsNote() {
576577 `,
577578 }));
578579 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`);
579584}
public/scripts/templates/macros.html+2 -1
@@ -20,7 +20,8 @@
2020 <li><tt>&lcub;&lcub;summary&rcub;&rcub;</tt> – <span data-i18n="help_macros_summary">the latest chat summary generated by the "Summarize" extension (if available).</span></li>
2121 <li><tt>&lcub;&lcub;user&rcub;&rcub;</tt> – <span data-i18n="help_macros_15">your current Persona username</span></li>
2222 <li><tt>&lcub;&lcub;char&rcub;&rcub;</tt> – <span data-i18n="help_macros_16">the Character's name</span></li>
2323 <li><tt>&lcub;&lcub;char_versionversion&rcub;&rcub;</tt> – <span data-i18n="help_macros_17">the Character's version number</span></li>
24+ <li><tt>&lcub;&lcub;charDepthPrompt&rcub;&rcub;</tt> – <span data-i18n="help_macros_charDepthPrompt">the Character's @ Depth Note</span></li>
2425 <li><tt>&lcub;&lcub;group&rcub;&rcub;</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: &lcub;&lcub;charIfNotGroup&rcub;&rcub;</span></li>
2526 <li><tt>&lcub;&lcub;groupNotMuted&rcub;&rcub;</tt> – <span data-i18n="help_groupNotMuted">the same as &lcub;&lcub;group&rcub;&rcub;, but excludes muted members</span></li>
2627 <li><tt>&lcub;&lcub;model&rcub;&rcub;</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>