Skip to content

Commit

Permalink
Rebuild Amalgamation Groupcards
Browse files Browse the repository at this point in the history
"The previous version is kinda broken visually (significant). Therefore, I manually copied a few functions into this version. I also incorporated my code refactoring for card amalgamation."
  • Loading branch information
ntvm committed Oct 29, 2023
1 parent 29520bc commit 7d87a13
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 44 deletions.
56 changes: 32 additions & 24 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3613,7 +3613,12 @@ <h2></h2>

<div class="inline-drawer wide100p flexFlowColumn">
<div id="groupControlsToggle" class="inline-drawer-toggle inline-drawer-header">
<span data-i18n="Group Controls">Group Controls</span>
<span>
<span data-i18n="Group Controls">Group Controls</span>
<a href="https://docs.sillytavern.app/usage/core-concepts/groupchats/" class="notes-link" target="_blank">
<span class="note-link-span">?</span>
</a>
</span>
<div class="fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>
</div>
<div class="inline-drawer-content">
Expand All @@ -3629,7 +3634,7 @@ <h2></h2>
</div>
<div id="groupTagList" class="tags paddingTopBot5"></div>
</div>
<div id="rm_group_top_bar" class="flex-container alignitemscenter spaceBetween width100p">
<div id="rm_group_top_bar" class="flex-container alignitemscenter spaceBetween width100p fontsize80p">
<div>
<label class="add_avatar avatar flex-container justifyCenter" for="group_avatar_button" title="Click to select a new avatar for this group" data-i18n="[title]Click to select a new avatar for this group">
<div id="group_avatar_preview">
Expand All @@ -3640,32 +3645,24 @@ <h2></h2>
<input hidden type="file" id="group_avatar_button" name="avatar" accept="image/png, image/jpeg, image/jpg, image/gif, image/bmp">
</label>
</div>
<div name="GroupStragegyAndOrder" id="rm_group_buttons" class="fontsize80p flex-container paddingLeftRight5 flex2">
<div class="">
<div name="GroupStragegyAndOrder" id="rm_group_buttons" class="flex-container paddingLeftRight5 flex2">
<div class="flex1 flexGap5">
<div class="flex-container flexnowrap width100p whitespacenowrap">
<span data-i18n="Group reply strategy">Group reply strategy</span>
<a href="https://docs.sillytavern.app/usage/core-concepts/groupchats/" class="notes-link" target="_blank">
<span class="note-link-span">?</span>
</a>
</div>
<label class="checkbox_label flexnowrap whitespacenowrap">
<input type="radio" name="rm_group_activation_strategy" value="0" />
<span data-i18n="Natural order">Natural order</span>
</label>
<label class="checkbox_label flexnowrap whitespacenowrap">
<input type="radio" name="rm_group_activation_strategy" value="1" />
<span data-i18n="List order">List order</span>
</label>
<select id="rm_group_activation_strategy">
<option value="0" data-i18n="Natural order">Natural order</option>
<option value="1" data-i18n="List order">List order</option>
</select>
</div>
<div class="">
<label class="checkbox_label whitespacenowrap">
<input id="rm_group_allow_self_responses" type="checkbox" />
<span data-i18n="Allow self responses">Allow self responses</span>
</label>
<label id="rm_group_automode_label" class="checkbox_label whitespacenowrap">
<input id="rm_group_automode" type="checkbox" />
<span data-i18n="Auto Mode">Auto Mode</span>
</label>
<div class="flex1 flexGap5">
<div class="flex-container flexnowrap width100p whitespacenowrap">
<span data-i18n="Group generation handling mode">Group generation handling mode</span>
</div>
<select id="rm_group_generation_mode">
<option value="0" data-i18n="Swap character cards">Swap character cards</option>
<option value="1" data-i18n="Join character cards">Join character cards</option>
</select>
</div>
</div>
<div id="GroupFavDelOkBack" class="flex-container flexGap5 spaceEvenly flex1">
Expand All @@ -3676,6 +3673,17 @@ <h2></h2>
<div id="rm_group_submit" class="heightFitContent margin0 menu_button fa-solid fa-check" title="Create" data-i18n="[title]Create"></div>
<div id="rm_group_restore_avatar" class="heightFitContent margin0 menu_button fa-solid fa-images" title="Restore collage avatar" data-i18n="[title]Restore collage avatar"></div>
<div id="rm_group_delete" class="heightFitContent margin0 menu_button fa-solid fa-trash-can" title="Delete" data-i18n="[title]Delete"></div>

<div class="flex1">
<label class="checkbox_label whitespacenowrap">
<input id="rm_group_allow_self_responses" type="checkbox" />
<span data-i18n="Allow self responses">Allow self responses</span>
</label>
<label id="rm_group_automode_label" class="checkbox_label whitespacenowrap">
<input id="rm_group_automode" type="checkbox" />
<span data-i18n="Auto Mode">Auto Mode</span>
</label>
</div>
</div>

</div>
Expand Down
53 changes: 43 additions & 10 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import {
importGroupChat,
getGroupBlock,
getGroupChatNames,
getGroupCharacterCards,
getGroupDepthPrompts,
} from "./scripts/group-chats.js";

import {
Expand Down Expand Up @@ -600,7 +602,7 @@ function getCurrentChatId() {
}

const talkativeness_default = 0.5;
const depth_prompt_depth_default = 4;
export const depth_prompt_depth_default = 4;
const per_page_default = 50;

var is_advanced_char_open = false;
Expand Down Expand Up @@ -2040,7 +2042,7 @@ function getExtensionPrompt(position = 0, depth = undefined, separator = "\n") {
return extension_prompt;
}

function baseChatReplace(value, name1, name2) {
export function baseChatReplace(value, name1, name2) {
if (value !== undefined && value.length > 0) {
value = substituteParams(value, name1, name2);

Expand Down Expand Up @@ -2546,21 +2548,40 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
const scenarioText = chat_metadata['scenario'] || characters[this_chid].scenario;
let charDescription = baseChatReplace(characters[this_chid].description.trim(), name1, name2);
let charPersonality = baseChatReplace(characters[this_chid].personality.trim(), name1, name2);
let personaDescription = baseChatReplace(power_user.persona_description.trim(), name1, name2);
let Scenario = baseChatReplace(scenarioText.trim(), name1, name2);
let scenario = baseChatReplace(scenarioText.trim(), name1, name2);
let mesExamples = baseChatReplace(characters[this_chid].mes_example.trim(), name1, name2);
let systemPrompt = power_user.prefer_character_prompt ? baseChatReplace(characters[this_chid].data?.system_prompt?.trim(), name1, name2) : '';
let jailbreakPrompt = power_user.prefer_character_jailbreak ? baseChatReplace(characters[this_chid].data?.post_history_instructions?.trim(), name1, name2) : '';

let personaDescription = baseChatReplace(power_user.persona_description.trim(), name1, name2);
if (isInstruct) {
systemPrompt = power_user.prefer_character_prompt && systemPrompt ? systemPrompt : baseChatReplace(power_user.instruct.system_prompt, name1, name2);
systemPrompt = formatInstructModeSystemPrompt(substituteParams(systemPrompt, name1, name2, power_user.instruct.system_prompt));
}

if (selected_group) {
const groupCards = getGroupCharacterCards(selected_group);

if (groupCards) {
charDescription = groupCards.description;
charPersonality = groupCards.personality;
scenario = groupCards.scenario;
mesExamples = groupCards.mesExample;
}
}

// Depth prompt (character-specific A/N)
const depthPromptText = baseChatReplace(characters[this_chid].data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || '';
const depthPromptDepth = characters[this_chid].data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth);
removeDepthPrompts();
const groupDepthPrompts = getGroupDepthPrompts(selected_group);

if (selected_group && Array.isArray(groupDepthPrompts) && groupDepthPrompts.length > 0) {
groupDepthPrompts.forEach((value, index) => {
setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth);
});
} else {
const depthPromptText = baseChatReplace(characters[this_chid].data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || '';
const depthPromptDepth = characters[this_chid].data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth);
}

// Parse example messages
if (!mesExamples.startsWith('<START>')) {
Expand Down Expand Up @@ -2689,7 +2710,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
description: charDescription,
personality: charPersonality,
persona: personaDescription,
scenario: Scenario,
scenario: scenario,
system: isInstruct ? systemPrompt : '',
char: name2,
user: name1,
Expand Down Expand Up @@ -3119,7 +3140,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
name2: name2,
charDescription: charDescription,
charPersonality: charPersonality,
Scenario: Scenario,
Scenario: scenario,
worldInfoBefore: worldInfoBefore,
worldInfoAfter: worldInfoAfter,
extensionPrompts: extension_prompts,
Expand Down Expand Up @@ -5758,6 +5779,18 @@ export function setExtensionPrompt(key, value, position, depth) {
extension_prompts[key] = { value: String(value), position: Number(position), depth: Number(depth) };
}

/**
* Removes all char A/N prompt injections from the chat.
* To clean up when switching from groups to solo and vice versa.
*/
export function removeDepthPrompts() {
for (const key of Object.keys(extension_prompts)) {
if (key.startsWith('DEPTH_PROMPT')) {
delete extension_prompts[key];
}
}
}

/**
* Adds or updates the metadata for the currently active chat.
* @param {Object} newValues An object with collection of new values to be added into the metadata.
Expand Down

0 comments on commit 7d87a13

Please sign in to comment.