mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#321 Predict trailing asterisk during streaming
This commit is contained in:
@ -107,7 +107,7 @@ import {
|
|||||||
setPoeOnlineStatus,
|
setPoeOnlineStatus,
|
||||||
} from "./scripts/poe.js";
|
} from "./scripts/poe.js";
|
||||||
|
|
||||||
import { debounce, delay, restoreCaretPosition, saveCaretPosition, end_trim_to_sentence } from "./scripts/utils.js";
|
import { debounce, delay, restoreCaretPosition, saveCaretPosition, end_trim_to_sentence, countOccurrences, isOdd } from "./scripts/utils.js";
|
||||||
import { extension_settings, loadExtensionSettings } from "./scripts/extensions.js";
|
import { extension_settings, loadExtensionSettings } from "./scripts/extensions.js";
|
||||||
import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js";
|
import { executeSlashCommands, getSlashCommandsHelp, registerSlashCommand } from "./scripts/slash-commands.js";
|
||||||
import {
|
import {
|
||||||
@ -1516,6 +1516,12 @@ class StreamingProcessor {
|
|||||||
let isName = result.this_mes_is_name;
|
let isName = result.this_mes_is_name;
|
||||||
processedText = result.getMessage;
|
processedText = result.getMessage;
|
||||||
|
|
||||||
|
// Predict unbalanced asterisks during streaming
|
||||||
|
if (!isFinal && isOdd(countOccurrences(processedText, '*'))) {
|
||||||
|
// Add asterisk at the end to balance it
|
||||||
|
processedText = processedText.trimEnd() + '*';
|
||||||
|
}
|
||||||
|
|
||||||
if (isImpersonate) {
|
if (isImpersonate) {
|
||||||
$('#send_textarea').val(processedText).trigger('input');
|
$('#send_textarea').val(processedText).trigger('input');
|
||||||
}
|
}
|
||||||
|
@ -216,3 +216,19 @@ export function end_trim_to_sentence(input, include_newline = false) {
|
|||||||
|
|
||||||
return input.substring(0, last + 1).trimEnd();
|
return input.substring(0, last + 1).trimEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function countOccurrences(string, character) {
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < string.length; i++) {
|
||||||
|
if (string[i] === character) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isOdd(number) {
|
||||||
|
return number % 2 !== 0;
|
||||||
|
}
|
Reference in New Issue
Block a user