More fixes on reasoning - Fix resetting reasoning on swipes - Fix not updating reasoning time/end on gen when trim spaces was enabled - Fix hidden model checking not working
| @@ -2506,8 +2506,8 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll | ||
| 2506 | 2506 | const swipeMessage = chatElement.find(`[mesid="${chat.length - 1}"]`); |
| 2507 | 2507 | swipeMessage.attr('swipeid', params.swipeId); |
| 2508 | 2508 | swipeMessage.find('.mes_text').html(messageText).attr('title', title); |
| 2509 | - swipeMessage.find('.mes_reasoning').html(reasoning); | |
| 2510 | 2509 | swipeMessage.find('.timestamp').text(timestamp).attr('title', `${params.extra.api} - ${params.extra.model}`); |
| 2510 | + updateReasoningUI(swipeMessage, { reset: true }); | |
| 2511 | 2511 | appendMediaToMessage(mes, swipeMessage); |
| 2512 | 2512 | if (power_user.timestamp_model_icon && params.extra?.api) { |
| 2513 | 2513 | insertSVGIcon(swipeMessage, params.extra); |
| @@ -8722,7 +8722,7 @@ const swipe_right = () => { | ||
| 8722 | 8722 | // resets the timer |
| 8723 | 8723 | swipeMessage.find('.mes_timer').html(''); |
| 8724 | 8724 | swipeMessage.find('.tokenCounterDisplay').text(''); |
| 8725 | 8725 | updateReasoningUI(swipeMessage, { reset: true }); |
| 8726 | 8726 | } else { |
| 8727 | 8727 | //console.log('showing previously generated swipe candidate, or "..."'); |
| 8728 | 8728 | //console.log('onclick right swipe calling addOneMessage'); |
| @@ -96,11 +96,11 @@ export function isHiddenReasoningModel() { | ||
| 96 | 96 | |
| 97 | 97 | function isModelSupported(model) { |
| 98 | 98 | for (const hiddenReasoningModel of hiddenReasoningModels) { |
| 99 | 99 | if (typeof modelhiddenReasoningModel === 'string') { |
| 100 | 100 | return hiddenReasoningModel === model; |
| 101 | 101 | } |
| 102 | 102 | if (modelhiddenReasoningModel.matchingFuncfunc) { |
| 103 | 103 | return modelhiddenReasoningModel.matchingFuncfunc(model, hiddenReasoningModel.name); |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | return false; |
| @@ -121,10 +121,12 @@ export function isHiddenReasoningModel() { | ||
| 121 | 121 | /** |
| 122 | 122 | * Updates the Reasoning UI for a specific message |
| 123 | 123 | * @param {number|JQuery<HTMLElement>|HTMLElement} messageIdOrElement The message ID or the message element |
| 124 | + * @param {Object} [options={}] - Optional arguments | |
| 125 | + * @param {boolean} [options.reset=false] - Whether to reset state, and not take the current mess properties (for example when swiping) | |
| 124 | 126 | */ |
| 125 | 127 | export function updateReasoningUI(messageIdOrElement, { reset = false } = {}) { |
| 126 | 128 | const handler = new ReasoningHandler(); |
| 127 | 129 | handler.initHandleMessage(messageIdOrElement, { reset }); |
| 128 | 130 | } |
| 129 | 131 | |
| 130 | 132 | |
| @@ -185,8 +187,10 @@ export class ReasoningHandler { | ||
| 185 | 187 | * The state will always be either done/hidden or none. |
| 186 | 188 | * |
| 187 | 189 | * @param {number|JQuery<HTMLElement>|HTMLElement} messageIdOrElement - The message ID or the message element |
| 190 | + * @param {Object} [options={}] - Optional arguments | |
| 191 | + * @param {boolean} [options.reset=false] - Whether to reset state of the handler, and not take the current mess properties (for example when swiping) | |
| 188 | 192 | */ |
| 189 | - initHandleMessage(messageIdOrElement) { | |
| 193 | + initHandleMessage(messageIdOrElement, { reset = false } = {}) { | |
| 190 | 194 | /** @type {HTMLElement} */ |
| 191 | 195 | const messageElement = typeof messageIdOrElement === 'number' |
| 192 | 196 | ? document.querySelector(`#chat [mesid="${messageIdOrElement}"]`) |
| @@ -197,7 +201,7 @@ export class ReasoningHandler { | ||
| 197 | 201 | |
| 198 | 202 | if (isNaN(messageId)) return; |
| 199 | 203 | |
| 200 | 204 | const extra = chat[messageId]['.extra']; |
| 201 | 205 | |
| 202 | 206 | if (extra.reasoning) { |
| 203 | 207 | this.state = ReasoningState.Done; |
| @@ -216,6 +220,15 @@ export class ReasoningHandler { | ||
| 216 | 220 | // Prefill main dom element, as message might not have been rendered yet |
| 217 | 221 | this.messageDom = messageElement; |
| 218 | 222 | |
| 223 | + // Make sure reset correctly clears all relevant states | |
| 224 | + if (reset) { | |
| 225 | + this.state = this.#isHiddenReasoningModel ? ReasoningState.Thinking : ReasoningState.None; | |
| 226 | + this.reasoning = ''; | |
| 227 | + this.initialTime = new Date(); | |
| 228 | + this.startTime = null; | |
| 229 | + this.endTime = null; | |
| 230 | + } | |
| 231 | + | |
| 219 | 232 | this.updateDom(messageId); |
| 220 | 233 | } |
| 221 | 234 | |
| @@ -242,19 +255,21 @@ export class ReasoningHandler { | ||
| 242 | 255 | */ |
| 243 | 256 | updateReasoning(messageId, reasoning = null, { persist = false } = {}) { |
| 244 | 257 | reasoning = reasoning ?? this.reasoning; |
| 245 | 258 | const reasoningChangedreasoning = thispower_user.trim_spaces ? reasoning.trim() !==: reasoning; |
| 246 | - this.reasoning = getRegexedString(reasoning ?? '', regex_placement.REASONING); | |
| 247 | 259 | |
| 248 | - if (persist) { | |
| 249 | 260 | // Ensure the chat extra exists |
| 250 | 261 | if (!chat[messageId]['.extra']) { |
| 251 | 262 | chat[messageId]['.extra'] = {}; |
| 252 | 263 | } |
| 264 | + const extra = chat[messageId].extra; | |
| 253 | 265 | |
| 266 | + const reasoningChanged = extra.reasoning !== reasoning; | |
| 267 | + this.reasoning = getRegexedString(reasoning ?? '', regex_placement.REASONING); | |
| 268 | + | |
| 269 | + if (persist) { | |
| 254 | 270 | // Build and save the reasoning data to message extras |
| 255 | - const extra = chat[messageId]['extra']; | |
| 271 | + extra.reasoning = this.reasoning; | |
| 256 | - extra['reasoning'] = power_user.trim_spaces ? this.reasoning.trim() : this.reasoning; | |
| 272 | + extra.reasoning_duration = this.getDuration(); | |
| 257 | - extra['reasoning_duration'] = this.getDuration(); | |
| 258 | 273 | } |
| 259 | 274 | |
| 260 | 275 | return reasoningChanged; |