From 86c7a7a058f0ee6b40fd5863209debe7fd504c0d Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:04:34 +0900 Subject: [PATCH] @Depth insertion for WI Entries --- public/index.html | 3 ++- public/script.js | 10 +++++++++- public/scripts/world-info.js | 11 +++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index 1e44acd0e..18e253e22 100644 --- a/public/index.html +++ b/public/index.html @@ -1935,7 +1935,7 @@ - + @@ -3960,6 +3960,7 @@ + diff --git a/public/script.js b/public/script.js index 9db5878f3..1412222fd 100644 --- a/public/script.js +++ b/public/script.js @@ -3286,6 +3286,14 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, } is_send_press = false; } + + //prevent custom depth WI entries (which have unique random key names) from duplicating + for (let key in extension_prompts) { + if (key.includes('customDepthWI')) { + let keyname = extension_prompts[key] + delete extension_prompts[key]; + } + } //console.log('generate ending'); } //generate ends @@ -5194,7 +5202,7 @@ export async function getChatsFromFiles(data, isGroupChat) { let chat_dict = {}; let chat_list = Object.values(data).sort((a, b) => a["file_name"].localeCompare(b["file_name"])).reverse(); - let chat_promise = chat_list.map(({ file_name}) => { + let chat_promise = chat_list.map(({ file_name }) => { return new Promise(async (res, rej) => { try { const endpoint = isGroupChat ? '/getgroupchat' : '/getchat'; diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 524215893..141cfe094 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -71,6 +71,7 @@ const world_info_position = { after: 1, ANTop: 2, ANBottom: 3, + atDepth: 4, }; @@ -658,6 +659,9 @@ function getWorldEntry(name, data, entry) { const uid = $(this).data("uid"); const value = Number($(this).val()); data.entries[uid].position = !isNaN(value) ? value : 0; + if (value === 4) { + template.find('label[for="order"').text('Depth:') + } else { template.find('label[for="order"').text('Order:') } // Spec v2 only supports before_char and after_char setOriginalDataValue(data, uid, "position", data.entries[uid].position == 0 ? 'before_char' : 'after_char'); // Write the original value as extensions field @@ -1154,6 +1158,13 @@ async function checkWorldInfo(chat, maxContext) { case world_info_position.ANBottom: ANBottomEntries.unshift(entry.content); break; + case world_info_position.atDepth: + //inserted one by one, unrelated to any array of items + //must have a unique value for 'key' argument + //uses the order input to specify depth + var randomNumber = Math.floor(Math.random() * 99999) + 1; + context.setExtensionPrompt(`customDepthWI-${entry.keywords}-${entry.uid}-${randomNumber}`, entry.content, 1, entry.order); + break; default: break; }