Early stopping if prompt reasoning limit reached

8fc880b69b88667f8120266669369dad2921e73e

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +15 -0Ignore whitespace
public/script.js+3 -0
@@ -3846,6 +3846,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
38463846
38473847 const reasoning = new PromptReasoning();
38483848 for (let i = coreChat.length - 1; i >= 0; i--) {
3849+ if (reasoning.isLimitReached()) {
3850+ break;
3851+ }
38493852 coreChat[i] = { ...coreChat[i], mes: reasoning.addToMessage(coreChat[i].mes, coreChat[i].extra?.reasoning) };
38503853 }
38513854
public/scripts/chats.js+12 -0
@@ -1432,6 +1432,18 @@ export class PromptReasoning {
14321432 }
14331433
14341434 /**
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+ /**
14351447 * Add reasoning to a message according to the power user settings.
14361448 * @param {string} content Message content
14371449 * @param {string} reasoning Message reasoning