Add prompt manager support for group chats
This commit is contained in:
parent
d9d10f3b00
commit
9a7bbd4ffb
|
@ -10,8 +10,12 @@ class IdentifierNotFoundError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
// OpenAI API chat message handling
|
||||
// const map = [{identifier: 'example', message: {role: 'system', content: 'exampleContent'}}, ...];
|
||||
/**
|
||||
* OpenAI API chat completion representation
|
||||
* const map = [{identifier: 'example', message: {role: 'system', content: 'exampleContent'}}, ...];
|
||||
*
|
||||
* @see https://platform.openai.com/docs/guides/gpt/chat-completions-api
|
||||
*/
|
||||
const ChatCompletion = {
|
||||
new() {
|
||||
return {
|
||||
|
@ -228,6 +232,12 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
|||
this.saveServiceSettings().then(() => this.render());
|
||||
});
|
||||
|
||||
// Re-render when the group changes.
|
||||
document.addEventListener('groupSelected', (event) => {
|
||||
this.handleGroupSelected(event)
|
||||
this.saveServiceSettings().then(() => this.render());
|
||||
});
|
||||
|
||||
// Sanitize settings after character has been deleted.
|
||||
document.addEventListener('characterDeleted', (event) => {
|
||||
this.handleCharacterDeleted(event)
|
||||
|
@ -297,7 +307,14 @@ PromptManagerModule.prototype.appendPrompt = function (prompt, character) {
|
|||
|
||||
if (-1 === index) promptList.push({identifier: prompt.identifier, enabled: false});
|
||||
}
|
||||
// Add a prompt to the current characters prompt list
|
||||
|
||||
/**
|
||||
* Append a prompt to the current characters prompt list
|
||||
*
|
||||
* @param {object} prompt
|
||||
* @param {object} character
|
||||
* @returns {void}
|
||||
*/
|
||||
PromptManagerModule.prototype.appendPrompt = function (prompt, character) {
|
||||
const promptList = this.getPromptListByCharacter(character);
|
||||
const index = promptList.findIndex(entry => entry.identifier === prompt.identifier);
|
||||
|
@ -414,6 +431,17 @@ PromptManagerModule.prototype.handleCharacterSelected = function (event) {
|
|||
if (0 === this.serviceSettings.prompts.length) this.setPrompts(openAiDefaultPrompts.prompts);
|
||||
}
|
||||
|
||||
PromptManagerModule.prototype.handleGroupSelected = function (event) {
|
||||
console.log(event.detail);
|
||||
|
||||
const characterDummy = {id: event.detail.id};
|
||||
this.activeCharacter = characterDummy;
|
||||
const promptList = this.getPromptListByCharacter(characterDummy);
|
||||
console.log(promptList);
|
||||
if (0 === promptList.length) this.addPromptListForCharacter(characterDummy, openAiDefaultPromptList)
|
||||
if (0 === this.serviceSettings.prompts.length) this.setPrompts(openAiDefaultPrompts.prompts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the prompts for a specific character. Can be filtered to only include enabled prompts.
|
||||
* @returns {object[]} The prompts for the character.
|
||||
|
|
|
@ -384,7 +384,8 @@ async function prepareOpenAIMessages({ systemPrompt, name2, storyString, worldIn
|
|||
const groupChatMessage = chatCompletion.makeSystemMessage(`[Start a new group chat. Group members: ${names}]`);
|
||||
const groupNudgeMessage = chatCompletion.makeSystemMessage(`[Write the next reply only as ${name2}]`);
|
||||
chatCompletion.replace('newMainChat', groupChatMessage)
|
||||
chatCompletion.insertAfter('newMainChat', 'groupNudgeMessage', groupNudgeMessage);
|
||||
chatCompletion.insertAfter('main', 'groupNudgeMessage', groupNudgeMessage);
|
||||
chatCompletion.remove('main'); // ToDo: Instead of removing, the main prompt could be altered to reinforce the situation being a group scene.
|
||||
}
|
||||
|
||||
// Handle NSFW prompt
|
||||
|
|
Loading…
Reference in New Issue