Merge branch 'form_io' of github.com:logspace-ai/langflow into form_io

This commit is contained in:
Lucas Oliveira 2023-06-27 12:40:51 -03:00
commit 54891277c6
4 changed files with 33 additions and 5 deletions

View file

@ -73,6 +73,11 @@ prompts:
- PromptTemplate - PromptTemplate
- FewShotPromptTemplate - FewShotPromptTemplate
- ZeroShotPrompt - ZeroShotPrompt
- ChatPromptTemplate
- SystemMessagePromptTemplate
- AIMessagePromptTemplate
- HumanMessagePromptTemplate
- ChatMessagePromptTemplate
textsplitters: textsplitters:
- CharacterTextSplitter - CharacterTextSplitter
- RecursiveCharacterTextSplitter - RecursiveCharacterTextSplitter

View file

@ -180,11 +180,17 @@ class PromptVertex(Vertex):
] ]
else: else:
prompt_params = ["template"] prompt_params = ["template"]
for param in prompt_params:
prompt_text = self.params[param] if "prompt" not in self.params and "messages" not in self.params:
variables = extract_input_variables_from_prompt(prompt_text) for param in prompt_params:
self.params["input_variables"].extend(variables) prompt_text = self.params[param]
self.params["input_variables"] = list(set(self.params["input_variables"])) variables = extract_input_variables_from_prompt(prompt_text)
self.params["input_variables"].extend(variables)
self.params["input_variables"] = list(
set(self.params["input_variables"])
)
else:
self.params.pop("input_variables", None)
self._build() self._build()
return self._built_object return self._built_object

View file

@ -6,6 +6,7 @@ from langchain.agents import (
Tool, Tool,
ZeroShotAgent, ZeroShotAgent,
initialize_agent, initialize_agent,
AgentType,
) )
from langchain.agents.agent_toolkits import ( from langchain.agents.agent_toolkits import (
SQLDatabaseToolkit, SQLDatabaseToolkit,
@ -297,6 +298,9 @@ class InitializeAgent(CustomAgentExecutor):
agent: str, agent: str,
memory: Optional[BaseChatMemory] = None, memory: Optional[BaseChatMemory] = None,
): ):
# Find which value in the AgentType enum corresponds to the string
# passed in as agent
agent = AgentType(agent)
return initialize_agent( return initialize_agent(
tools=tools, tools=tools,
llm=llm, llm=llm,

View file

@ -97,6 +97,19 @@ def instantiate_prompt(node_type, class_object, params):
if "tools" not in params: if "tools" not in params:
params["tools"] = [] params["tools"] = []
return ZeroShotAgent.create_prompt(**params) return ZeroShotAgent.create_prompt(**params)
if "MessagePromptTemplate" in node_type:
# Then we only need the template
from_template_params = {
"template": params.pop("prompt", params.pop("template", ""))
}
if not from_template_params.get("template"):
raise ValueError("Prompt template is required")
return class_object.from_template(**from_template_params)
if node_type == "ChatPromptTemplate":
return class_object.from_messages(**params)
return class_object(**params) return class_object(**params)