Skip to content

feat: add dropdown select for region on the langchain hub component - #10514

Open
0xNekr wants to merge 4 commits into
langflow-ai:mainfrom
0xNekr:feat/add-region-to-hub-prompt-component
Open

feat: add dropdown select for region on the langchain hub component#10514
0xNekr wants to merge 4 commits into
langflow-ai:mainfrom
0xNekr:feat/add-region-to-hub-prompt-component

Conversation

@0xNekr

@0xNekr 0xNekr commented Nov 6, 2025

Copy link
Copy Markdown

Hello everyone,

I have very recently started using Langflow, and in particular the connection with the Langchain prompt hub.

The component did not have the option to select the region for the API call, so it didn't work with what I had already done.
That's why I'm opening this PR to add a drop-down menu for selecting the region.

This is my first time contributing to this project, so please let me know if I've missed anything.

Summary by CodeRabbit

  • New Features
    • LangChain Hub integration now includes regional endpoint selection. Users can choose between US and EU regions when configuring prompts, allowing connection to the appropriate regional API endpoint based on geographic location or data residency requirements. US is set as the default region.

@github-actions github-actions Bot added the community Pull Request from an external contributor label Nov 6, 2025
@coderabbitai

coderabbitai Bot commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

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

Added region selection capability to LangChainHubPromptComponent with US/EU dropdown options. The region field controls API endpoint resolution within template fetching, routing requests to appropriate regional endpoints via the api_url parameter passed to langchain.hub.pull.

Changes

Cohort / File(s) Summary
LangChain Hub Region Support
src/lfx/src/lfx/components/langchain_utilities/langchain_hub.py
Added region DropdownInput field with US/EU options (default: US); imported DropdownInput; modified _fetch_langchain_hub_template to resolve region-specific API URLs (https://api.hub.langchain.com for US, https://eu.api.hub.langchain.com for EU); updated langchain.hub.pull call to pass resolved api_url parameter

Sequence Diagram

sequenceDiagram
    actor User
    participant Component as LangChainHubPromptComponent
    participant Fetch as _fetch_langchain_hub_template
    participant Hub as LangChain Hub API
    
    User->>Component: Select region (US/EU)
    Component->>Fetch: Call with region parameter
    Fetch->>Fetch: Resolve API URL based on region
    Note over Fetch: US → https://api.hub.langchain.com<br/>EU → https://eu.api.hub.langchain.com
    Fetch->>Hub: langchain.hub.pull(prompt_id, api_url)
    Hub-->>Fetch: Template response
    Fetch-->>Component: Template data
    Component-->>User: Populated template
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single file modification with straightforward logic additions
  • New field addition follows existing pattern
  • Region-to-URL mapping is simple conditional logic with no complex interactions

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, 3 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Test File Naming And Structure ⚠️ Warning Pull request adds region selection feature to LangChainHubPromptComponent but includes no corresponding test files with proper pytest naming patterns or test coverage for the new functionality. Create test_langchain_hub.py with tests for region selection, API URL generation, edge cases, and error handling to verify the new feature works correctly.
Test Coverage For New Implementations ❓ Inconclusive Repository structure could not be determined to locate component file and corresponding test files for assessment. Verify component file exists, identify test files following project conventions, and confirm test coverage for region field functionality.
Test Quality And Coverage ❓ Inconclusive No test files found for the LangChainHubPromptComponent region-based functionality in the repository. Locate or create tests covering region selection, API URL resolution, error handling, and both US/EU region scenarios.
Excessive Mock Usage Warning ❓ Inconclusive Test files for langchain_hub component could not be located to assess mock usage patterns. Locate test files for LangChainHubPromptComponent and verify mocks are used only for external dependencies, not core logic.
✅ Passed checks (2 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 change: adding a dropdown region selector to the LangChain Hub component.

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.

@github-actions github-actions Bot added the enhancement New feature or request label Nov 6, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 6, 2025

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

📜 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 b74e9ee and 6f538e9.

📒 Files selected for processing (1)
  • src/lfx/src/lfx/components/langchain_utilities/langchain_hub.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/lfx/src/lfx/components/langchain_utilities/langchain_hub.py (1)
src/lfx/src/lfx/inputs/inputs.py (2)
  • DefaultPromptField (651-658)
  • DropdownInput (465-490)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Update Component Index
🔇 Additional comments (3)
src/lfx/src/lfx/components/langchain_utilities/langchain_hub.py (3)

6-6: LGTM!

The DropdownInput import is correctly added to support the new region selection field.


26-33: LGTM!

The region dropdown field is properly configured with US/EU options and sensible defaults. The field definition follows the correct DropdownInput structure.


137-137: The api_url parameter is supported in langchain.hub.pull v0.3.23.

The api_url parameter is properly documented and implemented in langchain.hub.pull for version 0.3.23. The code at line 137 is correct and will execute without errors.

Comment on lines +133 to +134
# Determine the API URL based on region
api_url = "https://api.hub.langchain.com" if self.region == "US" else "https://eu.api.hub.langchain.com"

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 unreachable code: API URL logic is never executed.

Lines 133-134 are indented incorrectly and appear after the raise ValueError(msg) on Line 131, making them unreachable. The API URL will never be set, causing the region selection feature to not work at all.

Apply this diff to fix the indentation:

         # Check if the api key is provided
         if not self.langchain_api_key:
             msg = "Please provide a LangChain API Key"
-
             raise ValueError(msg)
 
-            # Determine the API URL based on region
-        api_url = "https://api.hub.langchain.com" if self.region == "US" else "https://eu.api.hub.langchain.com"
-
+        # Determine the API URL based on region
+        api_url = "https://api.hub.langchain.com" if self.region == "US" else "https://eu.api.hub.langchain.com"
+ 
         # Pull the prompt from LangChain Hub
         return langchain.hub.pull(self.langchain_hub_prompt, api_key=self.langchain_api_key, api_url=api_url)
📝 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
# Determine the API URL based on region
api_url = "https://api.hub.langchain.com" if self.region == "US" else "https://eu.api.hub.langchain.com"
# Check if the api key is provided
if not self.langchain_api_key:
msg = "Please provide a LangChain API Key"
raise ValueError(msg)
# Determine the API URL based on region
api_url = "https://api.hub.langchain.com" if self.region == "US" else "https://eu.api.hub.langchain.com"
# Pull the prompt from LangChain Hub
return langchain.hub.pull(self.langchain_hub_prompt, api_key=self.langchain_api_key, api_url=api_url)
🤖 Prompt for AI Agents
In src/lfx/src/lfx/components/langchain_utilities/langchain_hub.py around lines
133-134, the api_url assignment is indented after the raise ValueError and thus
never executed; move/dedent the API URL logic so it runs for valid regions
(place the api_url = ... line(s) before the raise and inside the code path that
handles valid region values, or immediately after region validation), ensuring
the raise remains for invalid regions.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant