mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Parse reasoning in multi-swipe swipes
This commit is contained in:
@ -1048,6 +1048,32 @@ function parseReasoningFromString(str, { strict = true } = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse reasoning in an array of swipe strings if auto-parsing is enabled.
|
||||
* @param {string[]} swipes Array of swipe strings
|
||||
* @param {{extra: {reasoning: string, reasoning_duration: number}}[]} swipeInfoArray Array of swipe info objects
|
||||
* @param {number?} duration Duration of the reasoning
|
||||
*/
|
||||
export function parseReasoningInSwipes(swipes, swipeInfoArray, duration) {
|
||||
if (!power_user.reasoning.auto_parse) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Something ain't right, don't parse
|
||||
if (!Array.isArray(swipes) || !Array.isArray(swipeInfoArray) || swipes.length !== swipeInfoArray.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let index = 0; index < swipes.length; index++) {
|
||||
const parsedReasoning = parseReasoningFromString(swipes[index]);
|
||||
if (parsedReasoning) {
|
||||
swipes[index] = parsedReasoning.content;
|
||||
swipeInfoArray[index].extra.reasoning = parsedReasoning.reasoning;
|
||||
swipeInfoArray[index].extra.reasoning_duration = duration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function registerReasoningAppEvents() {
|
||||
const eventHandler = (/** @type {number} */ idx) => {
|
||||
if (!power_user.reasoning.auto_parse) {
|
||||
|
Reference in New Issue
Block a user