bugfix: Handle prompts with no Chat messsages (#3892)
Also require API key for langsmith
This commit is contained in:
parent
e0e54a3ed0
commit
b59ae6befa
1 changed files with 12 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ from langflow.inputs import StrInput, SecretStrInput, DefaultPromptField
|
||||||
from langflow.io import Output
|
from langflow.io import Output
|
||||||
from langflow.schema.message import Message
|
from langflow.schema.message import Message
|
||||||
|
|
||||||
|
from langchain_core.prompts import HumanMessagePromptTemplate
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
@ -40,9 +41,15 @@ class LangChainHubPromptComponent(Component):
|
||||||
if field_name == "langchain_hub_prompt":
|
if field_name == "langchain_hub_prompt":
|
||||||
template = self._fetch_langchain_hub_template()
|
template = self._fetch_langchain_hub_template()
|
||||||
|
|
||||||
|
# Get the template's messages
|
||||||
|
if hasattr(template, "messages"):
|
||||||
|
template_messages = template.messages
|
||||||
|
else:
|
||||||
|
template_messages = [HumanMessagePromptTemplate(prompt=template)]
|
||||||
|
|
||||||
# Extract the messages from the prompt data
|
# Extract the messages from the prompt data
|
||||||
prompt_template = []
|
prompt_template = []
|
||||||
for message_data in template.messages:
|
for message_data in template_messages:
|
||||||
prompt_template.append(message_data.prompt)
|
prompt_template.append(message_data.prompt)
|
||||||
|
|
||||||
# Regular expression to find all instances of {<string>}
|
# Regular expression to find all instances of {<string>}
|
||||||
|
|
@ -103,6 +110,10 @@ class LangChainHubPromptComponent(Component):
|
||||||
def _fetch_langchain_hub_template(self):
|
def _fetch_langchain_hub_template(self):
|
||||||
import langchain.hub
|
import langchain.hub
|
||||||
|
|
||||||
|
# Check if the api key is provided
|
||||||
|
if not self.langchain_api_key:
|
||||||
|
raise ValueError("Please provide a LangChain API Key")
|
||||||
|
|
||||||
# Pull the prompt from LangChain Hub
|
# Pull the prompt from LangChain Hub
|
||||||
prompt_data = langchain.hub.pull(self.langchain_hub_prompt, api_key=self.langchain_api_key)
|
prompt_data = langchain.hub.pull(self.langchain_hub_prompt, api_key=self.langchain_api_key)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue