Refactor naming scheme for default promptmanager defaults

This commit is contained in:
maver 2023-07-20 19:49:38 +02:00
parent 4f734d12ab
commit dfd49813af
2 changed files with 23 additions and 23 deletions

View File

@ -442,7 +442,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
if (false === userChoice) return; if (false === userChoice) return;
this.removePromptListForCharacter(this.activeCharacter); this.removePromptListForCharacter(this.activeCharacter);
this.addPromptListForCharacter(this.activeCharacter, openAiDefaultPromptList); this.addPromptListForCharacter(this.activeCharacter, promptManagerDefaultPromptList);
this.saveServiceSettings().then(() => this.render()); this.saveServiceSettings().then(() => this.render());
}); });
@ -631,11 +631,11 @@ PromptManagerModule.prototype.sanitizeServiceSettings = function () {
// Check whether the referenced prompts are present. // Check whether the referenced prompts are present.
this.serviceSettings.prompts.length === 0 this.serviceSettings.prompts.length === 0
? this.setPrompts(openAiDefaultPrompts.prompts) ? this.setPrompts(chatCompletionDefaultPrompts.prompts)
: this.checkForMissingPrompts(this.serviceSettings.prompts); : this.checkForMissingPrompts(this.serviceSettings.prompts);
// Add prompt manager settings if not present // Add prompt manager settings if not present
this.serviceSettings.prompt_manager_settings = this.serviceSettings.prompt_manager_settings ?? {...defaultPromptManagerSettings}; this.serviceSettings.prompt_manager_settings = this.serviceSettings.prompt_manager_settings ?? {...promptManagerDefaultSettings};
// Add identifiers if there are none assigned to a prompt // Add identifiers if there are none assigned to a prompt
this.serviceSettings.prompts.forEach(prompt => prompt && (prompt.identifier = prompt.identifier ?? this.getUuidv4())); this.serviceSettings.prompts.forEach(prompt => prompt && (prompt.identifier = prompt.identifier ?? this.getUuidv4()));
@ -653,14 +653,14 @@ PromptManagerModule.prototype.sanitizeServiceSettings = function () {
}; };
PromptManagerModule.prototype.checkForMissingPrompts = function(prompts) { PromptManagerModule.prototype.checkForMissingPrompts = function(prompts) {
const defaultPromptIdentifiers = openAiDefaultPrompts.prompts.reduce((list, prompt) => { list.push(prompt.identifier); return list;}, []); const defaultPromptIdentifiers = chatCompletionDefaultPrompts.prompts.reduce((list, prompt) => { list.push(prompt.identifier); return list;}, []);
const missingIdentifiers = defaultPromptIdentifiers.filter(identifier => const missingIdentifiers = defaultPromptIdentifiers.filter(identifier =>
!prompts.some(prompt =>prompt.identifier === identifier) !prompts.some(prompt =>prompt.identifier === identifier)
); );
missingIdentifiers.forEach(identifier => { missingIdentifiers.forEach(identifier => {
const defaultPrompt = openAiDefaultPrompts.prompts.find(prompt => prompt?.identifier === identifier); const defaultPrompt = chatCompletionDefaultPrompts.prompts.find(prompt => prompt?.identifier === identifier);
if (defaultPrompt) { if (defaultPrompt) {
prompts.push(defaultPrompt); prompts.push(defaultPrompt);
this.log(`Missing system prompt: ${defaultPrompt.identifier}. Added default.`); this.log(`Missing system prompt: ${defaultPrompt.identifier}. Added default.`);
@ -727,7 +727,7 @@ PromptManagerModule.prototype.handleCharacterSelected = function (event) {
// ToDo: These should be passed as parameter or attached to the manager as a set of default options. // 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. // Set default prompts and order for character.
if (0 === promptList.length) this.addPromptListForCharacter(this.activeCharacter, openAiDefaultPromptList); if (0 === promptList.length) this.addPromptListForCharacter(this.activeCharacter, promptManagerDefaultPromptList);
} }
PromptManagerModule.prototype.handleCharacterUpdated = function (event) { PromptManagerModule.prototype.handleCharacterUpdated = function (event) {
@ -739,7 +739,7 @@ PromptManagerModule.prototype.handleGroupSelected = function (event) {
this.activeCharacter = characterDummy; this.activeCharacter = characterDummy;
const promptList = this.getPromptListForCharacter(characterDummy); const promptList = this.getPromptListForCharacter(characterDummy);
if (0 === promptList.length) this.addPromptListForCharacter(characterDummy, openAiDefaultPromptList) if (0 === promptList.length) this.addPromptListForCharacter(characterDummy, promptManagerDefaultPromptList)
} }
PromptManagerModule.prototype.getActiveGroupCharacters = function() { PromptManagerModule.prototype.getActiveGroupCharacters = function() {
@ -1469,7 +1469,7 @@ PromptManagerModule.prototype.profileEnd = function (identifier) {
} }
const openAiDefaultPrompts = { const chatCompletionDefaultPrompts = {
"prompts": [ "prompts": [
{ {
"name": "Main Prompt", "name": "Main Prompt",
@ -1545,11 +1545,11 @@ const openAiDefaultPrompts = {
] ]
}; };
const openAiDefaultPromptLists = { const promptManagerDefaultPromptLists = {
"prompt_lists": [] "prompt_lists": []
}; };
const openAiDefaultPromptList = [ const promptManagerDefaultPromptList = [
{ {
"identifier": "main", "identifier": "main",
"enabled": true "enabled": true
@ -1596,7 +1596,7 @@ const openAiDefaultPromptList = [
} }
]; ];
const defaultPromptManagerSettings = { const promptManagerDefaultSettings = {
prompt_manager_settings: { prompt_manager_settings: {
showAdvancedSettings: false showAdvancedSettings: false
} }
@ -1605,8 +1605,8 @@ const defaultPromptManagerSettings = {
export { export {
PromptManagerModule, PromptManagerModule,
registerPromptManagerMigration, registerPromptManagerMigration,
openAiDefaultPrompts, chatCompletionDefaultPrompts,
openAiDefaultPromptLists, promptManagerDefaultPromptLists,
defaultPromptManagerSettings, promptManagerDefaultSettings,
Prompt Prompt
}; };

View File

@ -28,9 +28,9 @@ import {
import {groups, selected_group} from "./group-chats.js"; import {groups, selected_group} from "./group-chats.js";
import { import {
defaultPromptManagerSettings, promptManagerDefaultSettings,
openAiDefaultPromptLists, promptManagerDefaultPromptLists,
openAiDefaultPrompts, Prompt, chatCompletionDefaultPrompts, Prompt,
PromptManagerModule as PromptManager PromptManagerModule as PromptManager
} from "./PromptManager.js"; } from "./PromptManager.js";
@ -144,9 +144,9 @@ const default_settings = {
openai_max_tokens: 300, openai_max_tokens: 300,
wrap_in_quotes: false, wrap_in_quotes: false,
names_in_completion: false, names_in_completion: false,
...openAiDefaultPrompts, ...chatCompletionDefaultPrompts,
...openAiDefaultPromptLists, ...promptManagerDefaultPromptLists,
...defaultPromptManagerSettings, ...promptManagerDefaultSettings,
send_if_empty: '', send_if_empty: '',
impersonation_prompt: default_impersonation_prompt, impersonation_prompt: default_impersonation_prompt,
new_chat_prompt: default_new_chat_prompt, new_chat_prompt: default_new_chat_prompt,
@ -183,9 +183,9 @@ const oai_settings = {
openai_max_tokens: 300, openai_max_tokens: 300,
wrap_in_quotes: false, wrap_in_quotes: false,
names_in_completion: false, names_in_completion: false,
...openAiDefaultPrompts, ...chatCompletionDefaultPrompts,
...openAiDefaultPromptLists, ...promptManagerDefaultPromptLists,
...defaultPromptManagerSettings, ...promptManagerDefaultSettings,
send_if_empty: '', send_if_empty: '',
impersonation_prompt: default_impersonation_prompt, impersonation_prompt: default_impersonation_prompt,
new_chat_prompt: default_new_chat_prompt, new_chat_prompt: default_new_chat_prompt,