Create a deep copy of prompt defaults on char select

Along other minor fixes and optimizations
This commit is contained in:
maver 2023-07-02 21:50:37 +02:00
parent 56a9dd158a
commit 632fa770be
4 changed files with 24 additions and 35 deletions

View File

@ -96,6 +96,7 @@
#completion_prompt_manager_popup #completion_prompt_manager_popup_entry_form_inspect_list {
margin-top: 1em;
padding: 1em;
}
#completion_prompt_manager_popup .completion_prompt_manager_prompt {

View File

@ -1282,11 +1282,11 @@
</div>
</div>
<div class="range-block">
<label for="names_in_completion" title="Apply character name to chat messages" class="checkbox_label widthFreeExpand">
<input id="names_in_completion" type="checkbox" /><span data-i18n="Add character names to chat messages">Add character names to chat messages</span>
<label for="names_in_completion" title="Add character names" class="checkbox_label widthFreeExpand">
<input id="names_in_completion" type="checkbox" /><span data-i18n="Add character names">Add character names</span>
</label>
<div class="toggle-description justifyLeft">
<span data-i18n="May help the model to understand context. Names must only contain letters or numbers.">May help the model to understand context. Names must only contain letters or numbers.</span>
<span data-i18n="May help the model to understand context. Names must only contain letters or numbers.">Helps the model to associate messages in group chats. Names must only contain letters or numbers without whitespaces.</span>
</div>
</div>
<div class="range-block">
@ -3596,7 +3596,7 @@
<a id="completion_prompt_manager_popup_close_button" title="close" class="fa-solid fa-close menu_button"></a>
</div>
<div class="text_muted">The list of prompts associated with this marker.</div>
<div id="completion_prompt_manager_popup_entry_form_inspect_list" class="text_pole"></div>
<div id="completion_prompt_manager_popup_entry_form_inspect_list"></div>
</div>
</form>
</div>

View File

@ -64,46 +64,39 @@ class Prompt {
class PromptCollection {
collection = [];
constructor(...prompts) {
this.add(...prompts);
}
checkPromptInstance(...prompts) {
for(let prompt of prompts) {
if(!(prompt instanceof Prompt)) {
throw new Error('Only Prompt instances can be added to PromptCollection');
}
}
this.collection.push(...prompts);
}
add(...prompts) {
for(let prompt of prompts) {
if(!(prompt instanceof Prompt)) {
throw new Error('Only Prompt instances can be added to PromptCollection');
}
}
this.checkPromptInstance(...prompts);
this.collection.push(...prompts);
}
set(prompt, position) {
if(!(prompt instanceof Prompt)) {
throw new Error('Only Prompt instances can be added to PromptCollection');
}
this.checkPromptInstance(prompt);
this.collection[position] = prompt;
}
get(identifier) {
const index = this.index(identifier);
if (0 > index) return null;
return this.collection[index];
return this.collection.find(prompt => prompt.identifier === identifier);
}
index (identifier){
index(identifier) {
return this.collection.findIndex(prompt => prompt.identifier === identifier);
}
has(identifier) {
return this.collection.some(message => message.identifier === identifier);
return this.index(identifier) !== -1;
}
}
@ -520,12 +513,12 @@ PromptManagerModule.prototype.checkForMissingPrompts = function(prompts) {
};
/**
* Check whether a prompt is a marker.
* Check whether a prompt can be inspected.
* @param {object} prompt - The prompt to check.
* @returns {boolean} True if the prompt is a marker, false otherwise.
*/
PromptManagerModule.prototype.isStPromptMarker = function (prompt) {
return true === prompt.marker;
PromptManagerModule.prototype.isPromptInspectionAllowed = function (prompt) {
return true === prompt.marker;
}
/**
@ -576,10 +569,7 @@ PromptManagerModule.prototype.handleCharacterSelected = function (event) {
// ToDo: These should be passed as parameter or attached to the manager as a set of default options.
// Set default prompts and order for character.
if (0 === promptList.length) this.addPromptListForCharacter(this.activeCharacter, openAiDefaultPromptList)
// Check whether the referenced prompts are present.
if (0 === this.serviceSettings.prompts.length) this.setPrompts(openAiDefaultPrompts.prompts);
if (0 === promptList.length) this.addPromptListForCharacter(this.activeCharacter, openAiDefaultPromptList);
}
PromptManagerModule.prototype.handleGroupSelected = function (event) {
@ -588,8 +578,6 @@ PromptManagerModule.prototype.handleGroupSelected = function (event) {
const promptList = this.getPromptListByCharacter(characterDummy);
if (0 === promptList.length) this.addPromptListForCharacter(characterDummy, openAiDefaultPromptList)
if (0 === this.serviceSettings.prompts.length) this.setPrompts(openAiDefaultPrompts.prompts);
}
PromptManagerModule.prototype.getActiveGroupCharacters = function() {
@ -645,7 +633,7 @@ PromptManagerModule.prototype.removePromptListForCharacter = function (character
PromptManagerModule.prototype.addPromptListForCharacter = function (character, promptList) {
this.serviceSettings.prompt_lists.push({
character_id: character.id,
list: promptList
list: JSON.parse(JSON.stringify(promptList))
});
}
@ -775,7 +763,7 @@ PromptManagerModule.prototype.loadMessagesIntoInspectForm = function (messages)
messages.getCollection().forEach(message => {
const truncatedTitle = message.content.length > 32 ? message.content.slice(0, 32) + '...' : message.content;
messageList.append(createInlineDrawer(message.title || truncatedTitle, message.content || 'No Content'));
messageList.append(createInlineDrawer(message.identifier || truncatedTitle, message.content || 'No Content'));
});
}
@ -981,7 +969,7 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
}
let inspectSpanHtml = '';
if (this.isStPromptMarker(prompt)) {
if (this.isPromptInspectionAllowed(prompt)) {
inspectSpanHtml = `
<span title="inspect" class="prompt-manager-inspect-action fa-solid fa-magnifying-glass"></span>
`;

View File

@ -454,7 +454,7 @@ function populateDialogueExamples(prompts, chatCompletion) {
/**
* Populate a chat conversation by adding prompts to the conversation and managing system and user prompts.
*
* @param {Map} prompts - Map object containing all prompts where the key is the prompt identifier and the value is the prompt object.
* @param {PromptCollection} prompts - PromptCollection 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} options - An object with optional settings.
* @param {string} options.bias - A bias to be added in the conversation.
@ -496,7 +496,7 @@ function populateChatCompletion (prompts, chatCompletion, {bias, quietPrompt, ty
[...systemPrompts, ...userPrompts].forEach(identifier => addToChatCompletion(identifier));
// Add enhance definition instruction
if (prompts.has('scenario')) addToChatCompletion('enhanceDefinitions');
if (prompts.has('enhanceDefinitions')) addToChatCompletion('enhanceDefinitions');
// Insert nsfw avoidance prompt into main, if no nsfw prompt is present
if (false === chatCompletion.has('nsfw') && oai_settings.nsfw_avoidance_prompt)