Simplify new character handling

This commit is contained in:
maver 2023-06-03 17:39:14 +02:00
parent a627f684d2
commit 0e3e57269c

View File

@ -313,11 +313,13 @@ PromptManagerModule.prototype.isPromptDeletionAllowed = function (prompt) {
PromptManagerModule.prototype.handleCharacterSelected = function (event) { PromptManagerModule.prototype.handleCharacterSelected = function (event) {
this.activeCharacter = {id: event.detail.id, ...event.detail.character}; this.activeCharacter = {id: event.detail.id, ...event.detail.character};
const promptList = this.getPromptListByCharacter(this.activeCharacter); const promptList = this.getPromptListByCharacter(this.activeCharacter);
if (0 === promptList.length) {
this.setPromptListForCharacter(this.activeCharacter, this.getDefaultPromptList()) // 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.setPromptListForCharacter(this.activeCharacter, openAiDefaultPromptList)
// Check whether the referenced prompts are present.
if (0 === this.serviceSettings.prompts.length) this.setPrompts(openAiDefaultPrompts);
} }
PromptManagerModule.prototype.getPromptsForCharacter = function (character, onlyEnabled = false) { PromptManagerModule.prototype.getPromptsForCharacter = function (character, onlyEnabled = false) {
@ -328,7 +330,11 @@ PromptManagerModule.prototype.getPromptsForCharacter = function (character, only
// Get the prompt order for a given character, otherwise an empty array is returned. // Get the prompt order for a given character, otherwise an empty array is returned.
PromptManagerModule.prototype.getPromptListByCharacter = function (character) { PromptManagerModule.prototype.getPromptListByCharacter = function (character) {
return character === null ? [] : (this.serviceSettings.prompt_lists.find(list => String(list.character_id) === String(character.id))?.list ?? []); return !character ? [] : (this.serviceSettings.prompt_lists.find(list => String(list.character_id) === String(character.id))?.list ?? []);
}
PromptManagerModule.prototype.setPrompts = function(prompts) {
this.serviceSettings.prompts = prompts;
} }
PromptManagerModule.prototype.setPromptListForCharacter = function (character, promptList) { PromptManagerModule.prototype.setPromptListForCharacter = function (character, promptList) {
@ -748,10 +754,10 @@ const openAiDefaultPrompts = {
}; };
const openAiDefaultPromptLists = { const openAiDefaultPromptLists = {
"prompt_lists": [ "prompt_lists": []
{ };
"character_id": "default",
"list": [ const openAiDefaultPromptList = [
{ {
"identifier": "worldInfoBefore", "identifier": "worldInfoBefore",
"enabled": true "enabled": true
@ -796,10 +802,7 @@ const openAiDefaultPromptLists = {
"identifier": "jailbreak", "identifier": "jailbreak",
"enabled": false "enabled": false
} }
] ];
}
]
};
const defaultPromptManagerSettings = { const defaultPromptManagerSettings = {
"prompt_manager_settings": { "prompt_manager_settings": {