mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' of https://github.com/Cohee1207/SillyTavern into staging
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
<input id="sd_expand" type="checkbox" />
|
||||
Auto-enhance prompts
|
||||
</label>
|
||||
<small>
|
||||
This option uses an additional GPT-2 text generation model to add more details to the prompt generated by the main API.
|
||||
Works best for SDXL image models. May not work well with other models, it is recommended to manually edit prompts in this case.
|
||||
</small>
|
||||
<label for="sd_source">Source</label>
|
||||
<select id="sd_source">
|
||||
<option value="extras">Extras API (local / remote)</option>
|
||||
|
@@ -66,6 +66,8 @@ import {
|
||||
system_avatar,
|
||||
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';
|
||||
@@ -101,6 +103,11 @@ export const group_activation_strategy = {
|
||||
LIST: 1,
|
||||
};
|
||||
|
||||
export const group_generation_mode = {
|
||||
SWAP: 0,
|
||||
APPEND: 1,
|
||||
}
|
||||
|
||||
export const groupCandidatesFilter = new FilterHelper(debounce(printGroupCandidates, 100));
|
||||
const groupAutoModeInterval = setInterval(groupChatAutoModeWorker, 5000);
|
||||
const saveGroupDebounced = debounce(async (group, reload) => await _save(group, reload), 500);
|
||||
@@ -193,6 +200,104 @@ export async function getGroupChat(groupId) {
|
||||
eventSource.emit(event_types.CHAT_CHANGED, getCurrentChatId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets depth prompts for group members.
|
||||
* @param {string} groupId Group ID
|
||||
* @param {number} characterId Current Character ID
|
||||
* @returns {{depth: number, text: string}[]} Array of depth prompts
|
||||
*/
|
||||
export function getGroupDepthPrompts(groupId, characterId) {
|
||||
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) {
|
||||
const index = characters.findIndex(x => x.avatar === member);
|
||||
const character = characters[index];
|
||||
|
||||
if (index === -1 || !character) {
|
||||
console.debug(`Skipping missing member: ${member}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (group.disabled_members.includes(member) && characterId !== index) {
|
||||
console.debug(`Skipping disabled group 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
|
||||
* @param {number} characterId Current Character ID
|
||||
* @returns {{description: string, personality: string, scenario: string, mesExample: string}} Group character cards combined
|
||||
*/
|
||||
export function getGroupCharacterCards(groupId, characterId) {
|
||||
console.debug('getGroupCharacterCards entered for group: ', groupId);
|
||||
const group = groups.find(x => x.id === groupId);
|
||||
|
||||
if (!group || group?.generation_mode !== group_generation_mode.APPEND || !Array.isArray(group.members) || !group.members.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const scenarioOverride = chat_metadata['scenario'];
|
||||
|
||||
let descriptions = [];
|
||||
let personalities = [];
|
||||
let scenarios = [];
|
||||
let mesExamples = [];
|
||||
|
||||
for (const member of group.members) {
|
||||
const index = characters.findIndex(x => x.avatar === member);
|
||||
const character = characters[index];
|
||||
|
||||
if (index === -1 || !character) {
|
||||
console.debug(`Skipping missing member: ${member}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (group.disabled_members.includes(member) && characterId !== index) {
|
||||
console.debug(`Skipping disabled group member: ${member}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
descriptions.push(baseChatReplace(character.description.trim(), name1, character.name));
|
||||
personalities.push(baseChatReplace(character.personality.trim(), name1, character.name));
|
||||
scenarios.push(baseChatReplace(character.scenario.trim(), name1, character.name));
|
||||
mesExamples.push(baseChatReplace(character.mes_example.trim(), name1, character.name));
|
||||
}
|
||||
|
||||
const description = descriptions.join('\n');
|
||||
const personality = personalities.join('\n');
|
||||
const scenario = scenarioOverride?.trim() || scenarios.join('\n');
|
||||
const mesExample = mesExamples.join('\n');
|
||||
|
||||
return { description, personality, scenario, mesExample };
|
||||
}
|
||||
|
||||
function getFirstCharacterMessage(character) {
|
||||
let messageText = character.first_mes;
|
||||
|
||||
@@ -922,6 +1027,14 @@ async function onGroupActivationStrategyInput(e) {
|
||||
}
|
||||
}
|
||||
|
||||
async function onGroupGenerationModeInput(e) {
|
||||
if (openGroupId) {
|
||||
let _thisGroup = groups.find((x) => x.id == openGroupId);
|
||||
_thisGroup.generation_mode = Number(e.target.value);
|
||||
await editGroup(openGroupId, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
async function onGroupNameInput() {
|
||||
if (openGroupId) {
|
||||
let _thisGroup = groups.find((x) => x.id == openGroupId);
|
||||
@@ -1085,12 +1198,16 @@ function select_group_chats(groupId, skipAnimation) {
|
||||
const group = openGroupId && groups.find((x) => x.id == openGroupId);
|
||||
const groupName = group?.name ?? "";
|
||||
const replyStrategy = Number(group?.activation_strategy ?? group_activation_strategy.NATURAL);
|
||||
const generationMode = Number(group?.generation_mode ?? group_generation_mode.SWAP);
|
||||
|
||||
setMenuType(!!group ? 'group_edit' : 'group_create');
|
||||
$("#group_avatar_preview").empty().append(getGroupAvatar(group));
|
||||
$("#rm_group_restore_avatar").toggle(!!group && isValidImageUrl(group.avatar_url));
|
||||
$("#rm_group_filter").val("").trigger("input");
|
||||
$(`input[name="rm_group_activation_strategy"][value="${replyStrategy}"]`).prop('checked', true);
|
||||
$("#rm_group_activation_strategy").val(replyStrategy);
|
||||
$(`#rm_group_activation_strategy option[value="${replyStrategy}"]`).prop('selected', true);
|
||||
$("#rm_group_generation_mode").val(generationMode);
|
||||
$(`#rm_group_generation_mode option[value="${generationMode}"]`).prop('selected', true);
|
||||
$("#rm_group_chat_name").val(groupName);
|
||||
|
||||
if (!skipAnimation) {
|
||||
@@ -1311,8 +1428,9 @@ function filterGroupMembers() {
|
||||
|
||||
async function createGroup() {
|
||||
let name = $("#rm_group_chat_name").val();
|
||||
let allow_self_responses = !!$("#rm_group_allow_self_responses").prop("checked");
|
||||
let activation_strategy = $('input[name="rm_group_activation_strategy"]:checked').val() ?? group_activation_strategy.NATURAL;
|
||||
let allowSelfResponses = !!$("#rm_group_allow_self_responses").prop("checked");
|
||||
let activationStrategy = Number($('#rm_group_activation_strategy').find(':selected').val()) ?? group_activation_strategy.NATURAL;
|
||||
let generationMode = Number($('#rm_group_generation_mode').find(':selected').val()) ?? group_generation_mode.SWAP;
|
||||
const members = newGroupMembers;
|
||||
const memberNames = characters.filter(x => members.includes(x.avatar)).map(x => x.name).join(", ");
|
||||
|
||||
@@ -1332,8 +1450,9 @@ async function createGroup() {
|
||||
name: name,
|
||||
members: members,
|
||||
avatar_url: isValidImageUrl(avatar_url) ? avatar_url : default_avatar,
|
||||
allow_self_responses: allow_self_responses,
|
||||
activation_strategy: activation_strategy,
|
||||
allow_self_responses: allowSelfResponses,
|
||||
activation_strategy: activationStrategy,
|
||||
generation_mode: generationMode,
|
||||
disabled_members: [],
|
||||
chat_metadata: {},
|
||||
fav: fav_grp_checked,
|
||||
@@ -1605,7 +1724,8 @@ jQuery(() => {
|
||||
$("#rm_group_delete").off().on("click", onDeleteGroupClick);
|
||||
$("#group_favorite_button").on('click', onFavoriteGroupClick);
|
||||
$("#rm_group_allow_self_responses").on("input", onGroupSelfResponsesClick);
|
||||
$('input[name="rm_group_activation_strategy"]').on("input", onGroupActivationStrategyInput);
|
||||
$("#rm_group_activation_strategy").on("change", onGroupActivationStrategyInput);
|
||||
$("#rm_group_generation_mode").on("change", onGroupGenerationModeInput);
|
||||
$("#group_avatar_button").on("input", uploadGroupAvatar);
|
||||
$("#rm_group_restore_avatar").on("click", restoreGroupAvatar);
|
||||
$(document).on("click", ".group_member .right_menu_button", onGroupActionClick);
|
||||
|
@@ -44,6 +44,8 @@ const textgenerationwebui_settings = {
|
||||
length_penalty: 1,
|
||||
min_length: 0,
|
||||
encoder_rep_pen: 1,
|
||||
freq_pen: 0,
|
||||
presence_pen: 0,
|
||||
do_sample: true,
|
||||
early_stopping: false,
|
||||
seed: -1,
|
||||
@@ -87,6 +89,8 @@ const setting_names = [
|
||||
"length_penalty",
|
||||
"min_length",
|
||||
"encoder_rep_pen",
|
||||
"freq_pen",
|
||||
"presence_pen",
|
||||
"do_sample",
|
||||
"early_stopping",
|
||||
"seed",
|
||||
@@ -415,6 +419,8 @@ export function getTextGenGenerationData(finalPrompt, this_amount_gen, isImperso
|
||||
'repetition_penalty': textgenerationwebui_settings.rep_pen,
|
||||
'repetition_penalty_range': textgenerationwebui_settings.rep_pen_range,
|
||||
'encoder_repetition_penalty': textgenerationwebui_settings.encoder_rep_pen,
|
||||
'frequency_penalty': textgenerationwebui_settings.freq_pen,
|
||||
'presence_penalty': textgenerationwebui_settings.presence_pen,
|
||||
'top_k': textgenerationwebui_settings.top_k,
|
||||
'min_length': textgenerationwebui_settings.min_length,
|
||||
'no_repeat_ngram_size': textgenerationwebui_settings.no_repeat_ngram_size,
|
||||
|
@@ -1383,12 +1383,16 @@ async function checkWorldInfo(chat, maxContext) {
|
||||
// Add the depth or AN if enabled
|
||||
// Put this code here since otherwise, the chat reference is modified
|
||||
if (extension_settings.note.allowWIScan) {
|
||||
let depthPrompt = getExtensionPromptByName("DEPTH_PROMPT")
|
||||
if (depthPrompt) {
|
||||
textToScan = `${depthPrompt}\n${textToScan}`
|
||||
for (const key of Object.keys(context.extensionPrompts)) {
|
||||
if (key.startsWith('DEPTH_PROMPT')) {
|
||||
const depthPrompt = getExtensionPromptByName(key)
|
||||
if (depthPrompt) {
|
||||
textToScan = `${depthPrompt}\n${textToScan}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let anPrompt = getExtensionPromptByName(NOTE_MODULE_NAME);
|
||||
const anPrompt = getExtensionPromptByName(NOTE_MODULE_NAME);
|
||||
if (anPrompt) {
|
||||
textToScan = `${anPrompt}\n${textToScan}`
|
||||
}
|
||||
|
Reference in New Issue
Block a user