mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add prompt manager support for group chats
This commit is contained in:
@ -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 = {
|
const ChatCompletion = {
|
||||||
new() {
|
new() {
|
||||||
return {
|
return {
|
||||||
@ -228,6 +232,12 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
|||||||
this.saveServiceSettings().then(() => this.render());
|
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.
|
// Sanitize settings after character has been deleted.
|
||||||
document.addEventListener('characterDeleted', (event) => {
|
document.addEventListener('characterDeleted', (event) => {
|
||||||
this.handleCharacterDeleted(event)
|
this.handleCharacterDeleted(event)
|
||||||
@ -297,7 +307,14 @@ PromptManagerModule.prototype.appendPrompt = function (prompt, character) {
|
|||||||
|
|
||||||
if (-1 === index) promptList.push({identifier: prompt.identifier, enabled: false});
|
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) {
|
PromptManagerModule.prototype.appendPrompt = function (prompt, character) {
|
||||||
const promptList = this.getPromptListByCharacter(character);
|
const promptList = this.getPromptListByCharacter(character);
|
||||||
const index = promptList.findIndex(entry => entry.identifier === prompt.identifier);
|
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);
|
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.
|
* Get the prompts for a specific character. Can be filtered to only include enabled prompts.
|
||||||
* @returns {object[]} The prompts for the character.
|
* @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 groupChatMessage = chatCompletion.makeSystemMessage(`[Start a new group chat. Group members: ${names}]`);
|
||||||
const groupNudgeMessage = chatCompletion.makeSystemMessage(`[Write the next reply only as ${name2}]`);
|
const groupNudgeMessage = chatCompletion.makeSystemMessage(`[Write the next reply only as ${name2}]`);
|
||||||
chatCompletion.replace('newMainChat', groupChatMessage)
|
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
|
// Handle NSFW prompt
|
||||||
|
Reference in New Issue
Block a user