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 | const swipeMessage = chatElement.find(`[mesid="${chat.length - 1}"]`); | 2506 | const swipeMessage = chatElement.find(`[mesid="${chat.length - 1}"]`); |
| 2507 | swipeMessage.attr('swipeid', params.swipeId); | 2507 | swipeMessage.attr('swipeid', params.swipeId); |
| 2508 | swipeMessage.find('.mes_text').html(messageText).attr('title', title); | 2508 | swipeMessage.find('.mes_text').html(messageText).attr('title', title); |
| 2509 | swipeMessage.find('.mes_reasoning').html(reasoning); | ||
| 2510 | swipeMessage.find('.timestamp').text(timestamp).attr('title', `${params.extra.api} - ${params.extra.model}`); | 2509 | swipeMessage.find('.timestamp').text(timestamp).attr('title', `${params.extra.api} - ${params.extra.model}`); |
| 2510 | updateReasoningUI(swipeMessage, { reset: true }); | ||
| 2511 | appendMediaToMessage(mes, swipeMessage); | 2511 | appendMediaToMessage(mes, swipeMessage); |
| 2512 | if (power_user.timestamp_model_icon && params.extra?.api) { | 2512 | if (power_user.timestamp_model_icon && params.extra?.api) { |
| 2513 | insertSVGIcon(swipeMessage, params.extra); | 2513 | insertSVGIcon(swipeMessage, params.extra); |
| @@ -8722,7 +8722,7 @@ const swipe_right = () => { | |||
| 8722 | // resets the timer | 8722 | // resets the timer |
| 8723 | swipeMessage.find('.mes_timer').html(''); | 8723 | swipeMessage.find('.mes_timer').html(''); |
| 8724 | swipeMessage.find('.tokenCounterDisplay').text(''); | 8724 | swipeMessage.find('.tokenCounterDisplay').text(''); |
| 8725 | updateReasoningUI(swipeMessage); | 8725 | updateReasoningUI(swipeMessage, { reset: true }); |
| 8726 | } else { | 8726 | } else { |
| 8727 | //console.log('showing previously generated swipe candidate, or "..."'); | 8727 | //console.log('showing previously generated swipe candidate, or "..."'); |
| 8728 | //console.log('onclick right swipe calling addOneMessage'); | 8728 | //console.log('onclick right swipe calling addOneMessage'); |
| @@ -96,11 +96,11 @@ export function isHiddenReasoningModel() { | |||
| 96 | 96 | ||
| 97 | function isModelSupported(model) { | 97 | function isModelSupported(model) { |
| 98 | for (const hiddenReasoningModel of hiddenReasoningModels) { | 98 | for (const hiddenReasoningModel of hiddenReasoningModels) { |
| 99 | if (typeof model === 'string') { | 99 | if (typeof hiddenReasoningModel === 'string') { |
| 100 | return hiddenReasoningModel === model; | 100 | return hiddenReasoningModel === model; |
| 101 | } | 101 | } |
| 102 | if (model.matchingFunc) { | 102 | if (hiddenReasoningModel.func) { |
| 103 | return model.matchingFunc(model, hiddenReasoningModel); | 103 | return hiddenReasoningModel.func(model, hiddenReasoningModel.name); |
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| 106 | return false; | 106 | return false; |
| @@ -121,10 +121,12 @@ export function isHiddenReasoningModel() { | |||
| 121 | /** | 121 | /** |
| 122 | * Updates the Reasoning UI for a specific message | 122 | * Updates the Reasoning UI for a specific message |
| 123 | * @param {number|JQuery<HTMLElement>|HTMLElement} messageIdOrElement The message ID or the message element | 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 | export function updateReasoningUI(messageIdOrElement) { | 127 | export function updateReasoningUI(messageIdOrElement, { reset = false } = {}) { |
| 126 | const handler = new ReasoningHandler(); | 128 | const handler = new ReasoningHandler(); |
| 127 | handler.initHandleMessage(messageIdOrElement); | 129 | handler.initHandleMessage(messageIdOrElement, { reset }); |
| 128 | } | 130 | } |
| 129 | 131 | ||
| 130 | 132 | ||
| @@ -185,8 +187,10 @@ export class ReasoningHandler { | |||
| 185 | * The state will always be either done/hidden or none. | 187 | * The state will always be either done/hidden or none. |
| 186 | * | 188 | * |
| 187 | * @param {number|JQuery<HTMLElement>|HTMLElement} messageIdOrElement - The message ID or the message element | 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 | /** @type {HTMLElement} */ | 194 | /** @type {HTMLElement} */ |
| 191 | const messageElement = typeof messageIdOrElement === 'number' | 195 | const messageElement = typeof messageIdOrElement === 'number' |
| 192 | ? document.querySelector(`#chat [mesid="${messageIdOrElement}"]`) | 196 | ? document.querySelector(`#chat [mesid="${messageIdOrElement}"]`) |
| @@ -197,7 +201,7 @@ export class ReasoningHandler { | |||
| 197 | 201 | ||
| 198 | if (isNaN(messageId)) return; | 202 | if (isNaN(messageId)) return; |
| 199 | 203 | ||
| 200 | const extra = chat[messageId]['extra']; | 204 | const extra = chat[messageId].extra; |
| 201 | 205 | ||
| 202 | if (extra.reasoning) { | 206 | if (extra.reasoning) { |
| 203 | this.state = ReasoningState.Done; | 207 | this.state = ReasoningState.Done; |
| @@ -216,6 +220,15 @@ export class ReasoningHandler { | |||
| 216 | // Prefill main dom element, as message might not have been rendered yet | 220 | // Prefill main dom element, as message might not have been rendered yet |
| 217 | this.messageDom = messageElement; | 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 | this.updateDom(messageId); | 232 | this.updateDom(messageId); |
| 220 | } | 233 | } |
| 221 | 234 | ||
| @@ -242,19 +255,21 @@ export class ReasoningHandler { | |||
| 242 | */ | 255 | */ |
| 243 | updateReasoning(messageId, reasoning = null, { persist = false } = {}) { | 256 | updateReasoning(messageId, reasoning = null, { persist = false } = {}) { |
| 244 | reasoning = reasoning ?? this.reasoning; | 257 | reasoning = reasoning ?? this.reasoning; |
| 245 | const reasoningChanged = this.reasoning !== reasoning; | 258 | reasoning = power_user.trim_spaces ? reasoning.trim() : reasoning; |
| 246 | this.reasoning = getRegexedString(reasoning ?? '', regex_placement.REASONING); | ||
| 247 | 259 | ||
| 248 | if (persist) { | ||
| 249 | // Ensure the chat extra exists | 260 | // Ensure the chat extra exists |
| 250 | if (!chat[messageId]['extra']) { | 261 | if (!chat[messageId].extra) { |
| 251 | chat[messageId]['extra'] = {}; | 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 | // Build and save the reasoning data to message extras | 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 | return reasoningChanged; | 275 | return reasoningChanged; |