Add IBM Watsonx CPD Chat and Embeddings Components#10564
Conversation
This file implements the WatsonxAIComponentCPD class, which integrates with IBM watsonx.ai for text generation. It includes input fields for configuration and methods for fetching models and building the language model client.
This file implements the WatsonxEmbeddingsComponentCPD class, which generates embeddings using IBM watsonx.ai for both SaaS and On-Prem deployments. It includes methods for fetching available models, updating build configurations based on deployment type, and building embeddings clients with the appropriate credentials.
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughTwo new IBM watsonx.ai components are introduced: WatsonxAIComponentCPD for chat and WatsonxEmbeddingsComponentCPD for embeddings. Both support dual deployment modes (SaaS and On-Premise CPD), featuring dynamic model loading from APIs, deployment-specific credential handling, and UI field visibility adjustments based on selected deployment type. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touchesImportant Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (2 warnings, 2 inconclusive)
✅ Passed checks (3 passed)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/lfx/src/lfx/components/ibm/watsonx_cpd.py(1 hunks)src/lfx/src/lfx/components/ibm/watsonx_embedding_cpd.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/lfx/src/lfx/components/ibm/watsonx_embedding_cpd.py (3)
src/lfx/src/lfx/field_typing/constants.py (1)
Embeddings(49-50)src/lfx/src/lfx/inputs/inputs.py (5)
BoolInput(414-426)IntInput(344-376)SecretStrInput(286-341)StrInput(126-182)TabInput(547-577)src/lfx/src/lfx/components/ibm/watsonx_cpd.py (2)
fetch_models(155-167)update_build_config(169-200)
src/lfx/src/lfx/components/ibm/watsonx_cpd.py (2)
src/lfx/src/lfx/components/ibm/watsonx_embedding_cpd.py (2)
fetch_models(92-104)update_build_config(106-138)src/lfx/src/lfx/components/ibm/watsonx.py (1)
WatsonxAIComponent(16-207)
| except Exception: | ||
| logger.exception("Error fetching SaaS models. Using defaults.") | ||
| return WatsonxAIComponent._default_models |
There was a problem hiding this comment.
Fix NameError in SaaS model fallback.
If fetch_models hits the exception path we return WatsonxAIComponent._default_models, but that class is not defined in this module, so we raise a NameError instead of falling back. Point the fallback at this class’s _default_models to keep SaaS model loading resilient.
- return WatsonxAIComponent._default_models
+ return WatsonxAIComponentCPD._default_models📝 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.
| except Exception: | |
| logger.exception("Error fetching SaaS models. Using defaults.") | |
| return WatsonxAIComponent._default_models | |
| except Exception: | |
| logger.exception("Error fetching SaaS models. Using defaults.") | |
| return WatsonxAIComponentCPD._default_models |
🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/ibm/watsonx_cpd.py around lines 165 to 167, the
exception handler returns WatsonxAIComponent._default_models which is not
defined and causes a NameError; change the fallback to use the current class's
default (e.g., return type(self)._default_models or
self.__class__._default_models) so the method returns the proper _default_models
defined on this class.
| from lfx.io import BoolInput, IntInput, SecretStrInput, StrInput, TabInput | ||
| from lfx.schema.dotdict import dotdict |
There was a problem hiding this comment.
Correct the input component import path.
Other components pull BoolInput, StrInput, etc. from lfx.inputs.inputs; importing them from lfx.io will raise at module import time because that module doesn’t expose these symbols. Swap to the existing inputs module so the component can load.
-from lfx.io import BoolInput, IntInput, SecretStrInput, StrInput, TabInput
+from lfx.inputs.inputs import BoolInput, IntInput, SecretStrInput, StrInput, TabInput📝 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.
| from lfx.io import BoolInput, IntInput, SecretStrInput, StrInput, TabInput | |
| from lfx.schema.dotdict import dotdict | |
| from lfx.inputs.inputs import BoolInput, IntInput, SecretStrInput, StrInput, TabInput | |
| from lfx.schema.dotdict import dotdict |
🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/ibm/watsonx_embedding_cpd.py around lines 12 to
13, the component incorrectly imports BoolInput, IntInput, SecretStrInput,
StrInput, TabInput from lfx.io which doesn't export them; update the import to
pull these symbols from lfx.inputs.inputs (e.g. from lfx.inputs.inputs import
BoolInput, IntInput, SecretStrInput, StrInput, TabInput) and leave the existing
dotdict import as-is so the module imports successfully.
| except Exception: | ||
| logger.exception("Could not fetch models from SaaS API.") | ||
| return WatsonxEmbeddingsComponent._default_models |
There was a problem hiding this comment.
Fix NameError in embeddings fallback.
When the SaaS model fetch fails we try to return WatsonxEmbeddingsComponent._default_models, but that class is undefined here, so we crash instead of falling back. Use this component’s _default_models list.
- return WatsonxEmbeddingsComponent._default_models
+ return WatsonxEmbeddingsComponentCPD._default_models📝 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.
| except Exception: | |
| logger.exception("Could not fetch models from SaaS API.") | |
| return WatsonxEmbeddingsComponent._default_models | |
| except Exception: | |
| logger.exception("Could not fetch models from SaaS API.") | |
| return WatsonxEmbeddingsComponentCPD._default_models |
🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/ibm/watsonx_embedding_cpd.py around lines 102 to
104, the except block returns WatsonxEmbeddingsComponent._default_models which
causes a NameError because that class name isn’t defined here; change the return
to use this component’s default list by returning self._default_models (or
type(self)._default_models if this is a classmethod) so the fallback uses the
correct attribute.
erichare
left a comment
There was a problem hiding this comment.
@Empreiteiro could you take a look at the ruff errors listed? if you go to the Files changed tab it should show them.
Also, maybe a quick test for the two components? Looks good to me otherwise!
Correcting ruff errors.
Correcting ruff errors.
@erichare, I corrected ruff's errors. Can you help me with the tests? I've never created tests for components before. Help me with these so I can do them in the future! |
Summary by CodeRabbit
Release Notes