feat: add dropdown select for region on the langchain hub component - #10514
feat: add dropdown select for region on the langchain hub component#105140xNekr wants to merge 4 commits into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughAdded 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touchesImportant Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (2 warnings, 3 inconclusive)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 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
DropdownInputimport 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
DropdownInputstructure.
137-137: Theapi_urlparameter is supported in langchain.hub.pull v0.3.23.The
api_urlparameter 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.
| # 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" |
There was a problem hiding this comment.
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.
| # 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.
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