| 376 | 377 | }); |
| 377 | 378 | |
| 378 | 379 | const msg = chat[messageId]; |
| 380 | + |
| 381 | + const reasoningPrefix = substituteParamsExtended(power_user.reasoning.prefix); |
| 382 | + const reasoningSuffix = substituteParamsExtended(power_user.reasoning.suffix); |
| 383 | + const isReasoningAutoParsed = power_user.reasoning.auto_parse; |
| 384 | + const msgHasParsedReasoning = msg.extra?.reasoning?.length > 0; |
| 385 | + let shouldRerollReasoning = false; |
| 386 | + |
| 387 | + //if we have pre-existing reasoning and are currently autoparsing |
| 388 | + if (isReasoningAutoParsed && msgHasParsedReasoning) { |
| 389 | + console.debug('saw autoparse on with reasoning in message'); |
| 390 | + //but the reroll prompt does not include the end of reasoning |
| 391 | + if (cleanedPrompt.includes(reasoningPrefix) && !cleanedPrompt.includes(reasoningSuffix)) { |
| 392 | + //we need to send the results to the reasoning block |
| 393 | + //this will involve the ReasoningHandler from reasoning.js |
| 394 | + console.debug('..with start tag but no end tag... reroll reasoning'); |
| 395 | + shouldRerollReasoning = true; |
| 396 | + } |
| 397 | + |
| 398 | + let hasReasoningPrefix = cleanedPrompt.includes(reasoningPrefix); |
| 399 | + let hasReasoningSuffix = cleanedPrompt.includes(reasoningSuffix); |
| 400 | + |
| 401 | + //..with both the start and end think tags |
| 402 | + //OR |
| 403 | + //..with only the end think tag (implying prefilled think start) |
| 404 | + if (hasReasoningPrefix && hasReasoningSuffix) { |
| 405 | + //we need to send the results to the response block without reasoning attached |
| 406 | + console.debug('...incl. end tag...rerolling response'); |
| 407 | + const endOfThink = cleanedPrompt.indexOf(reasoningSuffix) + reasoningSuffix.length; |
| 408 | + cleanedPrompt = cleanedPrompt.substring(endOfThink); |
| 409 | + } |
| 410 | + |
| 411 | + //if cleanedprompt includes the think prefix, but no suffix.. |
| 412 | + if (hasReasoningPrefix && !hasReasoningSuffix) { |
| 413 | + console.debug('..no end tag...rerolling reasoning, so removing prefix'); |
| 414 | + cleanedPrompt = cleanedPrompt.replace(reasoningPrefix, ''); |
| 415 | + } |
| 416 | + } |
| 417 | + |
| 418 | + console.debug('cleanedPrompt: ', cleanedPrompt); |
| 419 | + |
| 379 | 420 | const newSwipeInfo = { |
| 380 | 421 | send_date: msg.send_date, |
| 381 | 422 | gen_started: msg.gen_started, |