Merge pull request #3395 from pcpthm/reasoning-continue Always add reasoning for continue
Signed| @@ -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 |
| @@ -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 | } |