Skip to content

Conversation

@AntonioABLima
Copy link
Collaborator

@AntonioABLima AntonioABLima commented Nov 14, 2025

🔧 Summary

This PR fixes an issue in the Google Generative AI Agent component where the model_name field was not properly updated in the UI or in the internal component state.

This PR relates to issue #10572.

There were two underlying problems:

  • A hard-coded default model value ("gemini-1.5-pro") was still being assigned, causing mismatches whenever the available model list changed.
  • The code used:
  • build_config["model_name"].setdefault("value", ids[0])
    setdefault() does not override existing values, resulting in stale defaults persisting in the UI.

✅ What has been changed

✔ Removed hard-coded "gemini-1.5-pro"

The default model is now dynamically assigned using the first entry from the model list in the DropdownInput, following the same pattern used by all other providers in Langflow.

value = GOOGLE_GENERATIVE_AI_MODELS[0]

✔ Removed .setdefault("value", ids[0]) and replaced it with an explicit assignment to ensure the value is always updated

build_config["model_name"]["value"] = ids[0]

Summary by CodeRabbit

  • Bug Fixes
    • Fixed default model selection to properly reflect available options.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

The Google Generative AI component's default model selection was updated to dynamically reference the first available model from GOOGLE_GENERATIVE_AI_MODELS instead of a hard-coded string, and the update_build_config method was modified to directly assign model values instead of using a fallback-on-missing approach.

Changes

Cohort / File(s) Summary
Google Generative AI model defaults
src/lfx/src/lfx/components/google/google_generative_ai.py
Changed model_name dropdown default from hard-coded "gemini-1.5-pro" to GOOGLE_GENERATIVE_AI_MODELS[0]; updated update_build_config to directly assign values instead of using setdefault

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Areas of attention:
    • Verify that GOOGLE_GENERATIVE_AI_MODELS[0] is guaranteed to exist and matches expected behavior at initialization
    • Confirm that removing the setdefault fallback logic does not introduce edge cases where build_config["model_name"]["value"] could be undefined
    • Cross-check compatibility with related PRs (#9495, #8358) to ensure no conflicting logic

Possibly related PRs

Suggested labels

bug, lgtm

Suggested reviewers

  • edwinjosechittilappilly
  • ogabrielluiz

Pre-merge checks and finishing touches

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR modifies Google Generative AI component bug fix but no corresponding test files are present in the repository to cover the changes. Add test file (test_google_generative_ai.py) with tests for update_build_config method, model selection, edge cases, and dynamic default model assignment.
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.
Test Quality And Coverage ⚠️ Warning PR modifies google_generative_ai.py to fix model_name defaults but no test files exist in repository to validate changes. Add unit tests for model_name default assignment, build_config updates, edge cases, and integration tests for model changes.
Test File Naming And Structure ❓ Inconclusive Repository lacks accessible test files to evaluate test naming and structure patterns against established conventions. Provide access to test suite or confirm whether tests exist in tracked repository files and should be evaluated.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix/google agent models' directly addresses the main change: fixing model name handling in the Google Generative AI Agent component.
Excessive Mock Usage Warning ✅ Passed No test files are modified or added in this PR, therefore excessive mock usage cannot be assessed.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lfx/src/lfx/components/google/google_generative_ai.py (1)

112-125: Fix pre-existing bugs in model filtering logic.

While not introduced by this PR, there are critical bugs in the tool model filtering that could result in an empty ids list (causing the IndexError flagged in line 140):

  1. Line 120: Uses self.model_name instead of the loop variable model, causing the same model to be checked repeatedly instead of each model in the list.
  2. Line 124: Modifying model_ids during iteration can skip elements and produce incorrect results.

Apply this diff to fix both issues:

         if tool_model_enabled:
             try:
                 from langchain_google_genai.chat_models import ChatGoogleGenerativeAI
             except ImportError as e:
                 msg = "langchain_google_genai is not installed."
                 raise ImportError(msg) from e
-            for model in model_ids:
+            filtered_ids = []
+            for model in model_ids:
                 model_with_tool = ChatGoogleGenerativeAI(
-                    model=self.model_name,
+                    model=model,
                     google_api_key=self.api_key,
                 )
-                if not self.supports_tool_calling(model_with_tool):
-                    model_ids.remove(model)
-        return model_ids
+                if self.supports_tool_calling(model_with_tool):
+                    filtered_ids.append(model)
+            return filtered_ids
+        return model_ids
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d4469d and d410a89.

📒 Files selected for processing (1)
  • src/lfx/src/lfx/components/google/google_generative_ai.py (2 hunks)
🔇 Additional comments (1)
src/lfx/src/lfx/components/google/google_generative_ai.py (1)

27-35: ****

The original concern about IndexError on line 32 is not valid. GOOGLE_GENERATIVE_AI_MODELS is derived from a statically initialized list (GOOGLE_GENERATIVE_AI_MODELS_DETAILED) with hardcoded model entries, guaranteeing it is never empty at module initialization. Additionally, even in the update_build_config method (line 140), ids[0] is protected: it references either GOOGLE_GENERATIVE_AI_MODELS (non-empty) or falls back to it on exception, making it safe.

Likely an incorrect or invalid review comment.

Comment on lines 138 to +140
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
build_config["model_name"].setdefault("value", ids[0])
build_config["model_name"]["value"] = ids[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add bounds checking before accessing ids[0].

Direct assignment is correct for ensuring the value is always updated (fixing the setdefault issue). However, accessing ids[0] without verifying the list is non-empty will cause an IndexError if:

  • GOOGLE_GENERATIVE_AI_MODELS is empty
  • The API returns no models with "generateContent" support
  • All models are filtered out when tool_model_enabled is True

Apply this diff to add bounds checking:

                 build_config.setdefault("model_name", {})
                 build_config["model_name"]["options"] = ids
-                build_config["model_name"]["value"] = ids[0]
+                if ids:
+                    build_config["model_name"]["value"] = ids[0]
📝 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
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
build_config["model_name"].setdefault("value", ids[0])
build_config["model_name"]["value"] = ids[0]
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
if ids:
build_config["model_name"]["value"] = ids[0]
🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/google/google_generative_ai.py around lines 138 to
140, the code assigns build_config["model_name"]["value"] = ids[0] without
checking ids length which can raise IndexError; update the code to check that
ids is a non-empty list before accessing ids[0] (e.g., if ids: set value to
ids[0]; else set value to None or an empty string or omit the "value" key) and
ensure build_config["model_name"]["options"] still receives the ids list so
downstream logic can handle the empty case.

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.

1 participant