mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Prevent new example chat message being added for no reason
This commit is contained in:
@ -479,14 +479,8 @@ function populateChatHistory(prompts, chatCompletion, type = null, cyclePrompt =
|
|||||||
function populateDialogueExamples(prompts, chatCompletion) {
|
function populateDialogueExamples(prompts, chatCompletion) {
|
||||||
chatCompletion.add(new MessageCollection('dialogueExamples'), prompts.index('dialogueExamples'));
|
chatCompletion.add(new MessageCollection('dialogueExamples'), prompts.index('dialogueExamples'));
|
||||||
if (openai_msgs_example.length) {
|
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 newExampleChat = new Message('system', oai_settings.new_example_chat_prompt, 'newChat');
|
||||||
const dialogueExampleChat = new Message('system', oai_settings.new_example_chat_prompt, 'newChat');
|
chatCompletion.reserveBudget(newExampleChat);
|
||||||
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');
|
|
||||||
|
|
||||||
[...openai_msgs_example].forEach((dialogue, dialogueIndex) => {
|
[...openai_msgs_example].forEach((dialogue, dialogueIndex) => {
|
||||||
dialogue.forEach((prompt, promptIndex) => {
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user