mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #175 from gidzzz/fix-examples-positioning
Consistent positioning and formatting of pinned examples
This commit is contained in:
@@ -1465,12 +1465,8 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
if (count_view_mes < topAnchorDepth) {
|
if (count_view_mes < topAnchorDepth) {
|
||||||
storyString += appendToStoryString(charPersonality, power_user.disable_personality_formatting ? '' : name2 + "'s personality: ");
|
storyString += appendToStoryString(charPersonality, power_user.disable_personality_formatting ? '' : name2 + "'s personality: ");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (power_user.pin_examples && main_api !== 'openai') {
|
storyString += appendToStoryString(Scenario, power_user.disable_scenario_formatting ? '' : 'Circumstances and context of the dialogue: ');
|
||||||
for (let example of mesExamplesArray) {
|
|
||||||
storyString += appendToStoryString(example, '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pygmalion does that anyway
|
// Pygmalion does that anyway
|
||||||
@@ -1577,48 +1573,46 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
chat2.push('');
|
chat2.push('');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect enough messages to fill the context
|
let examplesString = '';
|
||||||
let chatString = '';
|
let chatString = '';
|
||||||
|
function canFitMessages() {
|
||||||
|
const encodeString = JSON.stringify(worldInfoString + storyString + examplesString + chatString + anchorTop + anchorBottom + charPersonality + promptBias + allAnchors);
|
||||||
|
return getTokenCount(encodeString, padding_tokens) < this_max_context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force pinned examples into the context
|
||||||
|
let pinExmString;
|
||||||
|
if (power_user.pin_examples) {
|
||||||
|
pinExmString = examplesString = mesExamplesArray.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect enough messages to fill the context
|
||||||
let arrMes = [];
|
let arrMes = [];
|
||||||
for (let item of chat2) {
|
for (let item of chat2) {
|
||||||
chatString = item + chatString;
|
chatString = item + chatString;
|
||||||
const encodeString = JSON.stringify(
|
if (canFitMessages()) { //(The number of tokens in the entire promt) need fix, it must count correctly (added +120, so that the description of the character does not hide)
|
||||||
worldInfoString + storyString + chatString +
|
|
||||||
anchorTop + anchorBottom +
|
|
||||||
charPersonality + promptBias + allAnchors
|
|
||||||
);
|
|
||||||
const tokenCount = getTokenCount(encodeString, padding_tokens);
|
|
||||||
if (tokenCount < this_max_context) { //(The number of tokens in the entire promt) need fix, it must count correctly (added +120, so that the description of the character does not hide)
|
|
||||||
//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 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await delay(1); //For disable slow down (encode gpt-2 need fix)
|
await delay(1); //For disable slow down (encode gpt-2 need fix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Estimate how many unpinned example messages fit in the context
|
// Estimate how many unpinned example messages fit in the context
|
||||||
let count_exm_add = 0;
|
let count_exm_add = 0;
|
||||||
if (!power_user.pin_examples) {
|
if (!power_user.pin_examples) {
|
||||||
let mesExmString = '';
|
|
||||||
for (let example of mesExamplesArray) {
|
for (let example of mesExamplesArray) {
|
||||||
mesExmString += example;
|
examplesString += example;
|
||||||
const prompt = JSON.stringify(worldInfoString + storyString + mesExmString + chatString + anchorTop + anchorBottom + charPersonality + promptBias + allAnchors);
|
if (canFitMessages()) {
|
||||||
const tokenCount = getTokenCount(prompt, padding_tokens);
|
|
||||||
if (tokenCount < this_max_context) {
|
|
||||||
count_exm_add++;
|
count_exm_add++;
|
||||||
await delay(1);
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
await delay(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_pygmalion && Scenario && Scenario.length > 0) {
|
|
||||||
storyString += !power_user.disable_scenario_formatting ? `Circumstances and context of the dialogue: ${Scenario}\n` : `${Scenario}\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mesSend = [];
|
let mesSend = [];
|
||||||
console.log('calling runGenerate');
|
console.log('calling runGenerate');
|
||||||
await runGenerate();
|
await runGenerate();
|
||||||
@@ -1692,15 +1686,12 @@ async function Generate(type, automatic_trigger, force_name2) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let mesSendString = '';
|
|
||||||
let mesExmString = '';
|
let mesExmString = '';
|
||||||
|
let mesSendString = '';
|
||||||
|
|
||||||
function setPromtString() {
|
function setPromtString() {
|
||||||
|
mesExmString = pinExmString ?? mesExamplesArray.slice(0, count_exm_add).join('');
|
||||||
mesSendString = '';
|
mesSendString = '';
|
||||||
mesExmString = '';
|
|
||||||
for (let j = 0; j < count_exm_add; j++) {
|
|
||||||
mesExmString += mesExamplesArray[j];
|
|
||||||
}
|
|
||||||
for (let j = 0; j < mesSend.length; j++) {
|
for (let j = 0; j < mesSend.length; j++) {
|
||||||
|
|
||||||
mesSendString += mesSend[j];
|
mesSendString += mesSend[j];
|
||||||
|
Reference in New Issue
Block a user