mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-12 17:36:22 +01:00
Prevent new example chat message being added for no reason
This commit is contained in:
parent
a9fa42524d
commit
03b8bb64fa
@ -479,14 +479,8 @@ function populateChatHistory(prompts, chatCompletion, type = null, cyclePrompt =
|
||||
function populateDialogueExamples(prompts, chatCompletion) {
|
||||
chatCompletion.add(new MessageCollection('dialogueExamples'), prompts.index('dialogueExamples'));
|
||||
if (openai_msgs_example.length) {
|
||||
// Insert chat message examples if there's enough budget if there is enough budget left for at least one example.
|
||||
const dialogueExampleChat = new Message('system', oai_settings.new_example_chat_prompt, 'newChat');
|
||||
const prompt = openai_msgs_example[0];
|
||||
const dialogueExample = new Message(prompt[0]?.role || 'system', prompt[0]?.content || '', 'dialogueExampleTest');
|
||||
|
||||
if (chatCompletion.canAfford(dialogueExampleChat) &&
|
||||
chatCompletion.canAfford(dialogueExample)) {
|
||||
chatCompletion.insert(dialogueExampleChat, 'dialogueExamples');
|
||||
const newExampleChat = new Message('system', oai_settings.new_example_chat_prompt, 'newChat');
|
||||
chatCompletion.reserveBudget(newExampleChat);
|
||||
|
||||
[...openai_msgs_example].forEach((dialogue, dialogueIndex) => {
|
||||
dialogue.forEach((prompt, promptIndex) => {
|
||||
@ -500,7 +494,11 @@ function populateDialogueExamples(prompts, chatCompletion) {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
chatCompletion.freeBudget(newExampleChat);
|
||||
|
||||
const chatExamples = chatCompletion.getMessages().getItemByIdentifier('dialogueExamples').getCollection();
|
||||
if(chatExamples.length) chatCompletion.insertAtStart(newExampleChat,'dialogueExamples');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user