mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #3718 from SillyTavern/feat/an-macro
Add macros for Author's Notes
This commit is contained in:
@@ -2746,6 +2746,7 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re
|
|||||||
environment.mesExamplesRaw = fields.mesExamples || '';
|
environment.mesExamplesRaw = fields.mesExamples || '';
|
||||||
environment.charVersion = fields.version || '';
|
environment.charVersion = fields.version || '';
|
||||||
environment.char_version = fields.version || '';
|
environment.char_version = fields.version || '';
|
||||||
|
environment.charDepthPrompt = fields.charDepthPrompt || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must be substituted last so that they're replaced inside {{description}}
|
// 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 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() {
|
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);
|
result.persona = baseChatReplace(power_user.persona_description?.trim(), name1, name2);
|
||||||
|
|
||||||
const character = characters[this_chid];
|
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.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.jailbreak = power_user.prefer_character_jailbreak ? baseChatReplace(character.data?.post_history_instructions?.trim(), name1, name2) : '';
|
||||||
result.version = character.data?.character_version ?? '';
|
result.version = character.data?.character_version ?? '';
|
||||||
|
result.charDepthPrompt = baseChatReplace(character.data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2);
|
||||||
|
|
||||||
if (selected_group) {
|
if (selected_group) {
|
||||||
const groupCards = getGroupCharacterCards(selected_group, Number(this_chid));
|
const groupCards = getGroupCharacterCards(selected_group, Number(this_chid));
|
||||||
@@ -3922,6 +3944,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
mesExamples,
|
mesExamples,
|
||||||
system,
|
system,
|
||||||
jailbreak,
|
jailbreak,
|
||||||
|
charDepthPrompt,
|
||||||
} = getCharacterCardFields();
|
} = getCharacterCardFields();
|
||||||
|
|
||||||
if (main_api !== 'openai') {
|
if (main_api !== 'openai') {
|
||||||
@@ -3944,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);
|
setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth, extension_settings.note.allowWIScan, role);
|
||||||
});
|
});
|
||||||
} else {
|
} 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 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);
|
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);
|
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';
|
|||||||
import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js';
|
import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js';
|
||||||
export { MODULE_NAME as NOTE_MODULE_NAME };
|
export { MODULE_NAME as NOTE_MODULE_NAME };
|
||||||
import { t } from './i18n.js';
|
import { t } from './i18n.js';
|
||||||
|
import { MacrosParser } from './macros.js';
|
||||||
|
|
||||||
const MODULE_NAME = '2_floating_prompt'; // <= Deliberate, for sorting lower than memory
|
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);
|
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`);
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,8 @@
|
|||||||
<li><tt>{{summary}}</tt> – <span data-i18n="help_macros_summary">the latest chat summary generated by the "Summarize" extension (if available).</span></li>
|
<li><tt>{{summary}}</tt> – <span data-i18n="help_macros_summary">the latest chat summary generated by the "Summarize" extension (if available).</span></li>
|
||||||
<li><tt>{{user}}</tt> – <span data-i18n="help_macros_15">your current Persona username</span></li>
|
<li><tt>{{user}}</tt> – <span data-i18n="help_macros_15">your current Persona username</span></li>
|
||||||
<li><tt>{{char}}</tt> – <span data-i18n="help_macros_16">the Character's name</span></li>
|
<li><tt>{{char}}</tt> – <span data-i18n="help_macros_16">the Character's name</span></li>
|
||||||
<li><tt>{{char_version}}</tt> – <span data-i18n="help_macros_17">the Character's version number</span></li>
|
<li><tt>{{version}}</tt> – <span data-i18n="help_macros_17">the Character's version number</span></li>
|
||||||
|
<li><tt>{{charDepthPrompt}}</tt> – <span data-i18n="help_macros_charDepthPrompt">the Character's @ Depth Note</span></li>
|
||||||
<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>
|
<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>
|
||||||
<li><tt>{{groupNotMuted}}</tt> – <span data-i18n="help_groupNotMuted">the same as {{group}}, but excludes muted members</span></li>
|
<li><tt>{{groupNotMuted}}</tt> – <span data-i18n="help_groupNotMuted">the same as {{group}}, but excludes muted members</span></li>
|
||||||
<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>
|
<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>
|
||||||
|
Reference in New Issue
Block a user