Allow setting altering group greetings with extensions. Add ability to add extensions when creating characters.
This commit is contained in:
parent
51f959c06b
commit
ce756bc4f7
|
@ -271,15 +271,18 @@
|
|||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.flexnowrap {
|
||||
.flexnowrap,
|
||||
.flexNoWrap {
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
.alignitemscenter {
|
||||
.alignitemscenter,
|
||||
.alignItemsCenter {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.alignitemsstart {
|
||||
.alignitemsstart,
|
||||
.alignItemsStart {
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
|
|
|
@ -4063,7 +4063,7 @@
|
|||
</div>
|
||||
<div id="firstMessageWrapper" class="flex-container flexFlowColumn flex1">
|
||||
<div id="first_message_div" class="marginBot5 title_restorable">
|
||||
<div class="flex-container alignitemscenter">
|
||||
<div class="flex-container alignitemscenter flex1">
|
||||
<span data-i18n="First message">First message</span>
|
||||
<i class="editor_maximize fa-solid fa-maximize right_menu_button" data-for="firstmessage_textarea" title="Expand the editor"></i>
|
||||
<a href="https://docs.sillytavern.app/usage/core-concepts/characterdesign/#first-message" class="notes-link" target="_blank">
|
||||
|
|
|
@ -400,6 +400,7 @@ export const event_types = {
|
|||
GROUP_MEMBER_DRAFTED: 'group_member_drafted',
|
||||
WORLD_INFO_ACTIVATED: 'world_info_activated',
|
||||
TEXT_COMPLETION_SETTINGS_READY: 'text_completion_settings_ready',
|
||||
CHARACTER_FIRST_MESSAGE_SELECTED: 'character_first_message_selected',
|
||||
};
|
||||
|
||||
export const eventSource = new EventEmitter();
|
||||
|
@ -745,6 +746,7 @@ let create_save = {
|
|||
alternate_greetings: [],
|
||||
depth_prompt_prompt: '',
|
||||
depth_prompt_depth: depth_prompt_depth_default,
|
||||
extensions: {},
|
||||
};
|
||||
|
||||
//animation right menu
|
||||
|
@ -7184,6 +7186,8 @@ async function createOrEditCharacter(e) {
|
|||
formData.append('alternate_greetings', value);
|
||||
}
|
||||
|
||||
formData.append('extensions', JSON.stringify(create_save.extensions));
|
||||
|
||||
await jQuery.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
|
@ -7216,6 +7220,7 @@ async function createOrEditCharacter(e) {
|
|||
{ id: '#character_json_data', callback: () => { } },
|
||||
{ id: '#alternate_greetings_template', callback: value => create_save.alternate_greetings = value, defaultValue: [] },
|
||||
{ id: '#character_world', callback: value => create_save.world = value },
|
||||
{ id: '#_character_extensions_fake', callback: value => create_save.extensions = {} },
|
||||
];
|
||||
|
||||
fields.forEach(field => {
|
||||
|
@ -7336,7 +7341,7 @@ window['SillyTavern'].getContext = function () {
|
|||
chatMetadata: chat_metadata,
|
||||
streamingProcessor,
|
||||
eventSource: eventSource,
|
||||
event_types: event_types,
|
||||
eventTypes: event_types,
|
||||
addOneMessage: addOneMessage,
|
||||
generate: Generate,
|
||||
getTokenCount: getTokenCount,
|
||||
|
@ -7366,6 +7371,12 @@ window['SillyTavern'].getContext = function () {
|
|||
writeExtensionField: writeExtensionField,
|
||||
tags: tags,
|
||||
tagMap: tag_map,
|
||||
menuType: menu_type,
|
||||
createCharacterData: create_save,
|
||||
/**
|
||||
* @deprecated Legacy snake-case naming, compatibility with old extensions
|
||||
*/
|
||||
event_types: event_types,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ export async function getGroupChat(groupId) {
|
|||
continue;
|
||||
}
|
||||
|
||||
const mes = getFirstCharacterMessage(character);
|
||||
const mes = await getFirstCharacterMessage(character);
|
||||
chat.push(mes);
|
||||
addOneMessage(mes);
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ export function getGroupCharacterCards(groupId, characterId) {
|
|||
return { description, personality, scenario, mesExamples };
|
||||
}
|
||||
|
||||
function getFirstCharacterMessage(character) {
|
||||
async function getFirstCharacterMessage(character) {
|
||||
let messageText = character.first_mes;
|
||||
|
||||
// if there are alternate greetings, pick one at random
|
||||
|
@ -383,6 +383,13 @@ function getFirstCharacterMessage(character) {
|
|||
messageText = messageTexts[Math.floor(Math.random() * messageTexts.length)];
|
||||
}
|
||||
|
||||
// Allow extensions to change the first message
|
||||
const eventArgs = { input: messageText, output: '', character: character };
|
||||
await eventSource.emit(event_types.CHARACTER_FIRST_MESSAGE_SELECTED, eventArgs);
|
||||
if (eventArgs.output) {
|
||||
messageText = eventArgs.output;
|
||||
}
|
||||
|
||||
const mes = {};
|
||||
mes['is_user'] = false;
|
||||
mes['is_system'] = false;
|
||||
|
|
|
@ -357,6 +357,16 @@ function charaFormatData(data) {
|
|||
}
|
||||
}
|
||||
|
||||
if (data.extensions) {
|
||||
try {
|
||||
const extensions = JSON.parse(data.extensions);
|
||||
// Deep merge the extensions object
|
||||
_.set(char, 'data.extensions', deepMerge(char.data.extensions, extensions));
|
||||
} catch {
|
||||
console.debug(`Failed to parse extensions JSON: ${data.extensions}`);
|
||||
}
|
||||
}
|
||||
|
||||
return char;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue