Skip to content

Commit

Permalink
Keep replacing until mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
lmg-anon committed May 24, 2024
1 parent 6ef08d0 commit 711de05
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions mikupad.html
Original file line number Diff line number Diff line change
Expand Up @@ -3879,28 +3879,46 @@
const additionalContextPrompt = assembleAdditionalContext(assembledWorldInfo, promptText);
const finalPrompt = assembleFinalPrompt(additionalContextPrompt);

let isReplacing = false;
predict(finalPrompt, leftPromptChunks.length, (chunk) => {
let stop = false;
let omitChunk = false;

let wasReplacing = isReplacing;
isReplacing = false;

if (rightPromptChunks[0]) {
const trimmedChunk = chunk.content.replace(/^ +| +$/gm, "")
if (trimmedChunk[0] == rightPromptChunks[0].content[0]) {
const trimmedChunk = chunk.content.replace(/^ /, "");
if (rightPromptChunks[0].content[0] === chunk.content[0] ||
rightPromptChunks[0].content[0] === trimmedChunk[0]
) {
omitChunk = true;
if (chunk.content[0] == ' ' && rightPromptChunks[0].content[0] != ' ') {
if (rightPromptChunks[0].type !== 'user')
console.warn("Predicted token changed, this shouldn't happen.");
rightPromptChunks[0].content = ' ' + rightPromptChunks[0].content;
} else if (rightPromptChunks[0].type === 'user') {
if (rightPromptChunks[0].content === chunk.content) {
rightPromptChunks[0] = chunk;
} else if (rightPromptChunks[0].content.startsWith(chunk.content)) {
}
if (rightPromptChunks[0].type === 'user') {
if (rightPromptChunks[0].content.startsWith(chunk.content)) {
rightPromptChunks[0].content = rightPromptChunks[0].content.substring(chunk.content.length);
if (!rightPromptChunks[0].content)
rightPromptChunks.shift();
omitChunk = false;
isReplacing = true;
}
}
stop = true;
}
}


// When replacing, we continue until any mismatch.
if (wasReplacing && !isReplacing) {
if (rightPromptChunks.length !== 0)
return false;
// This means that the mismatch was caused by the end of the chunks to be replaced.
isReplacing = false;
}

if (!omitChunk) {
setTokens(t => t + (chunk?.completion_probabilities?.length ?? 1));
leftPromptChunks.push(chunk);
Expand All @@ -3910,7 +3928,7 @@
...rightPromptChunks
]);

return !stop;
return !stop || isReplacing;
});

return true;
Expand Down

0 comments on commit 711de05

Please sign in to comment.