Smudge groups depth prompts in Join mode.

This commit is contained in:
Cohee
2023-10-26 00:39:11 +03:00
parent 8dcfe57888
commit 5cdc3d1d18
3 changed files with 82 additions and 8 deletions

View File

@@ -67,6 +67,7 @@ import {
isChatSaving,
setExternalAbortController,
baseChatReplace,
depth_prompt_depth_default,
} from "../script.js";
import { appendTagToList, createTagMapFromList, getTagsList, applyTagsOnCharacterSelect, tag_map, printTagFilters } from './tags.js';
import { FILTER_TYPES, FilterHelper } from './filters.js';
@@ -199,6 +200,53 @@ export async function getGroupChat(groupId) {
eventSource.emit(event_types.CHAT_CHANGED, getCurrentChatId());
}
/**
* Gets depth prompts for group members.
* @param {string} groupId Group ID
* @returns {{depth: number, text: string}[]} Array of depth prompts
*/
export function getGroupDepthPrompts(groupId) {
if (!groupId) {
return [];
}
console.debug('getGroupDepthPrompts entered for group: ', groupId);
const group = groups.find(x => x.id === groupId);
if (!group || !Array.isArray(group.members) || !group.members.length) {
return [];
}
if (group.generation_mode === group_generation_mode.SWAP) {
return [];
}
const depthPrompts = [];
for (const member of group.members) {
if (group.disabled_members.includes(member)) {
console.debug(`Skipping disabled group member: ${member}`);
continue;
}
const character = characters.find(x => x.avatar === member);
if (!character) {
console.debug(`Skipping missing member: ${member}`);
continue;
}
const depthPromptText = baseChatReplace(character.data?.extensions?.depth_prompt?.prompt?.trim(), name1, character.name) || '';
const depthPromptDepth = character.data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
if (depthPromptText) {
depthPrompts.push({ text: depthPromptText, depth: depthPromptDepth });
}
}
return depthPrompts;
}
/**
* Combines group members info a single string. Only for groups with generation mode set to APPEND.
* @param {string} groupId Group ID