mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into text-completion-include-reasoning
This commit is contained in:
@@ -2003,7 +2003,7 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number(messageId) === 0 && !isSystem && !isUser) {
|
if (Number(messageId) === 0 && !isSystem && !isUser && !isReasoning) {
|
||||||
const mesBeforeReplace = mes;
|
const mesBeforeReplace = mes;
|
||||||
const chatMessage = chat[messageId];
|
const chatMessage = chat[messageId];
|
||||||
mes = substituteParams(mes, undefined, ch_name);
|
mes = substituteParams(mes, undefined, ch_name);
|
||||||
@@ -3171,7 +3171,7 @@ class StreamingProcessor {
|
|||||||
this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true }));
|
this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await saveReply(this.type, text, true);
|
await saveReply(this.type, text, true, '', [], '');
|
||||||
messageId = chat.length - 1;
|
messageId = chat.length - 1;
|
||||||
this.#checkDomElements(messageId);
|
this.#checkDomElements(messageId);
|
||||||
this.showMessageButtons(messageId);
|
this.showMessageButtons(messageId);
|
||||||
@@ -3365,7 +3365,7 @@ class StreamingProcessor {
|
|||||||
const timestamps = [];
|
const timestamps = [];
|
||||||
for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) {
|
for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) {
|
||||||
timestamps.push(Date.now());
|
timestamps.push(Date.now());
|
||||||
if (this.isStopped) {
|
if (this.isStopped || this.abortController.signal.aborted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3863,10 +3863,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
|
|
||||||
const reasoning = new PromptReasoning();
|
const reasoning = new PromptReasoning();
|
||||||
for (let i = coreChat.length - 1; i >= 0; i--) {
|
for (let i = coreChat.length - 1; i >= 0; i--) {
|
||||||
if (reasoning.isLimitReached()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const depth = coreChat.length - i - 1;
|
const depth = coreChat.length - i - 1;
|
||||||
|
const isPrefix = isContinue && i === coreChat.length - 1;
|
||||||
coreChat[i] = {
|
coreChat[i] = {
|
||||||
...coreChat[i],
|
...coreChat[i],
|
||||||
mes: reasoning.addToMessage(
|
mes: reasoning.addToMessage(
|
||||||
@@ -3876,8 +3874,12 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
regex_placement.REASONING,
|
regex_placement.REASONING,
|
||||||
{ isPrompt: true, depth: depth },
|
{ isPrompt: true, depth: depth },
|
||||||
),
|
),
|
||||||
|
isPrefix,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
if (reasoning.isLimitReached()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine token limit
|
// Determine token limit
|
||||||
|
@@ -96,8 +96,13 @@ function highlightLockedBackground() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locks the background for the current chat
|
||||||
|
* @param {Event} e Click event
|
||||||
|
* @returns {string} Empty string
|
||||||
|
*/
|
||||||
function onLockBackgroundClick(e) {
|
function onLockBackgroundClick(e) {
|
||||||
e.stopPropagation();
|
e?.stopPropagation();
|
||||||
|
|
||||||
const chatName = getCurrentChatId();
|
const chatName = getCurrentChatId();
|
||||||
|
|
||||||
@@ -114,8 +119,13 @@ function onLockBackgroundClick(e) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locks the background for the current chat
|
||||||
|
* @param {Event} e Click event
|
||||||
|
* @returns {string} Empty string
|
||||||
|
*/
|
||||||
function onUnlockBackgroundClick(e) {
|
function onUnlockBackgroundClick(e) {
|
||||||
e.stopPropagation();
|
e?.stopPropagation();
|
||||||
removeBackgroundMetadata();
|
removeBackgroundMetadata();
|
||||||
unsetCustomBackground();
|
unsetCustomBackground();
|
||||||
highlightLockedBackground();
|
highlightLockedBackground();
|
||||||
@@ -513,12 +523,12 @@ export function initBackgrounds() {
|
|||||||
$('#add_bg_button').on('change', onBackgroundUploadSelected);
|
$('#add_bg_button').on('change', onBackgroundUploadSelected);
|
||||||
$('#bg-filter').on('input', onBackgroundFilterInput);
|
$('#bg-filter').on('input', onBackgroundFilterInput);
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'lockbg',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'lockbg',
|
||||||
callback: onLockBackgroundClick,
|
callback: () => onLockBackgroundClick(new CustomEvent('click')),
|
||||||
aliases: ['bglock'],
|
aliases: ['bglock'],
|
||||||
helpString: 'Locks a background for the currently selected chat',
|
helpString: 'Locks a background for the currently selected chat',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'unlockbg',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'unlockbg',
|
||||||
callback: onUnlockBackgroundClick,
|
callback: () => onUnlockBackgroundClick(new CustomEvent('click')),
|
||||||
aliases: ['bgunlock'],
|
aliases: ['bgunlock'],
|
||||||
helpString: 'Unlocks a background for the currently selected chat',
|
helpString: 'Unlocks a background for the currently selected chat',
|
||||||
}));
|
}));
|
||||||
|
@@ -50,11 +50,12 @@ export class PromptReasoning {
|
|||||||
* Add reasoning to a message according to the power user settings.
|
* Add reasoning to a message according to the power user settings.
|
||||||
* @param {string} content Message content
|
* @param {string} content Message content
|
||||||
* @param {string} reasoning Message reasoning
|
* @param {string} reasoning Message reasoning
|
||||||
|
* @param {boolean} isPrefix Whether this is the last message prefix
|
||||||
* @returns {string} Message content with reasoning
|
* @returns {string} Message content with reasoning
|
||||||
*/
|
*/
|
||||||
addToMessage(content, reasoning) {
|
addToMessage(content, reasoning, isPrefix) {
|
||||||
// Disabled or reached limit of additions
|
// Disabled or reached limit of additions
|
||||||
if (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions) {
|
if (!isPrefix && (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions)) {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +72,11 @@ export class PromptReasoning {
|
|||||||
const separator = substituteParams(power_user.reasoning.separator || '');
|
const separator = substituteParams(power_user.reasoning.separator || '');
|
||||||
const suffix = substituteParams(power_user.reasoning.suffix || '');
|
const suffix = substituteParams(power_user.reasoning.suffix || '');
|
||||||
|
|
||||||
|
// Combine parts with reasoning only
|
||||||
|
if (isPrefix && !content) {
|
||||||
|
return `${prefix}${reasoning}`;
|
||||||
|
}
|
||||||
|
|
||||||
// Combine parts with reasoning and content
|
// Combine parts with reasoning and content
|
||||||
return `${prefix}${reasoning}${suffix}${separator}${content}`;
|
return `${prefix}${reasoning}${suffix}${separator}${content}`;
|
||||||
}
|
}
|
||||||
@@ -117,6 +123,7 @@ function loadReasoningSettings() {
|
|||||||
function registerReasoningSlashCommands() {
|
function registerReasoningSlashCommands() {
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'reasoning-get',
|
name: 'reasoning-get',
|
||||||
|
aliases: ['get-reasoning'],
|
||||||
returns: ARGUMENT_TYPE.STRING,
|
returns: ARGUMENT_TYPE.STRING,
|
||||||
helpString: t`Get the contents of a reasoning block of a message. Returns an empty string if the message does not have a reasoning block.`,
|
helpString: t`Get the contents of a reasoning block of a message. Returns an empty string if the message does not have a reasoning block.`,
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
@@ -136,6 +143,7 @@ function registerReasoningSlashCommands() {
|
|||||||
|
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'reasoning-set',
|
name: 'reasoning-set',
|
||||||
|
aliases: ['set-reasoning'],
|
||||||
returns: ARGUMENT_TYPE.STRING,
|
returns: ARGUMENT_TYPE.STRING,
|
||||||
helpString: t`Set the reasoning block of a message. Returns the reasoning block content.`,
|
helpString: t`Set the reasoning block of a message. Returns the reasoning block content.`,
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
@@ -170,6 +178,7 @@ function registerReasoningSlashCommands() {
|
|||||||
|
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'reasoning-parse',
|
name: 'reasoning-parse',
|
||||||
|
aliases: ['parse-reasoning'],
|
||||||
returns: 'reasoning string',
|
returns: 'reasoning string',
|
||||||
helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`,
|
helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`,
|
||||||
namedArgumentList: [
|
namedArgumentList: [
|
||||||
@@ -218,7 +227,7 @@ function registerReasoningMacros() {
|
|||||||
MacrosParser.registerMacro('reasoningSeparator', () => power_user.reasoning.separator, t`Reasoning Separator`);
|
MacrosParser.registerMacro('reasoningSeparator', () => power_user.reasoning.separator, t`Reasoning Separator`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setReasoningEventHandlers(){
|
function setReasoningEventHandlers() {
|
||||||
$(document).on('click', '.mes_reasoning_copy', (e) => {
|
$(document).on('click', '.mes_reasoning_copy', (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@@ -54,6 +54,12 @@ const OPENROUTER_PROVIDERS = [
|
|||||||
'xAI',
|
'xAI',
|
||||||
'Cloudflare',
|
'Cloudflare',
|
||||||
'SF Compute',
|
'SF Compute',
|
||||||
|
'Minimax',
|
||||||
|
'Nineteen',
|
||||||
|
'Liquid',
|
||||||
|
'Nebius',
|
||||||
|
'Chutes',
|
||||||
|
'Kluster',
|
||||||
'01.AI',
|
'01.AI',
|
||||||
'HuggingFace',
|
'HuggingFace',
|
||||||
'Mancer',
|
'Mancer',
|
||||||
|
@@ -533,6 +533,7 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => {
|
|||||||
|
|
||||||
comfy.post('/generate', jsonParser, async (request, response) => {
|
comfy.post('/generate', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
|
let item;
|
||||||
const url = new URL(urlJoin(request.body.url, '/prompt'));
|
const url = new URL(urlJoin(request.body.url, '/prompt'));
|
||||||
|
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
@@ -557,7 +558,6 @@ comfy.post('/generate', jsonParser, async (request, response) => {
|
|||||||
/** @type {any} */
|
/** @type {any} */
|
||||||
const data = await promptResult.json();
|
const data = await promptResult.json();
|
||||||
const id = data.prompt_id;
|
const id = data.prompt_id;
|
||||||
let item;
|
|
||||||
const historyUrl = new URL(urlJoin(request.body.url, '/history'));
|
const historyUrl = new URL(urlJoin(request.body.url, '/history'));
|
||||||
while (true) {
|
while (true) {
|
||||||
const result = await fetch(historyUrl);
|
const result = await fetch(historyUrl);
|
||||||
|
Reference in New Issue
Block a user