Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lfx/src/lfx/_assets/component_index.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/lfx/src/lfx/components/google/google_generative_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GoogleGenerativeAIComponent(LCModelComponent):
display_name="Model",
info="The name of the model to use.",
options=GOOGLE_GENERATIVE_AI_MODELS,
value="gemini-1.5-pro",
value=GOOGLE_GENERATIVE_AI_MODELS[0],
refresh_button=True,
combobox=True,
),
Expand Down Expand Up @@ -137,7 +137,7 @@ def update_build_config(self, build_config: dotdict, field_value: Any, field_nam
ids = GOOGLE_GENERATIVE_AI_MODELS
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]
Comment on lines 138 to +140
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.

except Exception as e:
msg = f"Error getting model names: {e}"
raise ValueError(msg) from e
Expand Down
Loading