Add role selection to Character's Note depth prompt
This commit is contained in:
parent
50670c1e6a
commit
153f75cf1a
|
@ -4505,7 +4505,7 @@
|
||||||
Character's Note
|
Character's Note
|
||||||
</span>
|
</span>
|
||||||
</h4>
|
</h4>
|
||||||
<textarea id="depth_prompt_prompt" name="depth_prompt_prompt" class="text_pole" rows="2" maxlength="50000" autocomplete="off" form="form_create" placeholder="(Text to be inserted in-chat @ designated depth)"></textarea>
|
<textarea id="depth_prompt_prompt" name="depth_prompt_prompt" class="text_pole" rows="5" maxlength="50000" autocomplete="off" form="form_create" placeholder="(Text to be inserted in-chat @ designated depth and role)"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h4>
|
<h4>
|
||||||
|
@ -4513,7 +4513,17 @@
|
||||||
@ Depth
|
@ Depth
|
||||||
</span>
|
</span>
|
||||||
</h4>
|
</h4>
|
||||||
<input id="depth_prompt_depth" name="depth_prompt_depth" class="text_pole widthUnset m-t-0" type="number" min="0" max="999" value="4" form="form_create" />
|
<input id="depth_prompt_depth" name="depth_prompt_depth" class="text_pole textarea_compact m-t-0" type="number" min="0" max="999" value="4" form="form_create" />
|
||||||
|
<h4>
|
||||||
|
<span data-i18n="Role">
|
||||||
|
Role
|
||||||
|
</span>
|
||||||
|
</h4>
|
||||||
|
<select id="depth_prompt_role" name="depth_prompt_role" form="form_create" class="text_pole textarea_compact m-t-0">
|
||||||
|
<option value="system" data-i18n="System">System</option>
|
||||||
|
<option value="user" data-i18n="User">User</option>
|
||||||
|
<option value="assistant" data-i18n="Assistant">Assistant</option>
|
||||||
|
</select>
|
||||||
<div class="extension_token_counter">
|
<div class="extension_token_counter">
|
||||||
Tokens: <span data-token-counter="depth_prompt_prompt" data-token-permanent="true">counting...</span>
|
Tokens: <span data-token-counter="depth_prompt_prompt" data-token-permanent="true">counting...</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -752,6 +752,7 @@ function getCurrentChatId() {
|
||||||
|
|
||||||
const talkativeness_default = 0.5;
|
const talkativeness_default = 0.5;
|
||||||
export const depth_prompt_depth_default = 4;
|
export const depth_prompt_depth_default = 4;
|
||||||
|
export const depth_prompt_role_default = 'system';
|
||||||
const per_page_default = 50;
|
const per_page_default = 50;
|
||||||
|
|
||||||
var is_advanced_char_open = false;
|
var is_advanced_char_open = false;
|
||||||
|
@ -778,6 +779,7 @@ let create_save = {
|
||||||
alternate_greetings: [],
|
alternate_greetings: [],
|
||||||
depth_prompt_prompt: '',
|
depth_prompt_prompt: '',
|
||||||
depth_prompt_depth: depth_prompt_depth_default,
|
depth_prompt_depth: depth_prompt_depth_default,
|
||||||
|
depth_prompt_role: depth_prompt_role_default,
|
||||||
extensions: {},
|
extensions: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3114,12 +3116,14 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu
|
||||||
|
|
||||||
if (selected_group && Array.isArray(groupDepthPrompts) && groupDepthPrompts.length > 0) {
|
if (selected_group && Array.isArray(groupDepthPrompts) && groupDepthPrompts.length > 0) {
|
||||||
groupDepthPrompts.forEach((value, index) => {
|
groupDepthPrompts.forEach((value, index) => {
|
||||||
setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth, extension_settings.note.allowWIScan);
|
const role = getExtensionPromptRoleByName(value.role);
|
||||||
|
setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth, extension_settings.note.allowWIScan, role);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const depthPromptText = baseChatReplace(characters[this_chid].data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || '';
|
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;
|
const depthPromptDepth = characters[this_chid].data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
|
||||||
setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth, extension_settings.note.allowWIScan);
|
const depthPromptRole = getExtensionPromptRoleByName(characters[this_chid].data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default);
|
||||||
|
setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth, extension_settings.note.allowWIScan, depthPromptRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse example messages
|
// Parse example messages
|
||||||
|
@ -6697,6 +6701,7 @@ export function select_selected_character(chid) {
|
||||||
$('#scenario_pole').val(characters[chid].scenario);
|
$('#scenario_pole').val(characters[chid].scenario);
|
||||||
$('#depth_prompt_prompt').val(characters[chid].data?.extensions?.depth_prompt?.prompt ?? '');
|
$('#depth_prompt_prompt').val(characters[chid].data?.extensions?.depth_prompt?.prompt ?? '');
|
||||||
$('#depth_prompt_depth').val(characters[chid].data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default);
|
$('#depth_prompt_depth').val(characters[chid].data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default);
|
||||||
|
$('#depth_prompt_role').val(characters[chid].data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default);
|
||||||
$('#talkativeness_slider').val(characters[chid].talkativeness || talkativeness_default);
|
$('#talkativeness_slider').val(characters[chid].talkativeness || talkativeness_default);
|
||||||
$('#mes_example_textarea').val(characters[chid].mes_example);
|
$('#mes_example_textarea').val(characters[chid].mes_example);
|
||||||
$('#selected_chat_pole').val(characters[chid].chat);
|
$('#selected_chat_pole').val(characters[chid].chat);
|
||||||
|
@ -6767,6 +6772,7 @@ function select_rm_create() {
|
||||||
$('#scenario_pole').val(create_save.scenario);
|
$('#scenario_pole').val(create_save.scenario);
|
||||||
$('#depth_prompt_prompt').val(create_save.depth_prompt_prompt);
|
$('#depth_prompt_prompt').val(create_save.depth_prompt_prompt);
|
||||||
$('#depth_prompt_depth').val(create_save.depth_prompt_depth);
|
$('#depth_prompt_depth').val(create_save.depth_prompt_depth);
|
||||||
|
$('#depth_prompt_role').val(create_save.depth_prompt_role);
|
||||||
$('#mes_example_textarea').val(create_save.mes_example);
|
$('#mes_example_textarea').val(create_save.mes_example);
|
||||||
$('#character_json_data').val('');
|
$('#character_json_data').val('');
|
||||||
$('#avatar_div').css('display', 'flex');
|
$('#avatar_div').css('display', 'flex');
|
||||||
|
@ -6810,6 +6816,30 @@ export function setExtensionPrompt(key, value, position, depth, scan = false, ro
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a enum value of the extension prompt role by its name.
|
||||||
|
* @param {string} roleName The name of the extension prompt role.
|
||||||
|
* @returns {number} The role id of the extension prompt.
|
||||||
|
*/
|
||||||
|
export function getExtensionPromptRoleByName(roleName) {
|
||||||
|
// If the role is already a valid number, return it
|
||||||
|
if (typeof roleName === 'number' && Object.values(extension_prompt_roles).includes(roleName)) {
|
||||||
|
return roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (roleName) {
|
||||||
|
case 'system':
|
||||||
|
return extension_prompt_roles.SYSTEM;
|
||||||
|
case 'user':
|
||||||
|
return extension_prompt_roles.USER;
|
||||||
|
case 'assistant':
|
||||||
|
return extension_prompt_roles.ASSISTANT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skill issue?
|
||||||
|
return extension_prompt_roles.SYSTEM;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all char A/N prompt injections from the chat.
|
* Removes all char A/N prompt injections from the chat.
|
||||||
* To clean up when switching from groups to solo and vice versa.
|
* To clean up when switching from groups to solo and vice versa.
|
||||||
|
@ -7425,6 +7455,7 @@ async function createOrEditCharacter(e) {
|
||||||
{ id: '#scenario_pole', callback: value => create_save.scenario = value },
|
{ id: '#scenario_pole', callback: value => create_save.scenario = value },
|
||||||
{ id: '#depth_prompt_prompt', callback: value => create_save.depth_prompt_prompt = value },
|
{ id: '#depth_prompt_prompt', callback: value => create_save.depth_prompt_prompt = value },
|
||||||
{ id: '#depth_prompt_depth', callback: value => create_save.depth_prompt_depth = value, defaultValue: depth_prompt_depth_default },
|
{ id: '#depth_prompt_depth', callback: value => create_save.depth_prompt_depth = value, defaultValue: depth_prompt_depth_default },
|
||||||
|
{ id: '#depth_prompt_role', callback: value => create_save.depth_prompt_role = value, defaultValue: depth_prompt_role_default },
|
||||||
{ id: '#mes_example_textarea', callback: value => create_save.mes_example = value },
|
{ id: '#mes_example_textarea', callback: value => create_save.mes_example = value },
|
||||||
{ id: '#character_json_data', callback: () => { } },
|
{ id: '#character_json_data', callback: () => { } },
|
||||||
{ id: '#alternate_greetings_template', callback: value => create_save.alternate_greetings = value, defaultValue: [] },
|
{ id: '#alternate_greetings_template', callback: value => create_save.alternate_greetings = value, defaultValue: [] },
|
||||||
|
@ -8794,6 +8825,7 @@ jQuery(async function () {
|
||||||
'#talkativeness_slider': function () { create_save.talkativeness = Number($('#talkativeness_slider').val()); },
|
'#talkativeness_slider': function () { create_save.talkativeness = Number($('#talkativeness_slider').val()); },
|
||||||
'#depth_prompt_prompt': function () { create_save.depth_prompt_prompt = String($('#depth_prompt_prompt').val()); },
|
'#depth_prompt_prompt': function () { create_save.depth_prompt_prompt = String($('#depth_prompt_prompt').val()); },
|
||||||
'#depth_prompt_depth': function () { create_save.depth_prompt_depth = Number($('#depth_prompt_depth').val()); },
|
'#depth_prompt_depth': function () { create_save.depth_prompt_depth = Number($('#depth_prompt_depth').val()); },
|
||||||
|
'#depth_prompt_role': function () { create_save.depth_prompt_role = String($('#depth_prompt_role').val()); },
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.keys(elementsToUpdate).forEach(function (id) {
|
Object.keys(elementsToUpdate).forEach(function (id) {
|
||||||
|
|
|
@ -68,6 +68,7 @@ import {
|
||||||
depth_prompt_depth_default,
|
depth_prompt_depth_default,
|
||||||
loadItemizedPrompts,
|
loadItemizedPrompts,
|
||||||
animation_duration,
|
animation_duration,
|
||||||
|
depth_prompt_role_default,
|
||||||
} from '../script.js';
|
} from '../script.js';
|
||||||
import { printTagList, createTagMapFromList, applyTagsOnCharacterSelect, tag_map } from './tags.js';
|
import { printTagList, createTagMapFromList, applyTagsOnCharacterSelect, tag_map } from './tags.js';
|
||||||
import { FILTER_TYPES, FilterHelper } from './filters.js';
|
import { FILTER_TYPES, FilterHelper } from './filters.js';
|
||||||
|
@ -284,7 +285,7 @@ export function findGroupMemberId(arg) {
|
||||||
* Gets depth prompts for group members.
|
* Gets depth prompts for group members.
|
||||||
* @param {string} groupId Group ID
|
* @param {string} groupId Group ID
|
||||||
* @param {number} characterId Current Character ID
|
* @param {number} characterId Current Character ID
|
||||||
* @returns {{depth: number, text: string}[]} Array of depth prompts
|
* @returns {{depth: number, text: string, role: string}[]} Array of depth prompts
|
||||||
*/
|
*/
|
||||||
export function getGroupDepthPrompts(groupId, characterId) {
|
export function getGroupDepthPrompts(groupId, characterId) {
|
||||||
if (!groupId) {
|
if (!groupId) {
|
||||||
|
@ -320,9 +321,10 @@ export function getGroupDepthPrompts(groupId, characterId) {
|
||||||
|
|
||||||
const depthPromptText = baseChatReplace(character.data?.extensions?.depth_prompt?.prompt?.trim(), name1, character.name) || '';
|
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;
|
const depthPromptDepth = character.data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
|
||||||
|
const depthPromptRole = character.data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default;
|
||||||
|
|
||||||
if (depthPromptText) {
|
if (depthPromptText) {
|
||||||
depthPrompts.push({ text: depthPromptText, depth: depthPromptDepth });
|
depthPrompts.push({ text: depthPromptText, depth: depthPromptDepth, role: depthPromptRole });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,8 @@ function convertToV2(char) {
|
||||||
creator: char.creator,
|
creator: char.creator,
|
||||||
tags: char.tags,
|
tags: char.tags,
|
||||||
depth_prompt_prompt: char.depth_prompt_prompt,
|
depth_prompt_prompt: char.depth_prompt_prompt,
|
||||||
depth_prompt_response: char.depth_prompt_response,
|
depth_prompt_depth: char.depth_prompt_depth,
|
||||||
|
depth_prompt_role: char.depth_prompt_role,
|
||||||
});
|
});
|
||||||
|
|
||||||
result.chat = char.chat ?? humanizedISO8601DateTime();
|
result.chat = char.chat ?? humanizedISO8601DateTime();
|
||||||
|
@ -331,9 +332,12 @@ function charaFormatData(data) {
|
||||||
|
|
||||||
// Spec extension: depth prompt
|
// Spec extension: depth prompt
|
||||||
const depth_default = 4;
|
const depth_default = 4;
|
||||||
|
const role_default = 'system';
|
||||||
const depth_value = !isNaN(Number(data.depth_prompt_depth)) ? Number(data.depth_prompt_depth) : depth_default;
|
const depth_value = !isNaN(Number(data.depth_prompt_depth)) ? Number(data.depth_prompt_depth) : depth_default;
|
||||||
|
const role_value = data.depth_prompt_role ?? role_default;
|
||||||
_.set(char, 'data.extensions.depth_prompt.prompt', data.depth_prompt_prompt ?? '');
|
_.set(char, 'data.extensions.depth_prompt.prompt', data.depth_prompt_prompt ?? '');
|
||||||
_.set(char, 'data.extensions.depth_prompt.depth', depth_value);
|
_.set(char, 'data.extensions.depth_prompt.depth', depth_value);
|
||||||
|
_.set(char, 'data.extensions.depth_prompt.role', role_value);
|
||||||
//_.set(char, 'data.extensions.create_date', humanizedISO8601DateTime());
|
//_.set(char, 'data.extensions.create_date', humanizedISO8601DateTime());
|
||||||
//_.set(char, 'data.extensions.avatar', 'none');
|
//_.set(char, 'data.extensions.avatar', 'none');
|
||||||
//_.set(char, 'data.extensions.chat', data.ch_name + ' - ' + humanizedISO8601DateTime());
|
//_.set(char, 'data.extensions.chat', data.ch_name + ' - ' + humanizedISO8601DateTime());
|
||||||
|
|
Loading…
Reference in New Issue