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) {
this.activeCharacter = {id: event.detail.id, ...event.detail.character};
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) {
@ -328,7 +330,11 @@ PromptManagerModule.prototype.getPromptsForCharacter = function (character, only
// Get the prompt order for a given character, otherwise an empty array is returned.
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) {
@ -748,10 +754,10 @@ const openAiDefaultPrompts = {
};
const openAiDefaultPromptLists = {
"prompt_lists": [
{
"character_id": "default",
"list": [
"prompt_lists": []
};
const openAiDefaultPromptList = [
{
"identifier": "worldInfoBefore",
"enabled": true
@ -796,10 +802,7 @@ const openAiDefaultPromptLists = {
"identifier": "jailbreak",
"enabled": false
}
]
}
]
};
];
const defaultPromptManagerSettings = {
"prompt_manager_settings": {