Skip to content

Conversation

@HenryHengZJ
Copy link
Contributor

@HenryHengZJ HenryHengZJ commented Oct 30, 2025

Summary by CodeRabbit

New Features

  • Added configurable thinkingBudget parameter to ChatGoogleGenerativeAI node for Gemini 2.5 models, enabling users to control the number of thinking tokens (-1 for dynamic allocation, 0 to disable, or custom positive integer).

@coderabbitai
Copy link

coderabbitai bot commented Oct 30, 2025

Walkthrough

This pull request adds support for the thinkingBudget parameter to the ChatGoogleGenerativeAI node for Gemini 2.5 models. The parameter is exposed as a UI input with conditional visibility and is properly propagated through the initialization layer to the underlying API configuration.

Changes

Cohort / File(s) Summary
ChatGoogleGenerativeAI Configuration
packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/ChatGoogleGenerativeAI.ts, packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts
Added thinkingBudget (type number) parameter to UI configuration with conditional visibility for Gemini 2.5 models. Added field to interface and class implementation. Initialized in constructor and applied to generationConfig.thinkingConfig during client creation and in cached content handling. Parameter is parsed as integer before assignment.
Documentation Updates
packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/utils/common.ts
Added documentation comment clarifying default behavior for convertAuthorToRole function.

Sequence Diagram

sequenceDiagram
    participant UI as UI Config
    participant Init as Initialization
    participant Client as API Client
    
    UI->>Init: Pass thinkingBudget parameter
    Init->>Init: Parse thinkingBudget to integer
    Init->>Client: Create client with config
    Client->>Client: Set generationConfig.thinkingConfig
    Note over Client: thinkingBudget applied<br/>for Gemini 2.5 models
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Straightforward parameter addition following existing patterns
  • Changes are well-scoped to three files with clear responsibilities
  • No complex logic or control-flow modifications
  • Minor consideration: verify conditional visibility logic for model names is correctly specified

Poem

🐰 A budget for thinking, a gift to the wise,
Gemini 2.5 now sees through rabbit eyes,
From UI to client, the tokens will flow,
Integer-parsed paths for smarter minds to grow! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Feat/add thinking budget to gemini" directly aligns with the primary changes in the changeset, which add a new thinkingBudget input parameter to the ChatGoogleGenerativeAI node for Gemini 2.5 models. The title is concise, specific, and uses a conventional commit format with a clear feature prefix. It accurately summarizes the main objective without being vague or generic, and someone reviewing the commit history would immediately understand that this change introduces thinking budget functionality to Gemini models.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/Gemini-Thinking-Budget

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/ChatGoogleGenerativeAI.ts (1)

231-251: Consider adding validation for thinkingBudget values.

The code parses thinkingBudget but doesn't validate that it's -1 (dynamic), 0 (disabled), or a positive integer as documented. Invalid values like negative numbers (other than -1) or non-numeric strings would parse to NaN or invalid values.

Apply this diff to add validation:

 if (thinkingBudget) obj.thinkingBudget = parseInt(thinkingBudget, 10)
+        const parsedBudget = parseInt(thinkingBudget, 10)
+        if (!isNaN(parsedBudget) && (parsedBudget === -1 || parsedBudget >= 0)) {
+            obj.thinkingBudget = parsedBudget
+        }
+    }

Alternatively, rely on the API to validate and return errors for invalid values.

packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts (1)

665-665: Consider adding validation for thinkingBudget.

Similar to how temperature, topP, and topK are validated in the constructor (lines 625-641), consider adding validation to ensure thinkingBudget is -1, 0, or a positive integer.

Apply this diff to add validation:

 this.thinkingBudget = fields.thinkingBudget
+        if (this.thinkingBudget !== undefined && this.thinkingBudget !== -1 && this.thinkingBudget < 0) {
+            throw new Error('`thinkingBudget` must be -1 (dynamic), 0 (disabled), or a positive integer')
+        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9751598 and 69c7b1b.

📒 Files selected for processing (3)
  • packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/ChatGoogleGenerativeAI.ts (3 hunks)
  • packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts (4 hunks)
  • packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/utils/common.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (ubuntu-latest, 18.15.0)
  • GitHub Check: build
🔇 Additional comments (4)
packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/utils/common.ts (1)

51-52: LGTM! Documentation clarifies default behavior.

The comment helpfully documents that convertAuthorToRole returns 'user' as default instead of throwing an error, which aligns with the implementation at line 76.

packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/ChatGoogleGenerativeAI.ts (1)

177-188: LGTM! Clear parameter definition for Gemini 2.5 thinking budget.

The input parameter is well-defined with a clear description of valid values (-1 for dynamic, 0 to disable, or positive integer) and appropriate conditional visibility for Gemini 2.5 models.

packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts (2)

178-179: LGTM! Clear interface definition for thinkingBudget.

The interface field is properly typed and documented with the supported values for Gemini 2.5 thinking models.


605-605: LGTM! Field declaration follows existing pattern.

Comment on lines +685 to +689
if (this.thinkingBudget !== undefined) {
;(this.client.generationConfig as any).thinkingConfig = {
...(this.thinkingBudget !== undefined ? { thinkingBudget: this.thinkingBudget } : {})
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Simplify redundant conditional check.

The inner ternary operator is unnecessary since we're already inside an if (this.thinkingBudget !== undefined) block.

Apply this diff to simplify:

 if (this.thinkingBudget !== undefined) {
     ;(this.client.generationConfig as any).thinkingConfig = {
-        ...(this.thinkingBudget !== undefined ? { thinkingBudget: this.thinkingBudget } : {})
+        thinkingBudget: this.thinkingBudget
     }
 }

Note: The type cast to any is acceptable here since thinkingConfig is a new API feature that may not yet be in the TypeScript definitions.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (this.thinkingBudget !== undefined) {
;(this.client.generationConfig as any).thinkingConfig = {
...(this.thinkingBudget !== undefined ? { thinkingBudget: this.thinkingBudget } : {})
}
}
if (this.thinkingBudget !== undefined) {
;(this.client.generationConfig as any).thinkingConfig = {
thinkingBudget: this.thinkingBudget
}
}
🤖 Prompt for AI Agents
In
packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts
around lines 685-689, the inner ternary is redundant because you're already
inside an if checking this.thinkingBudget !== undefined; replace the current
assignment with a direct object assignment (e.g., (this.client.generationConfig
as any).thinkingConfig = { thinkingBudget: this.thinkingBudget }) to simplify
the code while keeping the any cast as noted.

Comment on lines +696 to +700
if (this.thinkingBudget !== undefined) {
;(this.client.generationConfig as any).thinkingConfig = {
...(this.thinkingBudget !== undefined ? { thinkingBudget: this.thinkingBudget } : {})
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Simplify redundant conditional check.

Same issue as in the constructor: the inner ternary operator is unnecessary since we're already inside an if (this.thinkingBudget !== undefined) block.

Apply this diff to simplify:

 if (this.thinkingBudget !== undefined) {
     ;(this.client.generationConfig as any).thinkingConfig = {
-        ...(this.thinkingBudget !== undefined ? { thinkingBudget: this.thinkingBudget } : {})
+        thinkingBudget: this.thinkingBudget
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (this.thinkingBudget !== undefined) {
;(this.client.generationConfig as any).thinkingConfig = {
...(this.thinkingBudget !== undefined ? { thinkingBudget: this.thinkingBudget } : {})
}
}
if (this.thinkingBudget !== undefined) {
;(this.client.generationConfig as any).thinkingConfig = {
thinkingBudget: this.thinkingBudget
}
}
🤖 Prompt for AI Agents
In
packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts
around lines 696 to 700, the inner ternary checking this.thinkingBudget is
redundant because the surrounding if already ensures it's defined; replace the
current assignment to this.client.generationConfig.thinkingConfig with a direct
object that sets thinkingBudget to this.thinkingBudget (i.e., assign {
thinkingBudget: this.thinkingBudget }) so the extra conditional is removed and
the code is simplified.

@HenryHengZJ HenryHengZJ merged commit f3d5b77 into main Oct 30, 2025
3 checks passed
@HenryHengZJ HenryHengZJ deleted the feature/Gemini-Thinking-Budget branch October 31, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants