mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Simplify the message gathering loop
This commit is contained in:
@ -1592,11 +1592,9 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
chat2.push('');
|
chat2.push('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect enough messages to fill the context
|
||||||
let chatString = '';
|
let chatString = '';
|
||||||
let arrMes = [];
|
let arrMes = [];
|
||||||
let mesSend = [];
|
|
||||||
let count_exm_add = 0;
|
|
||||||
let i = 0;
|
|
||||||
for (let item of chat2) {
|
for (let item of chat2) {
|
||||||
chatString = item + chatString;
|
chatString = item + chatString;
|
||||||
const encodeString = JSON.stringify(
|
const encodeString = JSON.stringify(
|
||||||
@ -1609,46 +1607,41 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
//if (is_pygmalion && i == chat2.length-1) item='<START>\n'+item;
|
//if (is_pygmalion && i == chat2.length-1) item='<START>\n'+item;
|
||||||
arrMes[arrMes.length] = item;
|
arrMes[arrMes.length] = item;
|
||||||
} else {
|
} else {
|
||||||
console.log('reducing chat.length by 1');
|
break;
|
||||||
i = chat2.length - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await delay(1); //For disable slow down (encode gpt-2 need fix)
|
await delay(1); //For disable slow down (encode gpt-2 need fix)
|
||||||
// console.log(i+' '+chat.length);
|
}
|
||||||
|
|
||||||
count_exm_add = 0;
|
// Prepare unpinned example messages
|
||||||
|
let count_exm_add = 0;
|
||||||
if (i === chat2.length - 1) {
|
|
||||||
if (!power_user.pin_examples) {
|
if (!power_user.pin_examples) {
|
||||||
let mesExmString = '';
|
let mesExmString = '';
|
||||||
for (let iii = 0; iii < mesExamplesArray.length; iii++) {
|
for (let i = 0; i < mesExamplesArray.length; i++) {
|
||||||
mesExmString += mesExamplesArray[iii];
|
mesExmString += mesExamplesArray[i];
|
||||||
const prompt = JSON.stringify(worldInfoString + storyString + mesExmString + chatString + anchorTop + anchorBottom + charPersonality + promptBias + allAnchors);
|
const prompt = JSON.stringify(worldInfoString + storyString + mesExmString + chatString + anchorTop + anchorBottom + charPersonality + promptBias + allAnchors);
|
||||||
const tokenCount = getTokenCount(prompt, padding_tokens);
|
const tokenCount = getTokenCount(prompt, padding_tokens);
|
||||||
if (tokenCount < this_max_context) {
|
if (tokenCount < this_max_context) {
|
||||||
if (power_user.disable_examples_formatting) {
|
if (power_user.disable_examples_formatting) {
|
||||||
mesExamplesArray[iii] = mesExamplesArray[iii].replace(/<START>/i, '');
|
mesExamplesArray[i] = mesExamplesArray[i].replace(/<START>/i, '');
|
||||||
}
|
} else if (!is_pygmalion) {
|
||||||
|
mesExamplesArray[i] = mesExamplesArray[i].replace(/<START>/i, `This is how ${name2} should talk`);
|
||||||
if (!is_pygmalion) {
|
|
||||||
mesExamplesArray[iii] = mesExamplesArray[iii].replace(/<START>/i, `This is how ${name2} should talk`);
|
|
||||||
}
|
}
|
||||||
count_exm_add++;
|
count_exm_add++;
|
||||||
await delay(1);
|
await delay(1);
|
||||||
} else {
|
} else {
|
||||||
iii = mesExamplesArray.length;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_pygmalion && Scenario && Scenario.length > 0) {
|
if (!is_pygmalion && Scenario && Scenario.length > 0) {
|
||||||
storyString += !power_user.disable_scenario_formatting ? `Circumstances and context of the dialogue: ${Scenario}\n` : `${Scenario}\n`;
|
storyString += !power_user.disable_scenario_formatting ? `Circumstances and context of the dialogue: ${Scenario}\n` : `${Scenario}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mesSend = [];
|
||||||
console.log('calling runGenerate');
|
console.log('calling runGenerate');
|
||||||
await runGenerate();
|
await runGenerate();
|
||||||
return;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runGenerate(cycleGenerationPromt = '') {
|
async function runGenerate(cycleGenerationPromt = '') {
|
||||||
is_send_press = true;
|
is_send_press = true;
|
||||||
|
Reference in New Issue
Block a user