From 8a4b675143e1eeeda36b2763acb55b8428d03de2 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 17 Apr 2024 21:23:06 +0300 Subject: [PATCH] Disable-able chat history and examples --- public/scripts/PromptManager.js | 6 +++--- public/scripts/openai.js | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index bf73b7265..295c12123 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -102,7 +102,7 @@ class Prompt { /** * Representing a collection of prompts. */ -class PromptCollection { +export class PromptCollection { collection = []; overriddenPrompts = []; @@ -163,7 +163,7 @@ class PromptCollection { /** * Retrieves the index of a Prompt instance in the collection by its identifier. * - * @param {null} identifier - The identifier of the Prompt instance to find. + * @param {string} identifier - The identifier of the Prompt instance to find. * @returns {number} The index of the Prompt instance in the collection, or -1 if not found. */ index(identifier) { @@ -904,7 +904,7 @@ class PromptManager { * @returns {boolean} True if the prompt can be deleted, false otherwise. */ isPromptToggleAllowed(prompt) { - const forceTogglePrompts = ['charDescription', 'charPersonality', 'scenario', 'personaDescription', 'worldInfoBefore', 'worldInfoAfter', 'main']; + const forceTogglePrompts = ['charDescription', 'charPersonality', 'scenario', 'personaDescription', 'worldInfoBefore', 'worldInfoAfter', 'main', 'chatHistory', 'dialogueExamples']; return prompt.marker && !forceTogglePrompts.includes(prompt.identifier) ? false : !this.configuration.toggleDisabled.includes(prompt.identifier); } diff --git a/public/scripts/openai.js b/public/scripts/openai.js index e0ff115d5..41c9b24a9 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -726,12 +726,16 @@ export function isOpenRouterWithInstruct() { /** * Populates the chat history of the conversation. * @param {object[]} messages - Array containing all messages. - * @param {PromptCollection} prompts - Map object containing all prompts where the key is the prompt identifier and the value is the prompt object. + * @param {import('./PromptManager').PromptCollection} prompts - Map object containing all prompts where the key is the prompt identifier and the value is the prompt object. * @param {ChatCompletion} chatCompletion - An instance of ChatCompletion class that will be populated with the prompts. * @param type * @param cyclePrompt */ async function populateChatHistory(messages, prompts, chatCompletion, type = null, cyclePrompt = null) { + if (!prompts.has('chatHistory')) { + return; + } + chatCompletion.add(new MessageCollection('chatHistory'), prompts.index('chatHistory')); // Reserve budget for new chat message @@ -816,11 +820,15 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul /** * This function populates the dialogue examples in the conversation. * - * @param {PromptCollection} prompts - Map object containing all prompts where the key is the prompt identifier and the value is the prompt object. + * @param {import('./PromptManager').PromptCollection} prompts - Map object containing all prompts where the key is the prompt identifier and the value is the prompt object. * @param {ChatCompletion} chatCompletion - An instance of ChatCompletion class that will be populated with the prompts. * @param {Object[]} messageExamples - Array containing all message examples. */ function populateDialogueExamples(prompts, chatCompletion, messageExamples) { + if (!prompts.has('dialogueExamples')) { + return; + } + chatCompletion.add(new MessageCollection('dialogueExamples'), prompts.index('dialogueExamples')); if (Array.isArray(messageExamples) && messageExamples.length) { const newExampleChat = new Message('system', substituteParams(oai_settings.new_example_chat_prompt), 'newChat');