mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Cache and sample classification results
This commit is contained in:
@ -438,9 +438,9 @@ export function sortByCssOrder(a, b) {
|
||||
* @param {boolean} include_newline Whether to include a newline character in the trimmed string.
|
||||
* @returns {string} The trimmed string.
|
||||
* @example
|
||||
* end_trim_to_sentence('Hello, world! I am from'); // 'Hello, world!'
|
||||
* trimToEndSentence('Hello, world! I am from'); // 'Hello, world!'
|
||||
*/
|
||||
export function end_trim_to_sentence(input, include_newline = false) {
|
||||
export function trimToEndSentence(input, include_newline = false) {
|
||||
const punctuation = new Set(['.', '!', '?', '*', '"', ')', '}', '`', ']', '$', '。', '!', '?', '”', ')', '】', '】', '’', '」', '】']); // extend this as you see fit
|
||||
let last = -1;
|
||||
|
||||
@ -465,6 +465,26 @@ export function end_trim_to_sentence(input, include_newline = false) {
|
||||
return input.substring(0, last + 1).trimEnd();
|
||||
}
|
||||
|
||||
export function trimToStartSentence(input) {
|
||||
let p1 = input.indexOf(".");
|
||||
let p2 = input.indexOf("!");
|
||||
let p3 = input.indexOf("?");
|
||||
let p4 = input.indexOf("\n");
|
||||
let first = p1;
|
||||
let skip1 = false;
|
||||
if (p2 > 0 && p2 < first) { first = p2; }
|
||||
if (p3 > 0 && p3 < first) { first = p3; }
|
||||
if (p4 > 0 && p4 < first) { first = p4; skip1 = true; }
|
||||
if (first > 0) {
|
||||
if (skip1) {
|
||||
return input.substring(first + 1);
|
||||
} else {
|
||||
return input.substring(first + 2);
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of occurrences of a character in a string.
|
||||
* @param {string} string The string to count occurrences in.
|
||||
|
Reference in New Issue
Block a user