Skip to content

feat: Add IBM watsonx.ai and Ollama to LanguageModelComponent#10471

Merged
edwinjosechittilappilly merged 18 commits into
mainfrom
feat-ibm-watsonx-ollama-models
Nov 5, 2025
Merged

feat: Add IBM watsonx.ai and Ollama to LanguageModelComponent#10471
edwinjosechittilappilly merged 18 commits into
mainfrom
feat-ibm-watsonx-ollama-models

Conversation

@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

@edwinjosechittilappilly edwinjosechittilappilly commented Nov 1, 2025

This pull request significantly enhances the LanguageModelComponent in the Basic Prompt Chaining.json starter project by adding support for IBM watsonx.ai and Ollama providers, enabling dynamic model selection and configuration for these new providers. It also refactors the input configuration and model-building logic to be more extensible and robust, including the ability to fetch available models from provider APIs. The changes improve the flexibility and usability of the component for users who want to work with a broader range of language model providers.

New Provider Integrations

  • Added support for IBM watsonx.ai and Ollama as selectable model providers, including new input fields for their specific configuration (API endpoint, project ID, and base URL).
  • Implemented logic to fetch available models dynamically from the IBM watsonx.ai and Ollama APIs, updating the model selection dropdown based on the provider and endpoint.

Input and Configuration Refactoring

  • Refactored the input configuration to show/hide relevant fields depending on the selected provider, improving the user experience and reducing input errors.
  • Added new input types (DropdownInput, StrInput, MessageTextInput) for provider-specific settings, such as base_url, project_id, and ollama_base_url. (F21eb8b

Summary by CodeRabbit

Release Notes

  • New Features
    • Added IBM watsonx.ai as a language model provider with dynamic model discovery
    • Added Ollama as a language model provider with automatic model fetching
    • Enhanced configuration options for provider-specific settings (API endpoints, project identifiers)
    • Improved model selection with intelligent fallback handling across all starter projects

Extended LanguageModelComponent to support IBM watsonx.ai as a provider, including dynamic model fetching, new input fields for API endpoint and project ID, and integration with ChatWatsonx. Updated starter project JSONs to reflect these changes and enable selection of IBM watsonx.ai models.
Extended the LanguageModelComponent to support Ollama as a provider, including dynamic model fetching from the Ollama API and related UI input fields. Updated build_model and update_build_config logic to handle Ollama-specific configuration and improved provider switching logic for all supported providers.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 1, 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

Extends LanguageModelComponent across multiple starter projects and core codebase to support IBM watsonx.ai and Ollama as new LLM providers. Adds dynamic model discovery helpers, new provider-specific configuration inputs (base_url, project_id, ollama_base_url), and expands build and update logic to handle provider-specific validation, instantiation, and UI visibility toggling.

Changes

Cohort / File(s) Change Summary
Starter Project Language Model Components
src/backend/base/langflow/initial_setup/starter_projects/Basic Prompt Chaining.json, Basic Prompting.json, Blog Writer.json, Custom Component Generator.json, Document Q&A.json, Financial Report Parser.json, Hybrid Search RAG.json, Image Sentiment Analysis.json, Instagram Copywriter.json, Market Research.json, Meeting Summary.json, Memory Chatbot.json, Portfolio Website Code Generator.json, Research Agent.json, Research Translation Loop.json, SEO Keyword Generator.json, Text Sentiment Analysis.json, Twitter Thread Generator.json, Vector Store RAG.json, Youtube Analysis.json
Replaced LanguageModelComponent implementation with expanded multi-provider version. Added static methods fetch_ibm_models(base_url: str) -> list[str] and fetch_ollama_models(base_url: str) -> list[str] for dynamic model discovery. Expanded inputs to include base_url (watsonx API endpoint), project_id (watsonx project ID), and ollama_base_url (Ollama API URL). Extended build_model() to instantiate ChatWatsonx for IBM watsonx.ai and ChatOllama for Ollama providers. Enhanced update_build_config() to manage per-provider field visibility and dynamically populate model options for IBM and Ollama when base URLs change.
Core Language Model Component
src/lfx/src/lfx/components/models/language_model.py
Added static methods fetch_ibm_models(base_url: str) -> list[str] and fetch_ollama_models(base_url: str) -> list[str] to LanguageModelComponent. Introduced new inputs for IBM watsonx.ai (base_url, project_id) and Ollama (ollama_base_url). Extended build_model() to route IBM watsonx.ai and Ollama providers with appropriate validation and client instantiation. Enhanced update_build_config() to toggle field visibility per provider and refresh Ollama/IBM model lists when endpoints change.

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as Build Config UI
    participant Component as LanguageModelComponent
    participant IBM as IBM watsonx.ai API
    participant Ollama as Ollama API
    participant LLM as LLM Client

    User->>UI: Select Provider
    UI->>Component: update_build_config(provider=X)
    
    alt Provider = "IBM watsonx.ai"
        Component->>Component: Show base_url, project_id fields
        Component->>IBM: fetch_ibm_models(base_url)
        IBM-->>Component: Model list / Error
        Component->>UI: Update model_name options
    else Provider = "Ollama"
        Component->>Component: Show ollama_base_url field
        Component->>Ollama: fetch_ollama_models(ollama_base_url)
        Ollama-->>Component: Model list / Empty list
        Component->>UI: Update model_name options
    else Provider = "OpenAI" / "Anthropic" / "Google"
        Component->>Component: Show/hide respective API key field
        Component->>UI: Update field visibility
    end
    
    User->>Component: build_model()
    
    alt Provider = "IBM watsonx.ai"
        Component->>Component: Validate api_key, base_url, project_id
        Component->>LLM: ChatWatsonx(apikey, url, project_id, model_id)
    else Provider = "Ollama"
        Component->>Component: Validate ollama_base_url, model_name
        Component->>Component: Normalize base_url (strip /v1 if present)
        Component->>LLM: ChatOllama(base_url, model, temperature)
    else Other providers
        Component->>LLM: Instantiate provider-specific client
    end
    
    LLM-->>Component: Model instance
    Component-->>User: Ready for inference
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • High file count: 21 files modified across starter projects and core codebase, requiring understanding of consistency across implementations
  • Logic density: Multiple interconnected concerns per file—provider routing, dynamic UI visibility, external API calls with error handling, URL normalization, and dynamic model population
  • Pattern repetition: While the same LanguageModelComponent pattern repeats across 20 starter project JSONs, each JSON requires verification for identical implementation and no subtle divergence
  • External integrations: New dependencies on IBM watsonx.ai and Ollama APIs introduce validation points for error handling, fallback logic, and API contract assumptions
  • Dynamic configuration: Complex update_build_config() logic with conditional field visibility and async model fetching—requires careful verification of state management and edge cases
  • Areas requiring extra attention:
    • Consistency verification across 20 nearly identical JSON starter project implementations
    • Error handling paths in fetch_ibm_models() and fetch_ollama_models() and their fallback behavior
    • URL normalization logic for Ollama (stripping /v1 suffix) and corresponding warning messages
    • Provider-specific field visibility toggling in update_build_config() to ensure no field leakage between providers
    • Backward compatibility with existing OpenAI/Anthropic/Google provider paths
    • Model selection and option population logic when switching providers or changing base URLs

Possibly related PRs

Suggested labels

enhancement, refactor, size:XXL, lgtm

Suggested reviewers

  • ogabrielluiz
  • lucaseduoli
  • jordanrfrazier

Pre-merge checks and finishing touches

❌ Failed checks (1 error, 4 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error The existing test file src/backend/tests/unit/components/models/test_language_model_component.py (219 lines) contains tests only for OpenAI, Anthropic, and Google providers. The grep search confirms there are "No IBM/Ollama references found in test file," demonstrating that this file has not been updated to test the new IBM watsonx.ai and Ollama providers added in the PR. The test file currently includes only 13 test methods covering provider selection, model creation, missing API key validation, and live API integration for the three existing providers. There are no tests for the new fetch_ibm_models(), fetch_ollama_models() static methods, IBM watsonx.ai or Ollama branches in build_model(), provider-specific field visibility toggling in update_build_config(), or URL scheme validation for SSRF prevention that the PR introduces. Additionally, git history shows this test file was last modified for adding OpenAI reasoning model support, not for the new providers being added in this PR. The existing test file must be updated to include comprehensive coverage for the new IBM watsonx.ai and Ollama providers. Required additions include: (1) test methods test_update_build_config_ibm and test_update_build_config_ollama to verify field visibility and model list population; (2) test methods test_ibm_model_creation and test_ollama_model_creation for ChatWatsonx and ChatOllama instantiation; (3) test methods for missing credentials validation (test_build_model_ibm_missing_credentials, test_build_model_ollama_missing_url); (4) unit tests for fetch_ibm_models() and fetch_ollama_models() with mocked HTTP responses covering both success and error scenarios; (5) SSRF validation tests confirming URL scheme checks reject invalid protocols; (6) regression tests ensuring existing OpenAI/Anthropic/Google tests continue to pass. Use unittest.mock to mock external API calls and requests.get to avoid dependencies on actual IBM/Ollama services during testing.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 The PR adds IBM watsonx.ai and Ollama provider support to LanguageModelComponent with two new static methods (fetch_ibm_models, fetch_ollama_models), three new input fields, and extended build/config logic. However, the existing test file test_language_model_component.py contains only 13 tests covering the original three providers (OpenAI, Anthropic, Google), with zero new tests added for the new providers or their complex functionality. The new code includes external API calls, provider-specific branching, dynamic URL handling with special case processing (/v1 suffix stripping), and conditional field visibility toggling—all untested. This represents a significant test coverage gap for high-complexity additions. Add tests to src/backend/tests/unit/components/models/test_language_model_component.py following the existing test pattern for all three new providers: (1) add test_update_build_config_ibm and test_update_build_config_ollama mirroring the existing provider tests, (2) add test_ibm_model_creation and test_ollama_model_creation to verify ChatWatsonx and ChatOllama instantiation, (3) add error tests for missing credentials (test_build_model_ibm_missing_credentials, test_build_model_ollama_missing_base_url), (4) add unit tests for both fetch methods with mocked requests.get() covering successful responses and exception handling, and (5) add tests validating dynamic model population when base_url or ollama_base_url field values change. Use pytest with mock decorators to isolate external API dependencies.
Test File Naming And Structure ⚠️ Warning An existing test file (src/backend/tests/unit/components/models/test_language_model_component.py) with proper naming convention and pytest structure is present in the repository. However, this test file has not been modified in the PR, and it lacks test coverage for the newly added IBM watsonx.ai and Ollama providers. The core Python file src/lfx/src/lfx/components/models/language_model.py introduces two new static methods (fetch_ibm_models and fetch_ollama_models), expands the provider options from 3 to 5 (adding IBM watsonx.ai and Ollama), adds 3 new input fields (base_url, project_id, ollama_base_url), and extends build_model and update_build_config methods to handle these new providers. The existing test file contains 13 test methods covering only OpenAI, Anthropic, and Google providers, with no corresponding tests for the new providers or their associated helper methods. Update src/backend/tests/unit/components/models/test_language_model_component.py to add comprehensive test coverage for the new IBM watsonx.ai and Ollama providers. Add test methods following the established async pattern: test_update_build_config_ibm_watsonx, test_update_build_config_ollama, test_ibm_watsonx_model_creation, test_ollama_model_creation, test_build_model_ibm_watsonx_missing_api_key, test_build_model_ollama_missing_base_url, and unit tests for the static methods test_fetch_ibm_models_success, test_fetch_ibm_models_error, test_fetch_ollama_models_success, and test_fetch_ollama_models_error with mocked HTTP responses. Ensure tests cover both positive scenarios and error conditions for each new provider to maintain consistency with the existing test structure.
Excessive Mock Usage Warning ⚠️ Warning
✅ 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 IBM watsonx.ai and Ollama to LanguageModelComponent" directly and clearly summarizes the main change across all modified files. The title accurately reflects the primary objective—extending the LanguageModelComponent to support two new LLM providers (IBM watsonx.ai and Ollama). It is concise, uses appropriate semantic versioning conventions, contains no vague terms or noise, and provides sufficient specificity that a team member reviewing git history would immediately understand the purpose of the changeset. The title does not attempt to cover implementation details like model fetching logic or input field configurations, which is appropriate for a pull request title.

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 31.41%. Comparing base (ed4385b) to head (d0f6b97).
⚠️ Report is 1 commits behind head on main.

❌ Your project status has failed because the head coverage (39.37%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10471      +/-   ##
==========================================
+ Coverage   31.39%   31.41%   +0.01%     
==========================================
  Files        1325     1325              
  Lines       59987    59987              
  Branches     8980     8980              
==========================================
+ Hits        18834    18844      +10     
+ Misses      40246    40237       -9     
+ Partials      907      906       -1     
Flag Coverage Δ
backend 50.93% <ø> (+0.05%) ⬆️
frontend 13.57% <ø> (ø)
lfx 39.37% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 1, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 15%
14.67% (3955/26947) 7.45% (1533/20552) 9% (532/5906)

Unit Test Results

Tests Skipped Failures Errors Time
1588 0 💤 0 ❌ 0 🔥 19.491s ⏱️

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 1, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for IBM watsonx.ai and Ollama as model providers to the LanguageModelComponent, expanding the platform's LLM integration capabilities beyond OpenAI, Anthropic, and Google. The changes implement dynamic model fetching from provider APIs and introduce provider-specific configuration fields.

Key Changes:

  • Added ChatWatsonx and ChatOllama integrations with respective provider-specific input fields
  • Implemented API-based model discovery for IBM watsonx.ai and Ollama providers
  • Enhanced input configuration logic to conditionally show/hide fields based on selected provider

Reviewed Changes

Copilot reviewed 21 out of 23 changed files in this pull request and generated no comments.

File Description
src/lfx/src/lfx/components/models/language_model.py Core implementation adding IBM watsonx.ai and Ollama providers with model fetching logic
src/backend/base/langflow/initial_setup/starter_projects/*.json Updated embedded LanguageModelComponent code in 14 starter project files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 1, 2025
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: 14

Caution

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

⚠️ Outside diff range comments (27)
src/backend/base/langflow/initial_setup/starter_projects/Image Sentiment Analysis.json (3)

1200-1377: Template/UI mismatch: new providers not exposed.

The template still lists only OpenAI/Anthropic/Google and lacks base_url, project_id, and ollama_base_url fields. Users won’t see IBM/Ollama options in the starter without regenerating the node template. Please re-export/regenerate this starter so template.provider.options includes “IBM watsonx.ai” and “Ollama” and the new inputs are present. Based on learnings.


1200-1408: The verification reveals a critical issue: langchain-ibm is properly declared in src/backend/base/pyproject.toml (line 91), but langchain-ollama is not shown in the pyproject.toml output, despite being present in lock files and imported by the starter project JSON files. This confirms the reviewer's concern about potential runtime ImportError.

Add langchain-ollama to src/backend/base/pyproject.toml dependencies.

The embedded Python code in the starter project JSON files (e.g., lines 1200-1408 in Image Sentiment Analysis.json) imports from langchain_ollama import ChatOllama, but this dependency is missing from the project's declared dependencies. Ensure both are explicitly declared:

  • langchain-ibm>=0.3.8,<1.0.0 (already present)
  • langchain-ollama==0.3.10 (or similar pinned version based on lock file)

1235-1408: Add Bearer token authentication and update API version to 2024-03-14.

The /ml/v1/foundation_model_specs endpoint requires authentication (Authorization: Bearer ...). The code makes an unauthenticated request that will fail on most IBM watsonx.ai tenants. Additionally, the current active API version to use is 2024-03-14, not 2024-09-16.

Update fetch_ibm_models() to:

  1. Accept an optional auth token parameter (or read from environment/config)
  2. Pass the Authorization header in the request
  3. Update params = {"version": "2024-03-14", ...}
  4. Handle 401/403 responses distinctly (auth failure) before catching all exceptions
src/backend/base/langflow/initial_setup/starter_projects/Hybrid Search RAG.json (2)

1493-1771: Template/UI mismatch: expose IBM/Ollama and new inputs.

The template for these nodes still shows only OpenAI/Anthropic/Google. Regenerate the starter so provider options and fields (watsonx base_url/project_id, ollama_base_url) are present.


1264-1471: Update IBM watsonx API version parameter to a documented version.

IBM's official documentation shows /ml/v1/foundation_model_specs with versions 2024-12-10 and 2024-05-01, but the code uses version 2024-09-16, which is not documented in IBM's official API reference. Update to a supported version to avoid potential runtime failures.

The ChatOpenAI constructor kwarg is verified as correct—model_name is the proper parameter with model as an alias in langchain-openai 0.3.x.

src/backend/base/langflow/initial_setup/starter_projects/Twitter Thread Generator.json (1)

2035-2070: Starter template ‘provider’ options don’t include IBM/Ollama

The template still lists only OpenAI/Anthropic/Google, while the component code supports IBM watsonx.ai and Ollama. Sync to avoid a confusing UI.

-                "options": [
-                  "OpenAI",
-                  "Anthropic",
-                  "Google"
-                ],
+                "options": [
+                  "OpenAI",
+                  "Anthropic",
+                  "Google",
+                  "IBM watsonx.ai",
+                  "Ollama"
+                ],
-                "options_metadata": [
+                "options_metadata": [
                   { "icon": "OpenAI" },
                   { "icon": "Anthropic" },
-                  { "icon": "Google" }
+                  { "icon": "GoogleGenerativeAI" },
+                  { "icon": "WatsonxAI" },
+                  { "icon": "Ollama" }
                 ],
src/backend/base/langflow/initial_setup/starter_projects/Memory Chatbot.json (1)

1434-1468: Template provider options missing IBM/Ollama

Align with component capabilities.

-                "options": [
-                  "OpenAI",
-                  "Anthropic",
-                  "Google"
-                ],
+                "options": [
+                  "OpenAI",
+                  "Anthropic",
+                  "Google",
+                  "IBM watsonx.ai",
+                  "Ollama"
+                ],
-                "options_metadata": [
+                "options_metadata": [
                   { "icon": "OpenAI" },
                   { "icon": "Anthropic" },
-                  { "icon": "GoogleGenerativeAI" }
+                  { "icon": "GoogleGenerativeAI" },
+                  { "icon": "WatsonxAI" },
+                  { "icon": "Ollama" }
                 ],
src/backend/base/langflow/initial_setup/starter_projects/SEO Keyword Generator.json (1)

1043-1069: Provider options in template should include IBM/Ollama

Expose new providers in starter template.

-                "options": [
-                  "OpenAI",
-                  "Anthropic",
-                  "Google"
-                ],
+                "options": [
+                  "OpenAI",
+                  "Anthropic",
+                  "Google",
+                  "IBM watsonx.ai",
+                  "Ollama"
+                ],
-                "options_metadata": [
+                "options_metadata": [
                   { "icon": "OpenAI" },
                   { "icon": "Anthropic" },
-                  { "icon": "GoogleGenerativeAI" }
+                  { "icon": "GoogleGenerativeAI" },
+                  { "icon": "WatsonxAI" },
+                  { "icon": "Ollama" }
                 ],
src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json (5)

3320-3360: ChatOpenAI: wrong parameter names cause runtime failure (use model and api_key).

ChatOpenAI expects model= and api_key=, not model_name= and openai_api_key=. This will raise a validation error at build time. Also avoid passing temperature=None; omit the arg instead. (api.python.langchain.com)

Apply this diff inside the code string:

-            return ChatOpenAI(
-                model_name=model_name,
-                temperature=temperature,
-                streaming=stream,
-                openai_api_key=self.api_key,
-            )
+            openai_kwargs = {
+                "model": model_name,
+                "streaming": stream,
+                "api_key": self.api_key,
+            }
+            if temperature is not None:
+                openai_kwargs["temperature"] = temperature
+            return ChatOpenAI(**openai_kwargs)

3310-3345: Starter template UI doesn’t list the new providers. Update provider.options.

The saved template still shows only ["OpenAI","Anthropic","Google"], so IBM/Ollama won’t appear in this starter. Update options and icons.

               "options": [
-                "OpenAI",
-                "Anthropic",
-                "Google"
+                "OpenAI",
+                "Anthropic",
+                "Google",
+                "IBM watsonx.ai",
+                "Ollama"
               ],
               "options_metadata": [
                 { "icon": "OpenAI" },
                 { "icon": "Anthropic" },
-                { "icon": "GoogleGenerativeAI" }
+                { "icon": "GoogleGenerativeAI" },
+                { "icon": "WatsonxAI" },
+                { "icon": "Ollama" }
               ],

3126-3134: Expose provider-specific fields in the starter template (field_order).

Without adding these, the new inputs won’t be visible/ordered in the UI.

               "field_order": [
                 "provider",
                 "model_name",
                 "api_key",
+                "base_url",
+                "project_id",
+                "ollama_base_url",
                 "input_value",
                 "system_message",
                 "stream",
                 "temperature"
               ],

3209-3418: Add template entries for new inputs (base_url, project_id, ollama_base_url).

The code defines these inputs, but the template lacks their definitions; add minimal stubs with show:false so the UI can render/serialize them.

               "api_key": {
                 "_input_type": "SecretStrInput",
                 "advanced": false,
                 "display_name": "OpenAI API Key",
                 "dynamic": false,
                 "info": "Model Provider API key",
                 "input_types": [],
                 "load_from_db": true,
                 "name": "api_key",
                 "password": true,
                 "placeholder": "",
                 "real_time_refresh": true,
                 "required": false,
                 "show": true,
                 "title_case": false,
                 "type": "str",
                 "value": "OPENAI_API_KEY"
               },
+              "base_url": {
+                "_input_type": "DropdownInput",
+                "advanced": false,
+                "display_name": "watsonx API Endpoint",
+                "dynamic": false,
+                "info": "The base URL of the API (IBM watsonx.ai only)",
+                "name": "base_url",
+                "options": [
+                  "https://us-south.ml.cloud.ibm.com",
+                  "https://eu-de.ml.cloud.ibm.com",
+                  "https://eu-gb.ml.cloud.ibm.com",
+                  "https://au-syd.ml.cloud.ibm.com",
+                  "https://jp-tok.ml.cloud.ibm.com",
+                  "https://ca-tor.ml.cloud.ibm.com"
+                ],
+                "placeholder": "",
+                "real_time_refresh": true,
+                "required": false,
+                "show": false,
+                "title_case": false,
+                "type": "str",
+                "value": "https://us-south.ml.cloud.ibm.com"
+              },
+              "project_id": {
+                "_input_type": "StrInput",
+                "advanced": false,
+                "display_name": "watsonx Project ID",
+                "dynamic": false,
+                "info": "The project ID associated with the foundation model (IBM watsonx.ai only)",
+                "name": "project_id",
+                "placeholder": "",
+                "required": false,
+                "show": false,
+                "title_case": false,
+                "type": "str",
+                "value": ""
+              },
+              "ollama_base_url": {
+                "_input_type": "MessageTextInput",
+                "advanced": false,
+                "display_name": "Ollama API URL",
+                "dynamic": false,
+                "info": "Endpoint of the Ollama API (Ollama only). Defaults to http://localhost:11434",
+                "name": "ollama_base_url",
+                "placeholder": "",
+                "real_time_refresh": true,
+                "required": false,
+                "show": false,
+                "title_case": false,
+                "type": "str",
+                "value": "http://localhost:11434"
+              },

3380-3418: Extend system_message visibility to o3/o4 reasoning models.

The current code (line 169) only hides system_message for o1* models, but leaves it in undefined state for o3* and o4* families. Since OpenAI o3 and o4-mini support system messages, the code should explicitly show system_message for these models.

Current behavior at lines 165–176 of src/lfx/src/lfx/components/openai/openai_chat_model.py:

  • Reasoning models (line 165): Hide temperature/seed; conditionally hide system_message only for o1*
  • Chat models (line 171): Show temperature/seed/system_message
  • Gap: o3/o4 reasoning models never reach the show=True block, leaving system_message visibility undefined

Fix: After line 170, explicitly show system_message for o3/o4 models:

if field_value.startswith("o1") and "system_message" in build_config:
    build_config["system_message"]["show"] = False
elif "system_message" in build_config:  # o3/o4 models support system_message
    build_config["system_message"]["show"] = True
src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json (1)

1987-2196: Add missing ollama_base_url template field definition.

The verification found that base_url (line 2734) and project_id (line 3097) are properly defined in the template section. However, ollama_base_url is referenced throughout the code but lacks a corresponding template field definition. The code attempts to manipulate build_config["ollama_base_url"] in the update_build_config method and set its visibility, but the template definition is missing. This will cause a KeyError at runtime.

Add the ollama_base_url field definition to the template section between project_id and input_value:

"ollama_base_url": {
  "_input_type": "MessageTextInput",
  "advanced": false,
  "display_name": "Ollama API URL",
  "dynamic": false,
  "info": "Endpoint of the Ollama API (Ollama only). Defaults to http://localhost:11434",
  "input_types": ["Message"],
  "list": false,
  "list_add_label": "Add More",
  "load_from_db": false,
  "multiline": false,
  "name": "ollama_base_url",
  "placeholder": "",
  "required": false,
  "show": false,
  "title_case": false,
  "tool_mode": false,
  "trace_as_input": true,
  "trace_as_metadata": true,
  "type": "str",
  "value": "http://localhost:11434"
}
src/backend/base/langflow/initial_setup/starter_projects/Custom Component Generator.json (7)

2667-2674: Verify requests library dependency.

The code uses requests.get() in both fetch_ibm_models() and fetch_ollama_models() static methods, but requests is not listed in the component's declared dependencies (lines 2524-2543).

Ensure requests is added to the project dependencies if not already present.


2651-2670: Validate error handling and API fallback logic in model fetching methods.

The fetch_ibm_models() method catches all exceptions broadly (except Exception) and silently falls back to IBM_WATSONX_DEFAULT_MODELS, which masks potential configuration errors (invalid endpoint, authentication failures, etc.). This could lead to users unaware that their custom base_url is not working. Similarly, fetch_ollama_models() returns an empty list on failure.

Consider distinguishing between transient errors (network timeout) and configuration errors (invalid URL, auth failure) to provide more targeted feedback:

@staticmethod
def fetch_ibm_models(base_url: str) -> list[str]:
    """Fetch available models from the watsonx.ai API."""
    try:
        endpoint = f"{base_url}/ml/v1/foundation_model_specs"
        params = {"version": "2024-09-16", "filters": "function_text_chat,!lifecycle_withdrawn"}
        response = requests.get(endpoint, params=params, timeout=10)
        response.raise_for_status()
        data = response.json()
        models = [model["model_id"] for model in data.get("resources", [])]
        return sorted(models)
    except requests.exceptions.HTTPError as e:
        logger.error(f"HTTP error fetching IBM models: {e.response.status_code} - {e}")
        return IBM_WATSONX_DEFAULT_MODELS
    except requests.exceptions.Timeout:
        logger.warning("Timeout fetching IBM models. Using default models.")
        return IBM_WATSONX_DEFAULT_MODELS
    except Exception as e:  # noqa: BLE001
        logger.exception(f"Unexpected error fetching IBM models: {e}")
        return IBM_WATSONX_DEFAULT_MODELS

2674-2690: Implement proper URL validation before API calls.

The fetch_ollama_models() method applies URL normalization (transform_localhost_url, removesuffix, etc.) but doesn't validate that base_url is a non-empty, properly formatted URL before making requests. An invalid or malformed URL could cause unexpected behavior or resource leaks.

Add URL validation before the API call:

@staticmethod
def fetch_ollama_models(base_url: str) -> list[str]:
    """Fetch available models from the Ollama API."""
    try:
        if not base_url or not isinstance(base_url, str):
            logger.warning("Invalid Ollama base_url provided")
            return []
        
        # Strip /v1 suffix if present, as Ollama API endpoints are at root level
        base_url = base_url.rstrip("/").removesuffix("/v1")
        if not base_url.endswith("/"):
            base_url = base_url + "/"
        base_url = transform_localhost_url(base_url)
        
        # Validate transformed URL is not empty
        if not base_url:
            logger.warning("Ollama base_url transformation resulted in empty URL")
            return []
        
        tags_url = urljoin(base_url, "api/tags")
        response = requests.get(tags_url, timeout=10)
        response.raise_for_status()
        data = response.json()
        models = [model["name"] for model in data.get("models", [])]
        return sorted(models)
    except Exception:  # noqa: BLE001
        logger.exception("Error fetching Ollama models. Returning empty list.")
        return []

2704-2766: Verify field validation in build_model() method.

The method validates required fields for each provider (e.g., if not self.api_key: raise ValueError), but there's a subtle issue: the api_key field is marked required=False in the inputs (line 2609), which allows users to skip setting it and encounter the validation error at build time rather than at input time.

Two approaches to fix:

  1. Set required=True for provider-specific API keys (preferred for better UX)
  2. Add more descriptive validation messages and early warnings

Additionally, for IBM watsonx.ai, the project_id field should also be marked required=True when the provider is IBM watsonx.ai.

Consider adding provider-dependent required field toggling in update_build_config():

def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:
    if field_name == "provider":
        if field_value == "OpenAI":
            build_config["api_key"]["required"] = True
            build_config["api_key"]["display_name"] = "OpenAI API Key"
            # ... rest of config
        elif field_value == "IBM watsonx.ai":
            build_config["api_key"]["required"] = True
            build_config["base_url"]["required"] = True
            build_config["project_id"]["required"] = True
            # ... rest of config
        elif field_value == "Ollama":
            build_config["api_key"]["required"] = False
            build_config["ollama_base_url"]["required"] = True
            # ... rest of config

2800-2828: Evaluate Ollama URL transformation logic for edge cases.

The Ollama URL handling strips /v1 suffix and normalizes localhost URLs, but the logic has potential edge cases:

  1. What if transformed_base_url is None or empty after transform_localhost_url()?
  2. The warning about /v1 suffix is logged but the behavior is transparent to the user in the UI—they may not see why their input was modified.

Add null/empty check and consider surfacing the transformation to the user:

if provider == "Ollama":
    if not self.ollama_base_url:
        msg = "Ollama API URL is required when using Ollama provider"
        raise ValueError(msg)
    if not model_name:
        msg = "Model name is required when using Ollama provider"
        raise ValueError(msg)

    transformed_base_url = transform_localhost_url(self.ollama_base_url)
    
    # Validate transformation succeeded
    if not transformed_base_url:
        msg = f"Failed to transform Ollama URL: {self.ollama_base_url}"
        raise ValueError(msg)

    # Check if URL contains /v1 suffix (OpenAI-compatible mode)
    if transformed_base_url.rstrip("/").endswith("/v1"):
        # Strip /v1 suffix and log warning
        transformed_base_url = transformed_base_url.rstrip("/").removesuffix("/v1")
        logger.warning(
            "Detected '/v1' suffix in Ollama base URL. The Ollama component uses the native Ollama API, "
            "not the OpenAI-compatible API. The '/v1' suffix has been automatically removed. "
            "If you want to use the OpenAI-compatible API, please use the OpenAI component instead. "
            "Learn more at https://docs.ollama.com/openai#openai-compatibility"
        )

    return ChatOllama(
        base_url=transformed_base_url,
        model=model_name,
        temperature=temperature,
    )

2682-2717: Verify provider options in template match code.

The template's provider dropdown (lines 2682-2706) shows options ["OpenAI", "Anthropic", "Google"] but the code supports 5 providers including "IBM watsonx.ai" and "Ollama". The template is out of sync with the implementation.

Update the template's provider field to include all five providers:

"provider": {
    "_input_type": "DropdownInput",
    "advanced": false,
    "combobox": false,
    "dialog_inputs": {},
    "display_name": "Model Provider",
    "dynamic": false,
    "info": "Select the model provider",
    "name": "provider",
    "options": [
      "OpenAI",
      "Anthropic",
      "Google",
      "IBM watsonx.ai",
      "Ollama"
    ],
    "options_metadata": [
      {"icon": "OpenAI"},
      {"icon": "Anthropic"},
      {"icon": "GoogleGenerativeAI"},
      {"icon": "WatsonxAI"},
      {"icon": "Ollama"}
    ],
    "placeholder": "",
    "real_time_refresh": true,
    "required": false,
    "show": true,
    "title_case": false,
    "toggle": false,
    "tool_mode": false,
    "trace_as_metadata": true,
    "type": "str",
    "value": "Anthropic"
}

2594-2610: Add missing input field configurations to the template section for the three new provider-specific fields.

The template JSON at lines 2592–2800 is indeed missing serialized configurations for base_url, project_id, and ollama_base_url. While these fields are defined in the embedded component code, they have no corresponding template entries with _input_type, display_name, options, and metadata. The template ends at line 2789 with only eight fields (api_key, code, input_value, model_name, provider, stream, system_message, temperature).

Add JSON configurations for:

  • base_url: DropdownInput with IBM_WATSONX_URLS options
  • project_id: StrInput
  • ollama_base_url: MessageTextInput

These should be inserted into the template object before the closing "tool_mode": false line, following the same structure as existing fields (e.g., api_key).

src/backend/base/langflow/initial_setup/starter_projects/Youtube Analysis.json (1)

2514-2688: I'll verify the exact constructor signatures by searching for more detailed documentation on these specific library versions.

Based on the official LangChain documentation, I can now provide the definitive verification:

ChatOpenAI (langchain_openai): Official examples show model= and api_key= as the correct parameters, not model_name and openai_api_key.

ChatAnthropic (langchain_anthropic): The parameter is anthropic_api_key with an alias api_key, meaning both work but api_key is the aliased form. Official examples show using model and api_key=.


Fix ChatOpenAI and ChatAnthropic constructor arguments.

The current code uses incorrect parameter names that will cause runtime failures:

  • ChatOpenAI: Change model_name= to model= and openai_api_key= to api_key=
  • ChatAnthropic: Change anthropic_api_key= to api_key= (for consistency with ChatOpenAI and modern LangChain patterns)
             return ChatOpenAI(
-                model_name=model_name,
+                model=model_name,
                 temperature=temperature,
                 streaming=stream,
-                openai_api_key=self.api_key,
+                api_key=self.api_key,
             )
         if provider == "Anthropic":
             if not self.api_key:
                 msg = "Anthropic API key is required when using Anthropic provider"
                 raise ValueError(msg)
             return ChatAnthropic(
                 model=model_name,
                 temperature=temperature,
                 streaming=stream,
-                anthropic_api_key=self.api_key,
+                api_key=self.api_key,
             )
src/backend/base/langflow/initial_setup/starter_projects/Research Translation Loop.json (1)

1471-1505: UI provider options not updated — IBM/Ollama missing. Users can’t select new providers.

The serialized template still lists only OpenAI/Anthropic/Google. Update options and icons to expose the new backends.

-                "options": [
-                  "OpenAI",
-                  "Anthropic",
-                  "Google"
-                ],
-                "options_metadata": [
-                  { "icon": "OpenAI" },
-                  { "icon": "Anthropic" },
-                  { "icon": "GoogleGenerativeAI" }
-                ],
+                "options": [
+                  "OpenAI",
+                  "Anthropic",
+                  "Google",
+                  "IBM watsonx.ai",
+                  "Ollama"
+                ],
+                "options_metadata": [
+                  { "icon": "OpenAI" },
+                  { "icon": "Anthropic" },
+                  { "icon": "GoogleGenerativeAI" },
+                  { "icon": "WatsonxAI" },
+                  { "icon": "Ollama" }
+                ],
src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json (1)

2862-2896: UI provider options not updated for the new providers.

Both LanguageModelComponent templates here still list only three providers. Add IBM watsonx.ai and Ollama (and icons) so the UI exposes the new paths.

-                "options": [
-                  "OpenAI",
-                  "Anthropic",
-                  "Google"
-                ],
-                "options_metadata": [
-                  { "icon": "OpenAI" },
-                  { "icon": "Anthropic" },
-                  { "icon": "GoogleGenerativeAI" }
-                ],
+                "options": [
+                  "OpenAI",
+                  "Anthropic",
+                  "Google",
+                  "IBM watsonx.ai",
+                  "Ollama"
+                ],
+                "options_metadata": [
+                  { "icon": "OpenAI" },
+                  { "icon": "Anthropic" },
+                  { "icon": "GoogleGenerativeAI" },
+                  { "icon": "WatsonxAI" },
+                  { "icon": "Ollama" }
+                ],

Also applies to: 3183-3218

src/backend/base/langflow/initial_setup/starter_projects/Text Sentiment Analysis.json (3)

1511-1531: Ollama model fetching returns empty list on error; inconsistent with IBM fallback.

The fetch_ollama_models() method returns an empty list when model fetching fails, whereas fetch_ibm_models() returns default models. This inconsistency could lead to confusion: IBM providers always have selectable defaults, but Ollama users may be left with no options if the endpoint is unreachable.

Additionally, a KeyError may occur if a model object lacks a "name" key.

Apply this diff to improve robustness and consistency:

         models = [model["name"] for model in data.get("models", [])]
         return sorted(models)
     except Exception:
         logger.exception("Error fetching Ollama models. Returning empty list.")
-        return []
+        logger.warning("Ollama endpoint not available. Please ensure Ollama is running.")
+        return []

And add defensive key access:

-        models = [model["name"] for model in data.get("models", [])]
+        models = [model.get("name", "") for model in data.get("models", []) if model.get("name")]

This prevents KeyErrors and provides user guidance.

Also applies to: 1639-1659, 1966-1986


1580-1610: Missing validation for IBM watsonx base_url format and potential null reference in Ollama.

Two validation gaps identified:

  1. IBM watsonx base_url: The code checks if base_url exists but doesn't validate it's a well-formed URL. A malformed URL could be passed to ChatWatsonx.
  2. Ollama base_url transformation: Line ~1599 calls transform_localhost_url(self.ollama_base_url) but doesn't handle a potential None return value before using it at line ~1602.

Add null checks and URL validation:

  if provider == "IBM watsonx.ai":
      if not self.api_key:
          msg = "IBM API key is required..."
          raise ValueError(msg)
      if not self.base_url:
          msg = "IBM watsonx API Endpoint is required..."
          raise ValueError(msg)
+     # Optional: Add URL format validation here
      if not self.project_id:
          msg = "IBM watsonx Project ID is required..."
          raise ValueError(msg)
  if provider == "Ollama":
      if not self.ollama_base_url:
          msg = "Ollama API URL is required..."
          raise ValueError(msg)
      if not model_name:
          msg = "Model name is required..."
          raise ValueError(msg)

      transformed_base_url = transform_localhost_url(self.ollama_base_url)
+     if not transformed_base_url:
+         msg = "Failed to transform Ollama base URL"
+         raise ValueError(msg)

Also applies to: 1708-1738, 2035-2065


1623-1675: Potential issues in update_build_config() when provider switches to Ollama and endpoint is unavailable.

When the provider is switched to "Ollama", the code immediately calls fetch_ollama_models(ollama_url). If Ollama is not running or the URL is incorrect, the method returns an empty list. The UI will then show no available models, potentially frustrating users.

Additionally, there's no validation that build_config["ollama_base_url"].get("value") returns a non-empty string before calling fetch.

Improve Ollama initialization with better defaults and user guidance:

  elif field_value == "Ollama":
      # Fetch Ollama models from the API
      ollama_url = build_config["ollama_base_url"].get("value", "http://localhost:11434")
+     if not ollama_url or not ollama_url.strip():
+         ollama_url = "http://localhost:11434"
      models = self.fetch_ollama_models(base_url=ollama_url)
+     if not models:
+         logger.warning(
+             f"No models found at {ollama_url}. Ensure Ollama is running and check the API URL. "
+             "You can still enter a model name manually if needed."
+         )
      build_config["model_name"]["options"] = models
      build_config["model_name"]["value"] = models[0] if models else ""

Additionally, allow users to override the model_name even if no models are detected:

      build_config["model_name"]["value"] = models[0] if models else ""
+     build_config["model_name"]["required"] = not bool(models)

This ensures the component doesn't break if no models are initially available.

Also applies to: 1751-1803, 2078-2130

♻️ Duplicate comments (4)
src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting.json (4)

964-1139: Same constructor kw concerns for ChatOpenAI/Anthropic as noted in YouTube Analysis.

Please apply the same fix here (model/api_key). See prior comment for diff.


990-1029: Enable combobox on model_name to allow manual entry (esp. for Ollama).

Match the adjustment suggested in the YouTube Analysis file.


1031-1065: Template provider options exclude IBM/Ollama; sync with code.

Same issue as in the YouTube Analysis file. Please update or confirm runtime regeneration.


964-1139: Minor UX polish for Ollama empty model list.

Apply the same graceful-handling suggestion as above.

🧹 Nitpick comments (35)
src/backend/base/langflow/initial_setup/starter_projects/Meeting Summary.json (1)

3076-3076: API timeout configuration uses hardcoded 10-second timeout.

Both fetch_ibm_models() and fetch_ollama_models() use a 10-second timeout for HTTP requests (e.g., line in code: response = requests.get(endpoint, params=params, timeout=10)). This may be insufficient for slow networks or distant API endpoints, and offers no configurability.

Consider making the timeout configurable through environment variables or component settings, with a documented default. This would improve resilience in diverse deployment scenarios:

FETCH_MODELS_TIMEOUT = int(os.getenv("LANGFLOW_FETCH_MODELS_TIMEOUT", "10"))
response = requests.get(endpoint, params=params, timeout=FETCH_MODELS_TIMEOUT)

Also applies to: 3403-3403

src/backend/base/langflow/initial_setup/starter_projects/Image Sentiment Analysis.json (3)

1235-1408: Add streaming to ChatOllama and harden Ollama URL parsing.

  • ChatOllama ignores the user’s Stream toggle. Pass streaming=stream.
  • Sanitize ollama_base_url: enforce http(s) scheme and reject obvious non-routable/private targets before requests.get.

Apply this patch inside the code block:

@@
-            return ChatOllama(
-                base_url=transformed_base_url,
-                model=model_name,
-                temperature=temperature,
-            )
+            return ChatOllama(
+                base_url=transformed_base_url,
+                model=model_name,
+                temperature=temperature,
+                streaming=stream,
+            )
@@
-    def fetch_ollama_models(base_url: str) -> list[str]:
+    def fetch_ollama_models(base_url: str) -> list[str]:
         """Fetch available models from the Ollama API."""
         try:
+            from urllib.parse import urlparse
+            parsed = urlparse(base_url)
+            if parsed.scheme not in ("http", "https"):
+                raise ValueError("Ollama base URL must be http(s)")
             # Strip /v1 suffix if present, as Ollama API endpoints are at root level
             base_url = base_url.rstrip("/").removesuffix("/v1")
             if not base_url.endswith("/"):
                 base_url = base_url + "/"
             base_url = transform_localhost_url(base_url)

761-769: Update prerequisites text.

Note still mentions only OpenAI. Add IBM/Ollama guidance or make it provider-agnostic so the starter doesn’t mislead users.


1559-1731: Duplicate logic across two LanguageModelComponent nodes.

Both nodes embed identical code. That’s expected in starters, but increases maintenance drift. If feasible in the export pipeline, prefer a single shared component or ensure automated regeneration keeps them in sync.

src/backend/base/langflow/initial_setup/starter_projects/Hybrid Search RAG.json (2)

1299-1471: Propagate ChatOllama streaming and URL guards.

Mirror the same fixes as suggested in the other file: pass streaming=stream to ChatOllama and validate/sanitize ollama_base_url (http(s) scheme). See patch in prior comment.


1820-1844: Docs block mentions only OpenAI.

Consider updating the Note’s prerequisites to include other providers or make neutral.

src/lfx/src/lfx/components/models/language_model.py (2)

283-292: Consider fallback when Ollama model fetch fails.

When fetching Ollama models fails or returns an empty list (line 286), model_name["value"] is set to an empty string (line 288). This could be confusing for users, as they'll see an empty model dropdown with no indication of what went wrong.

Consider one of these approaches:

  1. Set a placeholder message like "No models found - check Ollama connection"
  2. Fall back to common Ollama model names (e.g., ["llama2", "mistral", "codellama"])
  3. Keep the current behavior but ensure the UI shows a helpful message

293-293: Optional: Fix minor line length violations.

Lines 293 and 303 slightly exceed the maximum line length (121-122 characters vs 120 maximum). While not blocking, consider breaking these for consistency with project style.

Example for line 293:

-        elif field_name == "base_url" and field_value and hasattr(self, "provider") and self.provider == "IBM watsonx.ai":
+        elif (
+            field_name == "base_url"
+            and field_value
+            and hasattr(self, "provider")
+            and self.provider == "IBM watsonx.ai"
+        ):

Also applies to: 303-303

src/backend/base/langflow/initial_setup/starter_projects/SEO Keyword Generator.json (1)

968-969: Optional improvements for URL validation and response caching in model fetchers

In src/lfx/src/lfx/components/models/language_model.py (lines 45 and 60), consider adding:

  • URL scheme validation before making requests (e.g., validate that base_url starts with http:// or https://)—this provides clearer error messages if invalid URLs are passed
  • Simple memoization per URL to cache results within a component lifecycle, since fetch_ibm_models() and fetch_ollama_models() may be called repeatedly during UI edits when users adjust the base URL field

These changes would improve error handling clarity and avoid redundant API calls during rapid UI interactions, though the current implementation with try-catch blocks is functionally adequate.

src/backend/base/langflow/initial_setup/starter_projects/Memory Chatbot.json (1)

1367-1368: Add scheme validation and optional caching for dynamic URL fetchers

The fetch_ibm_models() and fetch_ollama_models() methods accept user-supplied base_url parameters without validating the URL scheme or host. While exceptions are safely caught, basic scheme validation (e.g., http:// or https:// only) is a standard SSRF mitigation. Additionally, caching fetch results by base_url in update_build_config() would avoid repeated API calls.

Example improvements:

  • Validate URL scheme before making requests
  • Add a simple cache (dict keyed by base_url) to avoid redundant API calls within the same config session

This pattern appears across multiple starter project files.

src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json (2)

3396-3418: Fetch IBM models immediately on provider switch (not only on base_url change).

Currently IBM model options update only after base_url changes. Fetch on provider selection to populate the dropdown right away.

             elif field_value == "IBM watsonx.ai":
-                build_config["model_name"]["options"] = IBM_WATSONX_DEFAULT_MODELS
-                build_config["model_name"]["value"] = IBM_WATSONX_DEFAULT_MODELS[0]
+                try:
+                    ibm_url = build_config["base_url"].get("value", IBM_WATSONX_URLS[0])
+                    models = self.fetch_ibm_models(base_url=ibm_url)
+                except Exception:  # noqa: BLE001
+                    logger.exception("Error fetching IBM models on provider change. Falling back to defaults.")
+                    models = IBM_WATSONX_DEFAULT_MODELS
+                build_config["model_name"]["options"] = models
+                build_config["model_name"]["value"] = models[0] if models else IBM_WATSONX_DEFAULT_MODELS[0]
                 build_config["api_key"]["display_name"] = "IBM API Key"
                 build_config["api_key"]["show"] = True
                 build_config["base_url"]["show"] = True
                 build_config["project_id"]["show"] = True
                 build_config["ollama_base_url"]["show"] = False

3142-3161: Add missing runtime dependencies to metadata for reproducibility.

Include langchain_ibm and langchain_ollama since the component imports them. This helps automated installers and CI.

               "dependencies": {
                 "dependencies": [
                   { "name": "langchain_anthropic", "version": "0.3.14" },
                   { "name": "langchain_google_genai", "version": "2.0.6" },
-                  { "name": "langchain_openai", "version": "0.3.23" },
+                  { "name": "langchain_openai", "version": "0.3.23" },
+                  { "name": "langchain_ibm", "version": null },
+                  { "name": "langchain_ollama", "version": null },
                   { "name": "lfx", "version": null }
                 ],
-                "total_dependencies": 4
+                "total_dependencies": 6
               },
src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json (2)

2023-2023: Exception handling pattern uses overly broad catch-all.

While the code has appropriate fallback behavior, using bare except Exception catches network errors, malformed responses, and timeouts uniformly. Consider distinguishing timeout exceptions to provide more granular error messages to users, or at minimum log the exception type for debugging.

Example improvement:

except requests.Timeout:
    logger.warning(f"Timeout fetching {provider} models from {base_url}")
    return defaults
except requests.RequestException as e:
    logger.exception(f"Failed to fetch {provider} models: {e}")
    return defaults

This is a lower-priority refinement since fallback behavior is sound.


2023-2023: Dynamic model fetching may show empty list if Ollama API unavailable on initial load.

When a user first selects the "Ollama" provider, the code attempts to fetch models from the default http://localhost:11434 without first confirming the endpoint is reachable. If Ollama isn't running locally, the model dropdown will be empty, which could confuse users. Consider:

  1. Showing a placeholder message like "Connect to Ollama and enter the API URL" when no models are fetched
  2. Or deferring the fetch until the user explicitly enters a base_url

This is a UX polish opportunity rather than a critical bug, since users can still manually enter a URL and the models will update.

src/backend/base/langflow/initial_setup/starter_projects/Custom Component Generator.json (2)

2717-2743: Verify IBM watsonx.ai model caching and refresh behavior.

In update_build_config(), when provider changes to "IBM watsonx.ai", the component uses IBM_WATSONX_DEFAULT_MODELS and doesn't fetch from the API until base_url changes. This means if a user switches to IBM watsonx.ai without changing the base_url field, they get default models. Later, when the user changes base_url, the fetch happens. This could be confusing.

Consider fetching IBM models eagerly when the provider is set to IBM watsonx.ai:

elif field_value == "IBM watsonx.ai":
    build_config["model_name"]["options"] = IBM_WATSONX_DEFAULT_MODELS
    build_config["model_name"]["value"] = IBM_WATSONX_DEFAULT_MODELS[0]
    build_config["api_key"]["display_name"] = "IBM API Key"
    build_config["api_key"]["show"] = True
    build_config["base_url"]["show"] = True
    build_config["project_id"]["show"] = True
    build_config["ollama_base_url"]["show"] = False
    
    # Eagerly fetch models if base_url has a value
    if "base_url" in build_config and build_config["base_url"].get("value"):
        try:
            models = self.fetch_ibm_models(build_config["base_url"]["value"])
            if models:
                build_config["model_name"]["options"] = models
                build_config["model_name"]["value"] = models[0]
        except Exception:  # noqa: BLE001
            logger.warning("Failed to fetch IBM models on provider change")

2769-2803: Verify SecretStr usage and API key safe handling.

For IBM watsonx.ai, the code converts the API key to a secret using SecretStr(self.api_key).get_secret_value(). However, self.api_key comes from a SecretStrInput and should already be a secure string. The conversion may be redundant or could introduce issues if the input is already handled securely by the framework.

Verify with the framework's documentation whether SecretStr conversion is necessary. If self.api_key is already secure, simplify to:

return ChatWatsonx(
    apikey=self.api_key,  # Already secure from SecretStrInput
    url=self.base_url,
    # ... rest
)

Otherwise, document why the extra conversion is needed.

src/backend/base/langflow/initial_setup/starter_projects/Market Research.json (1)

1313-1314: Harden model fetching with lightweight resiliency.

Add small retry/backoff and shorter timeouts to reduce UI stalls when endpoints are unreachable.

-            response = requests.get(endpoint, params=params, timeout=10)
+            response = requests.get(endpoint, params=params, timeout=5)
...
-            response = requests.get(tags_url, timeout=10)
+            response = requests.get(tags_url, timeout=5)

Optionally wrap with urllib3 Retry or a simple 2-attempt retry on RequestException.

Do you want me to add a tiny retry helper used by both fetch_* methods?

src/backend/base/langflow/initial_setup/starter_projects/Portfolio Website Code Generator.json (2)

1502-1502: Consider adding observability to model fetch failures and implement resilience best practices.

The fetch_ibm_models() and fetch_ollama_models() methods include fallback logic on error, but they silently catch all exceptions and log only warnings. Users may not realize that model discovery failed and are viewing stale or default options. Additionally, the 10-second timeout is hardcoded with no room for adjustment on slow networks or overloaded services.

Consider:

  1. Adding structured logging that distinguishes between network timeouts, authentication failures, and other errors so users can debug connectivity issues.
  2. Implementing exponential backoff retry logic for transient failures rather than immediately falling back.
  3. Surfacing a warning in the UI if model discovery fails (e.g., display a note like "Using cached/default models" when the API is unreachable).
  4. Making the timeout configurable or context-aware (e.g., longer for IBM API calls, shorter for local Ollama).

Also applies to: 1829-1829


1502-1502: Blocking API calls during UI field updates could degrade user experience for unreachable endpoints.

In the update_build_config() method, when the user selects the "Ollama" provider, the code immediately calls self.fetch_ollama_models(base_url=ollama_url) (line ~1653 in the code). If the Ollama endpoint is unreachable or slow, this synchronous API call will block the UI update and create a sluggish interaction.

Consider:

  1. Making model fetches asynchronous or deferring them until the user explicitly clicks a "refresh" button or opens the model dropdown.
  2. Caching model lists so repeated provider switches don't re-fetch.
  3. Setting a tighter timeout (e.g., 3–5 seconds) for these update-time fetches so the UI doesn't hang for too long.
  4. Showing a loading indicator or spinner while models are being fetched.

Also applies to: 1829-1829

src/backend/base/langflow/initial_setup/starter_projects/Youtube Analysis.json (4)

2540-2579: Allow manual model entry when dynamic fetch fails (enable combobox).

Ollama model discovery can return an empty list; with combobox=false, users can’t type a model name. Enable combobox for model_name to preserve usability.

Patch:

-                "combobox": false,
+                "combobox": true,

2580-2615: Provider options in the static template omit IBM/Ollama.

Template provider.options still shows ["OpenAI","Anthropic","Google"], while code supports IBM watsonx.ai and Ollama. Users may not see the new providers until regenerated. Sync the template to include the new options or ensure it’s rebuilt from code on import.

Patch:

-                "options": [
-                  "OpenAI",
-                  "Anthropic",
-                  "Google"
-                ],
+                "options": [
+                  "OpenAI",
+                  "Anthropic",
+                  "Google",
+                  "IBM watsonx.ai",
+                  "Ollama"
+                ],

If the runtime always derives inputs from the code block, please confirm and we can skip this change.


2514-2688: IBM model fetch is unauthenticated; consider optional auth for reliability.

fetch_ibm_models calls foundation_model_specs without auth and falls back to defaults. Some regions/orgs require IAM; consider: if api_key present, obtain IAM token and pass Authorization to improve success rate.

Outline:


2514-2688: Ollama: handle empty model list more gracefully.

When models=[], model_name is set to "", leading to immediate build-time error. Consider leaving current value unchanged or setting a helpful placeholder with instructions.

Example:

-                build_config["model_name"]["value"] = models[0] if models else ""
+                build_config["model_name"]["value"] = models[0] if models else build_config["model_name"].get("value", "")
+                if not models:
+                    logger.warning("No Ollama models found at %s. Ensure the server is running and models are pulled.", ollama_url)
src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json (2)

2795-2796: Harden dynamic model fetch (Ollama) against SSRF.

Same guardrails as suggested in the other file; apply in both code blocks.

(Reuse the fetch_ollama_models diff from the other comment.)

Also applies to: 3117-3118


2795-2796: IBM model discovery: accept api_key and use IAM token (optional but recommended).

Same refactor as suggested for the other file; apply in both code blocks.

(Reuse the fetch_ibm_models + call‑site diff from the other comment.)

Also applies to: 3117-3118

src/backend/base/langflow/initial_setup/starter_projects/Text Sentiment Analysis.json (2)

1466-1466: Code duplication across three LanguageModelComponent instances.

All three node instances (LanguageModelComponent-qFXT1, LanguageModelComponent-Wp3pC, LanguageModelComponent-gYAmH) contain identical Python code embedded in their template. While this is expected for a starter project (where multiple instances of the same component type coexist), ensure that any future updates to the component definition are propagated to all instances uniformly.

Consider centralizing the component definition outside the starter project JSON to reduce duplication and maintenance burden.

Also applies to: 1794-1794, 2121-2121


1488-1510: IBM watsonx API version is hardcoded; consider making it configurable.

The fetch_ibm_models() method uses a hardcoded API version ("2024-09-16"). While this ensures stability, it may become outdated and prevent access to newer models. The filter string ("function_text_chat,!lifecycle_withdrawn") is also fixed.

Consider adding optional configuration parameters (environment variables or component settings) to control the API version and filters, allowing users to adapt to API changes without modifying the component code.

Also applies to: 1616-1638, 1943-1965

src/backend/base/langflow/initial_setup/starter_projects/Basic Prompt Chaining.json (8)

1271-1271: Extract common code segment to avoid duplication across three LanguageModelComponent nodes.

The same Python code is duplicated across three separate LanguageModelComponent node instances. While this is typical for JSON flow files, any future maintenance or bug fixes will need to be applied in three places. Consider whether the starter project setup supports a shared code template or component inheritance.

Also applies to: 1593-1593, 1914-1914


1296-1310: Hardcoded IBM watsonx API version may become stale.

The fetch_ibm_models() method uses a hardcoded API version "2024-09-16" in the request parameters. IBM may release newer API versions, and this constant should be reviewed periodically or made configurable if this code is intended for long-term use.


1295-1310: Broad exception handling may mask specific API errors.

Both fetch_ibm_models() and fetch_ollama_models() catch all exceptions with except Exception: # noqa: BLE001. While fallbacks are provided, this masks specific errors (timeout, network, auth, invalid response format) that might need different handling. Consider catching specific exception types (e.g., requests.RequestException, requests.Timeout) and logging more context.


1335-1385: Update build_config may fail silently on missing keys.

In update_build_config(), lines like build_config[\"model_name\"][\"options\"] = ... assume the keys exist. If build_config is missing expected structure, this will raise a KeyError. Add defensive checks or validation to ensure required config keys are present before modification.


1375-1385: Model selection may be empty for Ollama with no running instance.

In the Ollama provider branch of update_build_config(), if fetch_ollama_models() returns an empty list (e.g., Ollama is not running or unreachable), the model dropdown will be empty (models[0] if models else ""). This may confuse users. Consider setting a default placeholder or informative message.


1400-1410: o1 model detection uses prefix match that could over-match future models.

The condition field_value.startswith("o1") will match "o1", "o1-2025", "o1-preview", etc. If OpenAI releases models that start with "o1" but do support system messages, this logic will incorrectly hide the field. Consider using an explicit allowlist or exact version matching.


1345-1360: Potential AttributeError if field_name matches but provider attribute missing.

In update_build_config(), lines like if field_name == "base_url" and field_value and hasattr(self, "provider") and self.provider == "IBM watsonx.ai": check for provider existence, but if self.provider is None or an unexpected value, comparisons could behave unexpectedly. Add explicit None checks or use a safer comparison pattern.


1365-1380: Resource leak risk with unclosed HTTP requests.

The fetch_ibm_models() and fetch_ollama_models() methods use requests.get() with timeout=10, but do not explicitly close the response. While the requests library auto-closes responses in most cases, consider using a context manager for clarity and robustness:

with requests.get(endpoint, params=params, timeout=10) as response:
    response.raise_for_status()
    data = response.json()

Comment thread src/backend/base/langflow/initial_setup/starter_projects/Document Q&amp;A.json Outdated
Comment thread src/backend/base/langflow/initial_setup/starter_projects/Market Research.json Outdated
Comment thread src/backend/base/langflow/initial_setup/starter_projects/Meeting Summary.json Outdated
Comment thread src/backend/base/langflow/initial_setup/starter_projects/Memory Chatbot.json Outdated
Comment thread src/lfx/src/lfx/components/models/language_model.py Outdated
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 4, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 4, 2025
Introduces a context_id input to ChatInput and ChatOutput components for enhanced chat memory management. Expands LanguageModelComponent to support IBM watsonx.ai and Ollama providers, including dynamic model fetching and related configuration options.
@github-actions github-actions Bot removed the enhancement New feature or request label Nov 4, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 5, 2025
Refactored LanguageModelComponent to support IBM watsonx and Ollama providers, including new input fields and validation logic. Updated build config logic and tests to handle provider-specific options, error cases, and model instantiation for IBM watsonx and Ollama.
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 5, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 5, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 5, 2025
@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Nov 5, 2025
@erichare erichare added this pull request to the merge queue Nov 5, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 5, 2025
@edwinjosechittilappilly edwinjosechittilappilly added this pull request to the merge queue Nov 5, 2025
Merged via the queue into main with commit b74e9ee Nov 5, 2025
83 of 84 checks passed
@edwinjosechittilappilly edwinjosechittilappilly deleted the feat-ibm-watsonx-ollama-models branch November 5, 2025 18:38
korenLazar pushed a commit to kiran-kate/langflow that referenced this pull request Nov 13, 2025
…ow-ai#10471)

* Add IBM watsonx.ai support to LanguageModelComponent

Extended LanguageModelComponent to support IBM watsonx.ai as a provider, including dynamic model fetching, new input fields for API endpoint and project ID, and integration with ChatWatsonx. Updated starter project JSONs to reflect these changes and enable selection of IBM watsonx.ai models.

* Add Ollama support to LanguageModelComponent

Extended the LanguageModelComponent to support Ollama as a provider, including dynamic model fetching from the Ollama API and related UI input fields. Updated build_model and update_build_config logic to handle Ollama-specific configuration and improved provider switching logic for all supported providers.

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* flow updates

* Update component_index.json

* Add context_id support and expand model providers

Introduces a context_id input to ChatInput and ChatOutput components for enhanced chat memory management. Expands LanguageModelComponent to support IBM watsonx.ai and Ollama providers, including dynamic model fetching and related configuration options.

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* [autofix.ci] apply automated fixes (attempt 3/3)

* Add IBM watsonx and Ollama support to LanguageModelComponent

Refactored LanguageModelComponent to support IBM watsonx and Ollama providers, including new input fields and validation logic. Updated build config logic and tests to handle provider-specific options, error cases, and model instantiation for IBM watsonx and Ollama.

* update to the componentn index and templates

* fix ruff

* Update component_index.json

* template updates

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants