Merge branch 'staging' into text-completion-include-reasoning
| @@ -2003,7 +2003,7 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san | |||
| 2003 | return ''; | 2003 | return ''; |
| 2004 | } | 2004 | } |
| 2005 | 2005 | ||
| 2006 | if (Number(messageId) === 0 && !isSystem && !isUser) { | 2006 | if (Number(messageId) === 0 && !isSystem && !isUser && !isReasoning) { |
| 2007 | const mesBeforeReplace = mes; | 2007 | const mesBeforeReplace = mes; |
| 2008 | const chatMessage = chat[messageId]; | 2008 | const chatMessage = chat[messageId]; |
| 2009 | mes = substituteParams(mes, undefined, ch_name); | 2009 | mes = substituteParams(mes, undefined, ch_name); |
| @@ -3171,7 +3171,7 @@ class StreamingProcessor { | |||
| 3171 | this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true })); | 3171 | this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true })); |
| 3172 | } | 3172 | } |
| 3173 | else { | 3173 | else { |
| 3174 | await saveReply(this.type, text, true); | 3174 | await saveReply(this.type, text, true, '', [], ''); |
| 3175 | messageId = chat.length - 1; | 3175 | messageId = chat.length - 1; |
| 3176 | this.#checkDomElements(messageId); | 3176 | this.#checkDomElements(messageId); |
| 3177 | this.showMessageButtons(messageId); | 3177 | this.showMessageButtons(messageId); |
| @@ -3365,7 +3365,7 @@ class StreamingProcessor { | |||
| 3365 | const timestamps = []; | 3365 | const timestamps = []; |
| 3366 | for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) { | 3366 | for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) { |
| 3367 | timestamps.push(Date.now()); | 3367 | timestamps.push(Date.now()); |
| 3368 | if (this.isStopped) { | 3368 | if (this.isStopped || this.abortController.signal.aborted) { |
| 3369 | return; | 3369 | return; |
| 3370 | } | 3370 | } |
| 3371 | 3371 | ||
| @@ -3863,10 +3863,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 3863 | 3863 | ||
| 3864 | const reasoning = new PromptReasoning(); | 3864 | const reasoning = new PromptReasoning(); |
| 3865 | for (let i = coreChat.length - 1; i >= 0; i--) { | 3865 | for (let i = coreChat.length - 1; i >= 0; i--) { |
| 3866 | if (reasoning.isLimitReached()) { | ||
| 3867 | break; | ||
| 3868 | } | ||
| 3869 | const depth = coreChat.length - i - 1; | 3866 | const depth = coreChat.length - i - 1; |
| 3867 | const isPrefix = isContinue && i === coreChat.length - 1; | ||
| 3870 | coreChat[i] = { | 3868 | coreChat[i] = { |
| 3871 | ...coreChat[i], | 3869 | ...coreChat[i], |
| 3872 | mes: reasoning.addToMessage( | 3870 | mes: reasoning.addToMessage( |
| @@ -3876,8 +3874,12 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 3876 | regex_placement.REASONING, | 3874 | regex_placement.REASONING, |
| 3877 | { isPrompt: true, depth: depth }, | 3875 | { isPrompt: true, depth: depth }, |
| 3878 | ), | 3876 | ), |
| 3877 | isPrefix, | ||
| 3879 | ), | 3878 | ), |
| 3880 | }; | 3879 | }; |
| 3880 | if (reasoning.isLimitReached()) { | ||
| 3881 | break; | ||
| 3882 | } | ||
| 3881 | } | 3883 | } |
| 3882 | 3884 | ||
| 3883 | // Determine token limit | 3885 | // Determine token limit |
| @@ -96,8 +96,13 @@ function highlightLockedBackground() { | |||
| 96 | }); | 96 | }); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | /** | ||
| 100 | * Locks the background for the current chat | ||
| 101 | * @param {Event} e Click event | ||
| 102 | * @returns {string} Empty string | ||
| 103 | */ | ||
| 99 | function onLockBackgroundClick(e) { | 104 | function onLockBackgroundClick(e) { |
| 100 | e.stopPropagation(); | 105 | e?.stopPropagation(); |
| 101 | 106 | ||
| 102 | const chatName = getCurrentChatId(); | 107 | const chatName = getCurrentChatId(); |
| 103 | 108 | ||
| @@ -114,8 +119,13 @@ function onLockBackgroundClick(e) { | |||
| 114 | return ''; | 119 | return ''; |
| 115 | } | 120 | } |
| 116 | 121 | ||
| 122 | /** | ||
| 123 | * Locks the background for the current chat | ||
| 124 | * @param {Event} e Click event | ||
| 125 | * @returns {string} Empty string | ||
| 126 | */ | ||
| 117 | function onUnlockBackgroundClick(e) { | 127 | function onUnlockBackgroundClick(e) { |
| 118 | e.stopPropagation(); | 128 | e?.stopPropagation(); |
| 119 | removeBackgroundMetadata(); | 129 | removeBackgroundMetadata(); |
| 120 | unsetCustomBackground(); | 130 | unsetCustomBackground(); |
| 121 | highlightLockedBackground(); | 131 | highlightLockedBackground(); |
| @@ -513,12 +523,12 @@ export function initBackgrounds() { | |||
| 513 | $('#add_bg_button').on('change', onBackgroundUploadSelected); | 523 | $('#add_bg_button').on('change', onBackgroundUploadSelected); |
| 514 | $('#bg-filter').on('input', onBackgroundFilterInput); | 524 | $('#bg-filter').on('input', onBackgroundFilterInput); |
| 515 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'lockbg', | 525 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'lockbg', |
| 516 | callback: onLockBackgroundClick, | 526 | callback: () => onLockBackgroundClick(new CustomEvent('click')), |
| 517 | aliases: ['bglock'], | 527 | aliases: ['bglock'], |
| 518 | helpString: 'Locks a background for the currently selected chat', | 528 | helpString: 'Locks a background for the currently selected chat', |
| 519 | })); | 529 | })); |
| 520 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'unlockbg', | 530 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'unlockbg', |
| 521 | callback: onUnlockBackgroundClick, | 531 | callback: () => onUnlockBackgroundClick(new CustomEvent('click')), |
| 522 | aliases: ['bgunlock'], | 532 | aliases: ['bgunlock'], |
| 523 | helpString: 'Unlocks a background for the currently selected chat', | 533 | helpString: 'Unlocks a background for the currently selected chat', |
| 524 | })); | 534 | })); |
| @@ -50,11 +50,12 @@ export class PromptReasoning { | |||
| 50 | * Add reasoning to a message according to the power user settings. | 50 | * Add reasoning to a message according to the power user settings. |
| 51 | * @param {string} content Message content | 51 | * @param {string} content Message content |
| 52 | * @param {string} reasoning Message reasoning | 52 | * @param {string} reasoning Message reasoning |
| 53 | * @param {boolean} isPrefix Whether this is the last message prefix | ||
| 53 | * @returns {string} Message content with reasoning | 54 | * @returns {string} Message content with reasoning |
| 54 | */ | 55 | */ |
| 55 | addToMessage(content, reasoning) { | 56 | addToMessage(content, reasoning, isPrefix) { |
| 56 | // Disabled or reached limit of additions | 57 | // Disabled or reached limit of additions |
| 57 | if (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions) { | 58 | if (!isPrefix && (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions)) { |
| 58 | return content; | 59 | return content; |
| 59 | } | 60 | } |
| 60 | 61 | ||
| @@ -71,6 +72,11 @@ export class PromptReasoning { | |||
| 71 | const separator = substituteParams(power_user.reasoning.separator || ''); | 72 | const separator = substituteParams(power_user.reasoning.separator || ''); |
| 72 | const suffix = substituteParams(power_user.reasoning.suffix || ''); | 73 | const suffix = substituteParams(power_user.reasoning.suffix || ''); |
| 73 | 74 | ||
| 75 | // Combine parts with reasoning only | ||
| 76 | if (isPrefix && !content) { | ||
| 77 | return `${prefix}${reasoning}`; | ||
| 78 | } | ||
| 79 | |||
| 74 | // Combine parts with reasoning and content | 80 | // Combine parts with reasoning and content |
| 75 | return `${prefix}${reasoning}${suffix}${separator}${content}`; | 81 | return `${prefix}${reasoning}${suffix}${separator}${content}`; |
| 76 | } | 82 | } |
| @@ -117,6 +123,7 @@ function loadReasoningSettings() { | |||
| 117 | function registerReasoningSlashCommands() { | 123 | function registerReasoningSlashCommands() { |
| 118 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | 124 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 119 | name: 'reasoning-get', | 125 | name: 'reasoning-get', |
| 126 | aliases: ['get-reasoning'], | ||
| 120 | returns: ARGUMENT_TYPE.STRING, | 127 | returns: ARGUMENT_TYPE.STRING, |
| 121 | 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.`, | 128 | 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.`, |
| 122 | unnamedArgumentList: [ | 129 | unnamedArgumentList: [ |
| @@ -136,6 +143,7 @@ function registerReasoningSlashCommands() { | |||
| 136 | 143 | ||
| 137 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | 144 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 138 | name: 'reasoning-set', | 145 | name: 'reasoning-set', |
| 146 | aliases: ['set-reasoning'], | ||
| 139 | returns: ARGUMENT_TYPE.STRING, | 147 | returns: ARGUMENT_TYPE.STRING, |
| 140 | helpString: t`Set the reasoning block of a message. Returns the reasoning block content.`, | 148 | helpString: t`Set the reasoning block of a message. Returns the reasoning block content.`, |
| 141 | namedArgumentList: [ | 149 | namedArgumentList: [ |
| @@ -170,6 +178,7 @@ function registerReasoningSlashCommands() { | |||
| 170 | 178 | ||
| 171 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | 179 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 172 | name: 'reasoning-parse', | 180 | name: 'reasoning-parse', |
| 181 | aliases: ['parse-reasoning'], | ||
| 173 | returns: 'reasoning string', | 182 | returns: 'reasoning string', |
| 174 | helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`, | 183 | helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`, |
| 175 | namedArgumentList: [ | 184 | namedArgumentList: [ |
| @@ -54,6 +54,12 @@ const OPENROUTER_PROVIDERS = [ | |||
| 54 | 'xAI', | 54 | 'xAI', |
| 55 | 'Cloudflare', | 55 | 'Cloudflare', |
| 56 | 'SF Compute', | 56 | 'SF Compute', |
| 57 | 'Minimax', | ||
| 58 | 'Nineteen', | ||
| 59 | 'Liquid', | ||
| 60 | 'Nebius', | ||
| 61 | 'Chutes', | ||
| 62 | 'Kluster', | ||
| 57 | '01.AI', | 63 | '01.AI', |
| 58 | 'HuggingFace', | 64 | 'HuggingFace', |
| 59 | 'Mancer', | 65 | 'Mancer', |
| @@ -533,6 +533,7 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => { | |||
| 533 | 533 | ||
| 534 | comfy.post('/generate', jsonParser, async (request, response) => { | 534 | comfy.post('/generate', jsonParser, async (request, response) => { |
| 535 | try { | 535 | try { |
| 536 | let item; | ||
| 536 | const url = new URL(urlJoin(request.body.url, '/prompt')); | 537 | const url = new URL(urlJoin(request.body.url, '/prompt')); |
| 537 | 538 | ||
| 538 | const controller = new AbortController(); | 539 | const controller = new AbortController(); |
| @@ -557,7 +558,6 @@ comfy.post('/generate', jsonParser, async (request, response) => { | |||
| 557 | /** @type {any} */ | 558 | /** @type {any} */ |
| 558 | const data = await promptResult.json(); | 559 | const data = await promptResult.json(); |
| 559 | const id = data.prompt_id; | 560 | const id = data.prompt_id; |
| 560 | let item; | ||
| 561 | const historyUrl = new URL(urlJoin(request.body.url, '/history')); | 561 | const historyUrl = new URL(urlJoin(request.body.url, '/history')); |
| 562 | while (true) { | 562 | while (true) { |
| 563 | const result = await fetch(historyUrl); | 563 | const result = await fetch(historyUrl); |