#2284 Persona description in-chat-at-depth

This commit is contained in:
Cohee 2024-05-21 01:57:04 +03:00
parent 09a575b783
commit 3dc4c8ca39
4 changed files with 95 additions and 17 deletions

View File

@ -4381,7 +4381,22 @@
<option value="0" data-i18n="In Story String / Prompt Manager">In Story String / Prompt Manager</option>
<option value="2" data-i18n="Top of Author's Note">Top of Author's Note</option>
<option value="3" data-i18n="Bottom of Author's Note">Bottom of Author's Note</option>
<option value="4" data-i18n="In-chat @ Depth">In-chat @ Depth</option>
</select>
<div id="persona_depth_position_settings" class="flex-container">
<div class="flex1">
<label for="persona_depth_value" data-i18n="Depth:">Depth:</label>
<input id="persona_depth_value" class="text_pole" type="number" min="0" max="999" step="1">
</div>
<div class="flex1">
<label for="persona_depth_role" data-i18n="Role:">Role:</label>
<select id="persona_depth_role" class="text_pole">
<option data-i18n="System" value="0">System</option>
<option data-i18n="User" value="1">User</option>
<option data-i18n="Assistant" value="2">Assistant</option>
</select>
</div>
</div>
</div>
</div>
<div class="range-block">

View File

@ -2551,6 +2551,9 @@ function cleanGroupMessage(getMessage) {
}
function addPersonaDescriptionExtensionPrompt() {
const INJECT_TAG = 'PERSONA_DESCRIPTION';
setExtensionPrompt(INJECT_TAG, '', extension_prompt_types.IN_PROMPT, 0);
if (!power_user.persona_description) {
return;
}
@ -2565,6 +2568,10 @@ function addPersonaDescriptionExtensionPrompt() {
setExtensionPrompt(NOTE_MODULE_NAME, ANWithDesc, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth], extension_settings.note.allowWIScan, chat_metadata[metadata_keys.role]);
}
if (power_user.persona_description_position === persona_description_positions.AT_DEPTH) {
setExtensionPrompt(INJECT_TAG, power_user.persona_description, extension_prompt_types.IN_CHAT, power_user.persona_description_depth, true, power_user.persona_description_role);
}
}
function getAllExtensionPrompts() {
@ -3389,6 +3396,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
// Extension added strings
// Set non-WI AN
setFloatingPrompt();
// Add persona description to prompt
addPersonaDescriptionExtensionPrompt();
// Add WI to prompt (and also inject WI to AN value via hijack)
// Make quiet prompt available for WIAN
@ -3506,8 +3515,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
userAlignmentMessage = formatMessageHistoryItem(alignmentMessage, isInstruct, false);
}
// Add persona description to prompt
addPersonaDescriptionExtensionPrompt();
// Call combined AN into Generate
const beforeScenarioAnchor = getExtensionPrompt(extension_prompt_types.BEFORE_PROMPT).trimStart();
const afterScenarioAnchor = getExtensionPrompt(extension_prompt_types.IN_PROMPT);

View File

@ -27,6 +27,8 @@ import { selected_group } from './group-chats.js';
let savePersonasPage = 0;
const GRID_STORAGE_KEY = 'Personas_GridView';
const DEFAULT_DEPTH = 2;
const DEFAULT_ROLE = 0;
export let user_avatar = '';
export const personasFilter = new FilterHelper(debounce(getUserAvatars, debounce_timeout.quick));
@ -371,6 +373,8 @@ export function initPersona(avatarId, personaName, personaDescription) {
power_user.persona_descriptions[avatarId] = {
description: personaDescription || '',
position: persona_description_positions.IN_PROMPT,
depth: DEFAULT_DEPTH,
role: DEFAULT_ROLE,
};
saveSettingsDebounced();
@ -415,6 +419,8 @@ export async function convertCharacterToPersona(characterId = null) {
power_user.persona_descriptions[overwriteName] = {
description: description,
position: persona_description_positions.IN_PROMPT,
depth: DEFAULT_DEPTH,
role: DEFAULT_ROLE,
};
// If the user is currently using this persona, update the description
@ -447,11 +453,17 @@ export function setPersonaDescription() {
power_user.persona_description_position = persona_description_positions.IN_PROMPT;
}
$('#persona_depth_position_settings').toggle(power_user.persona_description_position === persona_description_positions.AT_DEPTH);
$('#persona_description').val(power_user.persona_description);
$('#persona_depth_value').val(power_user.persona_description_depth ?? DEFAULT_DEPTH);
$('#persona_description_position')
.val(power_user.persona_description_position)
.find(`option[value='${power_user.persona_description_position}']`)
.find(`option[value="${power_user.persona_description_position}"]`)
.attr('selected', String(true));
$('#persona_depth_role')
.val(power_user.persona_description_role)
.find(`option[value="${power_user.persona_description_role}"]`)
.prop('selected', String(true));
countPersonaDescriptionTokens();
}
@ -479,6 +491,8 @@ async function updatePersonaNameIfExists(avatarId, newName) {
power_user.persona_descriptions[avatarId] = {
description: '',
position: persona_description_positions.IN_PROMPT,
depth: DEFAULT_DEPTH,
role: DEFAULT_ROLE,
};
console.log(`Created persona name for ${avatarId} as ${newName}`);
}
@ -517,6 +531,8 @@ async function bindUserNameToPersona(e) {
power_user.persona_descriptions[avatarId] = {
description: isCurrentPersona ? power_user.persona_description : '',
position: isCurrentPersona ? power_user.persona_description_position : persona_description_positions.IN_PROMPT,
depth: isCurrentPersona ? power_user.persona_description_depth : DEFAULT_DEPTH,
role: isCurrentPersona ? power_user.persona_description_role : DEFAULT_ROLE,
};
}
@ -557,12 +573,16 @@ function selectCurrentPersona() {
const descriptor = power_user.persona_descriptions[user_avatar];
if (descriptor) {
power_user.persona_description = descriptor.description;
power_user.persona_description_position = descriptor.position;
power_user.persona_description = descriptor.description ?? '';
power_user.persona_description_position = descriptor.position ?? persona_description_positions.IN_PROMPT;
power_user.persona_description_depth = descriptor.depth ?? DEFAULT_DEPTH;
power_user.persona_description_role = descriptor.role ?? DEFAULT_ROLE;
} else {
power_user.persona_description = '';
power_user.persona_description_position = persona_description_positions.IN_PROMPT;
power_user.persona_descriptions[user_avatar] = { description: '', position: persona_description_positions.IN_PROMPT };
power_user.persona_description_depth = DEFAULT_DEPTH;
power_user.persona_description_role = DEFAULT_ROLE;
power_user.persona_descriptions[user_avatar] = { description: '', position: persona_description_positions.IN_PROMPT, depth: DEFAULT_DEPTH, role: DEFAULT_ROLE };
}
setPersonaDescription();
@ -667,6 +687,8 @@ function onPersonaDescriptionInput() {
object = {
description: power_user.persona_description,
position: Number($('#persona_description_position').find(':selected').val()),
depth: Number($('#persona_depth_value').val()),
role: Number($('#persona_depth_role').find(':selected').val()),
};
power_user.persona_descriptions[user_avatar] = object;
}
@ -680,26 +702,55 @@ function onPersonaDescriptionInput() {
saveSettingsDebounced();
}
function onPersonaDescriptionDepthValueInput() {
power_user.persona_description_depth = Number($('#persona_depth_value').val());
if (power_user.personas[user_avatar]) {
const object = getOrCreatePersonaDescriptor();
object.depth = power_user.persona_description_depth;
}
saveSettingsDebounced();
}
function onPersonaDescriptionDepthRoleInput() {
power_user.persona_description_role = Number($('#persona_depth_role').find(':selected').val());
if (power_user.personas[user_avatar]) {
const object = getOrCreatePersonaDescriptor();
object.role = power_user.persona_description_role;
}
saveSettingsDebounced();
}
function onPersonaDescriptionPositionInput() {
power_user.persona_description_position = Number(
$('#persona_description_position').find(':selected').val(),
);
if (power_user.personas[user_avatar]) {
const object = getOrCreatePersonaDescriptor();
object.position = power_user.persona_description_position;
}
saveSettingsDebounced();
$('#persona_depth_position_settings').toggle(power_user.persona_description_position === persona_description_positions.AT_DEPTH);
}
function getOrCreatePersonaDescriptor() {
let object = power_user.persona_descriptions[user_avatar];
if (!object) {
object = {
description: power_user.persona_description,
position: power_user.persona_description_position,
depth: power_user.persona_description_depth,
role: power_user.persona_description_role,
};
power_user.persona_descriptions[user_avatar] = object;
}
object.position = power_user.persona_description_position;
}
saveSettingsDebounced();
return object;
}
async function setDefaultPersona(e) {
@ -925,6 +976,8 @@ export function initPersonas() {
$('#create_dummy_persona').on('click', createDummyPersona);
$('#persona_description').on('input', onPersonaDescriptionInput);
$('#persona_description_position').on('input', onPersonaDescriptionPositionInput);
$('#persona_depth_value').on('input', onPersonaDescriptionDepthValueInput);
$('#persona_depth_role').on('input', onPersonaDescriptionDepthRoleInput);
$('#personas_backup').on('click', onBackupPersonas);
$('#personas_restore').on('click', () => $('#personas_restore_input').trigger('click'));
$('#personas_restore_input').on('change', onPersonasRestoreInput);

View File

@ -102,6 +102,7 @@ export const persona_description_positions = {
AFTER_CHAR: 1,
TOP_AN: 2,
BOTTOM_AN: 3,
AT_DEPTH: 4,
};
let power_user = {
@ -244,6 +245,8 @@ let power_user = {
persona_description: '',
persona_description_position: persona_description_positions.IN_PROMPT,
persona_description_role: 0,
persona_description_depth: 2,
persona_show_notifications: true,
persona_sort_order: 'asc',
@ -1401,7 +1404,7 @@ async function applyMovingUIPreset(name) {
console.log('MovingUI Preset applied: ' + name);
loadMovingUIState();
saveSettingsDebounced()
saveSettingsDebounced();
}
/**