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 -4Showing whitespace changes
public/script.js+26 -3
@@ -2746,6 +2746,7 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re
2746 environment.mesExamplesRaw = fields.mesExamples || '';2746 environment.mesExamplesRaw = fields.mesExamples || '';
2747 environment.charVersion = fields.version || '';2747 environment.charVersion = fields.version || '';
2748 environment.char_version = fields.version || '';2748 environment.char_version = fields.version || '';
2749 environment.charDepthPrompt = fields.charDepthPrompt || '';
2749 }2750 }
27502751
2751 // Must be substituted last so that they're replaced inside {{description}}2752 // Must be substituted last so that they're replaced inside {{description}}
@@ -3097,10 +3098,30 @@ export function baseChatReplace(value, name1, name2) {
30973098
3098/**3099/**
3099 * Returns the character card fields for the current character.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 */
3102export function getCharacterCardFields() {3113export 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 result.persona = baseChatReplace(power_user.persona_description?.trim(), name1, name2);3125 result.persona = baseChatReplace(power_user.persona_description?.trim(), name1, name2);
31053126
3106 const character = characters[this_chid];3127 const character = characters[this_chid];
@@ -3117,6 +3138,7 @@ export function getCharacterCardFields() {
3117 result.system = power_user.prefer_character_prompt ? baseChatReplace(character.data?.system_prompt?.trim(), name1, name2) : '';3138 result.system = power_user.prefer_character_prompt ? baseChatReplace(character.data?.system_prompt?.trim(), name1, name2) : '';
3118 result.jailbreak = power_user.prefer_character_jailbreak ? baseChatReplace(character.data?.post_history_instructions?.trim(), name1, name2) : '';3139 result.jailbreak = power_user.prefer_character_jailbreak ? baseChatReplace(character.data?.post_history_instructions?.trim(), name1, name2) : '';
3119 result.version = character.data?.character_version ?? '';3140 result.version = character.data?.character_version ?? '';
3141 result.charDepthPrompt = baseChatReplace(character.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2);
31203142
3121 if (selected_group) {3143 if (selected_group) {
3122 const groupCards = getGroupCharacterCards(selected_group, Number(this_chid));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 mesExamples,3944 mesExamples,
3923 system,3945 system,
3924 jailbreak,3946 jailbreak,
3947 charDepthPrompt,
3925 } = getCharacterCardFields();3948 } = getCharacterCardFields();
39263949
3927 if (main_api !== 'openai') {3950 if (main_api !== 'openai') {
@@ -3944,7 +3967,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
3944 setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth, extension_settings.note.allowWIScan, role);3967 setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth, extension_settings.note.allowWIScan, role);
3945 });3968 });
3946 } else {3969 } else {
3947 const depthPromptText = baseChatReplace(characters[this_chid]?.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || '';3970 const depthPromptText = charDepthPrompt || '';
3948 const depthPromptDepth = characters[this_chid]?.data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;3971 const depthPromptDepth = characters[this_chid]?.data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
3949 const depthPromptRole = getExtensionPromptRoleByName(characters[this_chid]?.data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default);3972 const depthPromptRole = getExtensionPromptRoleByName(characters[this_chid]?.data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default);
3950 setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth, extension_settings.note.allowWIScan, depthPromptRole);3973 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';
17import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js';17import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js';
18export { MODULE_NAME as NOTE_MODULE_NAME };18export { MODULE_NAME as NOTE_MODULE_NAME };
19import { t } from './i18n.js';19import { t } from './i18n.js';
20import { MacrosParser } from './macros.js';
2021
21const MODULE_NAME = '2_floating_prompt'; // <= Deliberate, for sorting lower than memory22const MODULE_NAME = '2_floating_prompt'; // <= Deliberate, for sorting lower than memory
2223
@@ -576,4 +577,8 @@ export function initAuthorsNote() {
576 `,577 `,
577 }));578 }));
578 eventSource.on(event_types.CHAT_CHANGED, onChatChanged);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}
public/scripts/templates/macros.html+2 -1
@@ -20,7 +20,8 @@
20 <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>20 <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>
21 <li><tt>&lcub;&lcub;user&rcub;&rcub;</tt> – <span data-i18n="help_macros_15">your current Persona username</span></li>21 <li><tt>&lcub;&lcub;user&rcub;&rcub;</tt> – <span data-i18n="help_macros_15">your current Persona username</span></li>
22 <li><tt>&lcub;&lcub;char&rcub;&rcub;</tt> – <span data-i18n="help_macros_16">the Character's name</span></li>22 <li><tt>&lcub;&lcub;char&rcub;&rcub;</tt> – <span data-i18n="help_macros_16">the Character's name</span></li>
23 <li><tt>&lcub;&lcub;char_version&rcub;&rcub;</tt> – <span data-i18n="help_macros_17">the Character's version number</span></li>23 <li><tt>&lcub;&lcub;version&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>
24 <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>25 <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>
25 <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>26 <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>
26 <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>27 <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>