Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/lfx/src/lfx/components/langchain_utilities/langchain_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from langchain_core.prompts import HumanMessagePromptTemplate

from lfx.custom.custom_component.component import Component
from lfx.inputs.inputs import DefaultPromptField, SecretStrInput, StrInput
from lfx.inputs.inputs import DefaultPromptField, DropdownInput, SecretStrInput, StrInput
from lfx.io import Output
from lfx.schema.message import Message

Expand All @@ -23,6 +23,14 @@ class LangChainHubPromptComponent(Component):
info="The LangChain API Key to use.",
required=True,
),
DropdownInput(
name="region",
display_name="Region",
info="Select the LangChain Hub region (US or EU)",
options=["US", "EU"],
value="US",
required=True,
),
StrInput(
name="langchain_hub_prompt",
display_name="LangChain Hub Prompt",
Expand Down Expand Up @@ -122,5 +130,8 @@ def _fetch_langchain_hub_template(self):

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"

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.


# Pull the prompt from LangChain Hub
return langchain.hub.pull(self.langchain_hub_prompt, api_key=self.langchain_api_key)
return langchain.hub.pull(self.langchain_hub_prompt, api_key=self.langchain_api_key, api_url=api_url)
Loading