Early stopping if prompt reasoning limit reached
| @@ -3846,6 +3846,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 3846 | 3846 | ||
| 3847 | const reasoning = new PromptReasoning(); | 3847 | const reasoning = new PromptReasoning(); |
| 3848 | for (let i = coreChat.length - 1; i >= 0; i--) { | 3848 | for (let i = coreChat.length - 1; i >= 0; i--) { |
| 3849 | if (reasoning.isLimitReached()) { | ||
| 3850 | break; | ||
| 3851 | } | ||
| 3849 | coreChat[i] = { ...coreChat[i], mes: reasoning.addToMessage(coreChat[i].mes, coreChat[i].extra?.reasoning) }; | 3852 | coreChat[i] = { ...coreChat[i], mes: reasoning.addToMessage(coreChat[i].mes, coreChat[i].extra?.reasoning) }; |
| 3850 | } | 3853 | } |
| 3851 | 3854 | ||
| @@ -1432,6 +1432,18 @@ export class PromptReasoning { | |||
| 1432 | } | 1432 | } |
| 1433 | 1433 | ||
| 1434 | /** | 1434 | /** |
| 1435 | * Checks if the limit of reasoning additions has been reached. | ||
| 1436 | * @returns {boolean} True if the limit of reasoning additions has been reached, false otherwise. | ||
| 1437 | */ | ||
| 1438 | isLimitReached() { | ||
| 1439 | if (!power_user.reasoning.add_to_prompts) { | ||
| 1440 | return true; | ||
| 1441 | } | ||
| 1442 | |||
| 1443 | return this.counter >= power_user.reasoning.max_additions; | ||
| 1444 | } | ||
| 1445 | |||
| 1446 | /** | ||
| 1435 | * Add reasoning to a message according to the power user settings. | 1447 | * Add reasoning to a message according to the power user settings. |
| 1436 | * @param {string} content Message content | 1448 | * @param {string} content Message content |
| 1437 | * @param {string} reasoning Message reasoning | 1449 | * @param {string} reasoning Message reasoning |