mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-26 08:58:09 +01:00
Auto-complete code blocks during streaming
This commit is contained in:
parent
e4cb916dff
commit
7f8df9533b
@ -2185,11 +2185,12 @@ class StreamingProcessor {
|
||||
let processedText = cleanUpMessage(text, isImpersonate, isContinue, !isFinal);
|
||||
|
||||
// Predict unbalanced asterisks / quotes during streaming
|
||||
const charsToBalance = ['*', '"'];
|
||||
const charsToBalance = ['*', '"', '```'];
|
||||
for (const char of charsToBalance) {
|
||||
if (!isFinal && isOdd(countOccurrences(processedText, char))) {
|
||||
// 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;
|
||||
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
if (string[i] === character) {
|
||||
if (string.substring(i, i + character.length) === character) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user