Let prompt manager control messages sent to openai

This commit is contained in:
maver 2023-05-28 15:55:52 +02:00
parent c6eee88cd4
commit ded29a225d
1 changed files with 22 additions and 2 deletions

View File

@ -374,6 +374,8 @@ async function prepareOpenAIMessages({ systemPrompt, name2, storyString, worldIn
enhance_definitions_prompt = "If you have more knowledge of " + name2 + ", add to the character's lore and personality to enhance them but keep the Character Sheet's definitions absolute.";
}
const characterInfo = storyString;
const wiBefore = formatWorldInfo(worldInfoBefore);
const wiAfter = formatWorldInfo(worldInfoAfter);
@ -535,11 +537,29 @@ async function prepareOpenAIMessages({ systemPrompt, name2, storyString, worldIn
}
}
const chatCompletion = promptManager.getChatCompletion();
chatCompletion.replace('worldInfoBefore', {role: "system", content: wiBefore});
chatCompletion.replace('worldInfoAfter', {role: "system", content: wiAfter});
chatCompletion.replace('characterInfo', {role: 'system', content: characterInfo});
chatCompletion.replace('newExampleChat', new_chat_msg);
chatCompletion.replace('newMainChat', new_chat_msg);
chatCompletion.replace('chatHistory', openai_msgs);
const flattenedExampleMessages = 0 !== openai_msgs_example.length ? openai_msgs_example.reduce( (examples, obj) => [...examples, ...obj]) : [];
chatCompletion.replace('dialogueExamples', flattenedExampleMessages);
chatCompletion.insertAfter('characterInfo', 'enhancedDefinitions', {role: 'system', content: enhance_definitions_prompt});
chatCompletion.insertAfter('worldInfoAfter', 'extensionPrompt', extensionPrompt);
openai_messages_count = openai_msgs_tosend.filter(x => x.role == "user" || x.role == "assistant").length + openai_narrator_messages_count;
// reverse the messages array because we had the newest at the top to remove the oldest,
// now we want proper order
openai_msgs_tosend.reverse();
openai_msgs_tosend = [prompt_msg, ...examples_tosend, new_chat_msg, ...openai_msgs_tosend]
//openai_msgs_tosend.reverse();
//openai_msgs_tosend = [prompt_msg, ...examples_tosend, new_chat_msg, ...openai_msgs_tosend]
openai_msgs_tosend = chatCompletion.getChat();
//console.log("We're sending this:")
//console.log(openai_msgs_tosend);