mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Auto-complete code blocks during streaming
This commit is contained in:
@ -2185,11 +2185,12 @@ class StreamingProcessor {
|
|||||||
let processedText = cleanUpMessage(text, isImpersonate, isContinue, !isFinal);
|
let processedText = cleanUpMessage(text, isImpersonate, isContinue, !isFinal);
|
||||||
|
|
||||||
// Predict unbalanced asterisks / quotes during streaming
|
// Predict unbalanced asterisks / quotes during streaming
|
||||||
const charsToBalance = ['*', '"'];
|
const charsToBalance = ['*', '"', '```'];
|
||||||
for (const char of charsToBalance) {
|
for (const char of charsToBalance) {
|
||||||
if (!isFinal && isOdd(countOccurrences(processedText, char))) {
|
if (!isFinal && isOdd(countOccurrences(processedText, char))) {
|
||||||
// Add character at the end to balance it
|
// Add character at the end to balance it
|
||||||
processedText = processedText.trimEnd() + char;
|
const separator = char.length > 1 ? '\n' : '';
|
||||||
|
processedText = processedText.trimEnd() + separator + char;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +498,7 @@ export function countOccurrences(string, character) {
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
for (let i = 0; i < string.length; i++) {
|
for (let i = 0; i < string.length; i++) {
|
||||||
if (string[i] === character) {
|
if (string.substring(i, i + character.length) === character) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user