mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add /sendas command
This commit is contained in:
@ -1990,7 +1990,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
// Add quiet generation prompt at depth 0
|
// Add quiet generation prompt at depth 0
|
||||||
if (quiet_prompt && quiet_prompt.length) {
|
if (quiet_prompt && quiet_prompt.length) {
|
||||||
const name = is_pygmalion ? 'You' : name1;
|
const name = is_pygmalion ? 'You' : name1;
|
||||||
const quietAppend = isInstruct ? formatInstructModeChat(name, quiet_prompt, false, true) : `\n${name}: ${quiet_prompt}`;
|
const quietAppend = isInstruct ? formatInstructModeChat(name, quiet_prompt, false, true, false) : `\n${name}: ${quiet_prompt}`;
|
||||||
mesSendString += quietAppend;
|
mesSendString += quietAppend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2362,14 +2362,14 @@ function getBiasStrings(textareaText) {
|
|||||||
|
|
||||||
function formatMessageHistoryItem(chatItem, isInstruct) {
|
function formatMessageHistoryItem(chatItem, isInstruct) {
|
||||||
const isNarratorType = chatItem?.extra?.type === system_message_types.NARRATOR;
|
const isNarratorType = chatItem?.extra?.type === system_message_types.NARRATOR;
|
||||||
const characterName = selected_group ? chatItem.name : name2;
|
const characterName = (selected_group || chatItem.force_avatar) ? chatItem.name : name2;
|
||||||
const itemName = chatItem.is_user ? chatItem['name'] : characterName;
|
const itemName = chatItem.is_user ? chatItem['name'] : characterName;
|
||||||
const shouldPrependName = (chatItem.is_name || selected_group) && !isNarratorType;
|
const shouldPrependName = (chatItem.is_name || chatItem.force_avatar || selected_group) && !isNarratorType;
|
||||||
|
|
||||||
let textResult = shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`;
|
let textResult = shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`;
|
||||||
|
|
||||||
if (isInstruct) {
|
if (isInstruct) {
|
||||||
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType);
|
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace bias markup
|
// replace bias markup
|
||||||
|
@ -171,8 +171,8 @@ function setOpenAIMessages(chat) {
|
|||||||
role = 'system';
|
role = 'system';
|
||||||
}
|
}
|
||||||
|
|
||||||
// for groups - prepend a character's name
|
// for groups or sendas command - prepend a character's name
|
||||||
if (selected_group) {
|
if (selected_group || chat[j].force_avatar) {
|
||||||
content = `${chat[j].name}: ${content}`;
|
content = `${chat[j].name}: ${content}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,8 +640,8 @@ function loadInstructMode() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatInstructModeChat(name, mes, isUser, isNarrator) {
|
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar) {
|
||||||
const includeNames = isNarrator ? false : power_user.instruct.names || !!selected_group;
|
const includeNames = isNarrator ? false : (power_user.instruct.names || !!selected_group || !!forceAvatar);
|
||||||
const sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence;
|
const sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence;
|
||||||
const separator = power_user.instruct.wrap ? '\n' : '';
|
const separator = power_user.instruct.wrap ? '\n' : '';
|
||||||
const separatorSequence = power_user.instruct.separator_sequence && !isUser
|
const separatorSequence = power_user.instruct.separator_sequence && !isUser
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
addOneMessage,
|
addOneMessage,
|
||||||
|
characters,
|
||||||
chat,
|
chat,
|
||||||
chat_metadata,
|
chat_metadata,
|
||||||
|
default_avatar,
|
||||||
|
getThumbnailUrl,
|
||||||
saveChatConditional,
|
saveChatConditional,
|
||||||
sendSystemMessage,
|
sendSystemMessage,
|
||||||
system_avatar,
|
system_avatar,
|
||||||
@ -85,7 +88,8 @@ const registerSlashCommand = parser.addCommand.bind(parser);
|
|||||||
const getSlashCommandsHelp = parser.getHelpString.bind(parser);
|
const getSlashCommandsHelp = parser.getHelpString.bind(parser);
|
||||||
|
|
||||||
parser.addCommand('help', helpCommandCallback, ['?'], ' – displays this help message', true, true);
|
parser.addCommand('help', helpCommandCallback, ['?'], ' – displays this help message', true, true);
|
||||||
parser.addCommand('bg', setBackgroundCallback, ['background'], '<span class="monospace">(filename)</span> – sets a background according to filename, partial names allowed, will set the first one alphebetically if multiple files begin with the provided argument string', false, true);
|
parser.addCommand('bg', setBackgroundCallback, ['background'], '<span class="monospace">(filename)</span> – sets a background according to filename, partial names allowed, will set the first one alphabetically if multiple files begin with the provided argument string', false, true);
|
||||||
|
parser.addCommand('sendas', sendMessageAs, [], ` – sends message as a specific character.<br>Example:<br><pre><code>/sendas Chloe\nHello, guys!</code></pre>will send "Hello, guys!" from "Chloe".<br>Uses character avatar if it exists in the characters list.`, true, true);
|
||||||
parser.addCommand('sys', sendNarratorMessage, [], '<span class="monospace">(text)</span> – sends message as a system narrator', false, true);
|
parser.addCommand('sys', sendNarratorMessage, [], '<span class="monospace">(text)</span> – sends message as a system narrator', false, true);
|
||||||
parser.addCommand('sysname', setNarratorName, [], '<span class="monospace">(name)</span> – sets a name for future system narrator messages in this chat (display only). Default: System. Leave empty to reset.', true, true);
|
parser.addCommand('sysname', setNarratorName, [], '<span class="monospace">(name)</span> – sets a name for future system narrator messages in this chat (display only). Default: System. Leave empty to reset.', true, true);
|
||||||
|
|
||||||
@ -99,6 +103,49 @@ function setNarratorName(_, text) {
|
|||||||
saveChatConditional();
|
saveChatConditional();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendMessageAs(_, text) {
|
||||||
|
if (!text) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = text.split('\n');
|
||||||
|
|
||||||
|
if (parts.length <= 1) {
|
||||||
|
toastr.warning('Both character name and message are required. Separate them with a new line.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = parts.shift().trim();
|
||||||
|
const mesText = parts.join('\n').trim();
|
||||||
|
|
||||||
|
const character = characters.find(x => x.name === name);
|
||||||
|
let force_avatar, original_avatar;
|
||||||
|
|
||||||
|
if (character && character.avatar !== 'none') {
|
||||||
|
force_avatar = getThumbnailUrl('avatar', character.avatar);
|
||||||
|
original_avatar = character.avatar;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
force_avatar = default_avatar;
|
||||||
|
original_avatar = default_avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = {
|
||||||
|
name: name,
|
||||||
|
is_user: false,
|
||||||
|
is_name: true,
|
||||||
|
is_system: false,
|
||||||
|
send_date: humanizedDateTime(),
|
||||||
|
mes: mesText,
|
||||||
|
force_avatar: force_avatar,
|
||||||
|
original_avatar: original_avatar,
|
||||||
|
};
|
||||||
|
|
||||||
|
chat.push(message);
|
||||||
|
addOneMessage(message);
|
||||||
|
saveChatConditional();
|
||||||
|
}
|
||||||
|
|
||||||
function sendNarratorMessage(_, text) {
|
function sendNarratorMessage(_, text) {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user