Skip to content

Add IBM Watsonx CPD Chat and Embeddings Components#10564

Closed
Empreiteiro wants to merge 8 commits into
langflow-ai:mainfrom
Empreiteiro:watson_ai_cpd
Closed

Add IBM Watsonx CPD Chat and Embeddings Components#10564
Empreiteiro wants to merge 8 commits into
langflow-ai:mainfrom
Empreiteiro:watson_ai_cpd

Conversation

@Empreiteiro
Copy link
Copy Markdown
Collaborator

@Empreiteiro Empreiteiro commented Nov 11, 2025

  • add new WatsonxAIComponent for text generation, supporting both SaaS and Cloud Pak for Data deployments
  • add new WatsonxEmbeddingsComponent for embedding generation with equivalent SaaS/CPD support

Summary by CodeRabbit

Release Notes

  • New Features
    • Added support for IBM watsonx.ai integration supporting both Cloud Pak for Data (CPD) on-premises and SaaS deployments
    • Introduced configurable language model component with dynamic credential handling and model selection
    • Introduced embedding generation component with multi-deployment support and customizable parameters

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.
@github-actions github-actions Bot added the community Pull Request from an external contributor label Nov 11, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 11, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Two 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

Cohort / File(s) Summary
IBM Watsonx.ai CPD Components
src/lfx/src/lfx/components/ibm/watsonx_cpd.py, src/lfx/src/lfx/components/ibm/watsonx_embedding_cpd.py
Added WatsonxAIComponentCPD and WatsonxEmbeddingsComponentCPD classes with model fetching from SaaS API, dynamic config updates based on deployment type (SaaS vs On-Prem CPD), credential handling for both modes, and model building with comprehensive parameter support. Both components support fallback to default model lists on API errors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Dynamic UI configuration logic: Verify correctness of field visibility and requirement updates based on deployment_type changes in both components
  • Credential handling branches: Ensure SaaS (API key) and CPD (username/password) authentication paths are properly differentiated and error-handled
  • API error handling and fallbacks: Check that model fetching gracefully falls back to defaults and logging is appropriate
  • Parameter parsing: Review JSON parsing for logit_bias and validation of optional generation hyperparameters
  • Consistency between components: Verify similar patterns are implemented consistently in both chat and embedding components

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • lucaseduoli
  • edwinjosechittilappilly

Pre-merge checks and finishing touches

Important

Pre-merge checks failed

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

❌ Failed checks (2 warnings, 2 inconclusive)
Check name Status Explanation Resolution
Test Quality And Coverage ⚠️ Warning No test files added for WatsonxAIComponentCPD and WatsonxEmbeddingsComponentCPD components with complex API integration and credential handling logic. Add comprehensive pytest test files covering fetch_models(), update_build_config(), build_model()/build_embeddings() methods with mocking for API calls and credential scenarios.
Test File Naming And Structure ⚠️ Warning Pull request adds two new components (WatsonxAIComponentCPD and WatsonxEmbeddingsComponentCPD) but includes no corresponding test files following the test_*.py naming convention in tests/components/ibm/ directory. Add test_watsonx_cpd.py and test_watsonx_embedding_cpd.py in tests/components/ibm/ with comprehensive pytest coverage for initialization, model fetching, configuration updates, and credential handling.
Test Coverage For New Implementations ❓ Inconclusive Component files (watsonx_cpd.py, watsonx_embedding_cpd.py) could not be located in repository despite extensive searching, preventing assessment of test coverage. Verify PR branch is checked out and component files are accessible; then confirm test files exist in standard test directory following naming convention test_watsonx_cpd.py and test_watsonx_embedding_cpd.py.
Excessive Mock Usage Warning ❓ Inconclusive No test files found for the new WatsonxAIComponentCPD and WatsonxEmbeddingsComponentCPD components to assess mock usage patterns. Locate or provide test files for these components to evaluate mock usage; if no tests exist, add appropriate unit tests using minimal mocking for external dependencies only.
✅ 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 accurately describes the main additions: two new IBM Watsonx components for CPD with chat and embeddings functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

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.

❤️ Share

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

Copy link
Copy Markdown
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: 3

📜 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 bd3f04e and 25584d6.

📒 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)

Comment on lines +165 to +167
except Exception:
logger.exception("Error fetching SaaS models. Using defaults.")
return WatsonxAIComponent._default_models
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
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.

Comment on lines +12 to +13
from lfx.io import BoolInput, IntInput, SecretStrInput, StrInput, TabInput
from lfx.schema.dotdict import dotdict
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
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.

Comment on lines +102 to +104
except Exception:
logger.exception("Could not fetch models from SaaS API.")
return WatsonxEmbeddingsComponent._default_models
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
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.

Copy link
Copy Markdown
Collaborator

@erichare erichare left a comment

Choose a reason for hiding this comment

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

@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.
@Empreiteiro Empreiteiro requested a review from erichare November 26, 2025 14:02
@Empreiteiro
Copy link
Copy Markdown
Collaborator Author

@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!

@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!

@erichare erichare removed their request for review March 11, 2026 20:56
@Empreiteiro Empreiteiro deleted the watson_ai_cpd branch April 18, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Pull Request from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants