diff --git a/public/index.html b/public/index.html index d91958044..d28775b27 100644 --- a/public/index.html +++ b/public/index.html @@ -4505,7 +4505,7 @@ Character's Note - +

@@ -4513,7 +4513,17 @@ @ Depth

- + +

+ + Role + +

+
Tokens: counting...
diff --git a/public/script.js b/public/script.js index 5a2be853e..acb63bcf3 100644 --- a/public/script.js +++ b/public/script.js @@ -752,6 +752,7 @@ function getCurrentChatId() { const talkativeness_default = 0.5; export const depth_prompt_depth_default = 4; +export const depth_prompt_role_default = 'system'; const per_page_default = 50; var is_advanced_char_open = false; @@ -778,6 +779,7 @@ let create_save = { alternate_greetings: [], depth_prompt_prompt: '', depth_prompt_depth: depth_prompt_depth_default, + depth_prompt_role: depth_prompt_role_default, 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) { 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 { 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, 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 @@ -6697,6 +6701,7 @@ export function select_selected_character(chid) { $('#scenario_pole').val(characters[chid].scenario); $('#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_role').val(characters[chid].data?.extensions?.depth_prompt?.role ?? depth_prompt_role_default); $('#talkativeness_slider').val(characters[chid].talkativeness || talkativeness_default); $('#mes_example_textarea').val(characters[chid].mes_example); $('#selected_chat_pole').val(characters[chid].chat); @@ -6767,6 +6772,7 @@ function select_rm_create() { $('#scenario_pole').val(create_save.scenario); $('#depth_prompt_prompt').val(create_save.depth_prompt_prompt); $('#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); $('#character_json_data').val(''); $('#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. * 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: '#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_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: '#character_json_data', callback: () => { } }, { 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()); }, '#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_role': function () { create_save.depth_prompt_role = String($('#depth_prompt_role').val()); }, }; Object.keys(elementsToUpdate).forEach(function (id) { diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 27708edc5..3b2f1c121 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -68,6 +68,7 @@ import { depth_prompt_depth_default, loadItemizedPrompts, animation_duration, + depth_prompt_role_default, } from '../script.js'; import { printTagList, createTagMapFromList, applyTagsOnCharacterSelect, tag_map } from './tags.js'; import { FILTER_TYPES, FilterHelper } from './filters.js'; @@ -284,7 +285,7 @@ export function findGroupMemberId(arg) { * 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 + * @returns {{depth: number, text: string, role: string}[]} Array of depth prompts */ export function getGroupDepthPrompts(groupId, characterId) { 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 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) { - depthPrompts.push({ text: depthPromptText, depth: depthPromptDepth }); + depthPrompts.push({ text: depthPromptText, depth: depthPromptDepth, role: depthPromptRole }); } } diff --git a/src/endpoints/characters.js b/src/endpoints/characters.js index 613f88c79..45d2896ac 100644 --- a/src/endpoints/characters.js +++ b/src/endpoints/characters.js @@ -210,7 +210,8 @@ function convertToV2(char) { creator: char.creator, tags: char.tags, 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(); @@ -331,9 +332,12 @@ function charaFormatData(data) { // Spec extension: depth prompt 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 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.depth', depth_value); + _.set(char, 'data.extensions.depth_prompt.role', role_value); //_.set(char, 'data.extensions.create_date', humanizedISO8601DateTime()); //_.set(char, 'data.extensions.avatar', 'none'); //_.set(char, 'data.extensions.chat', data.ch_name + ' - ' + humanizedISO8601DateTime());