feat: get_signature can return the FrontendNode directly now

This commit is contained in:
Gabriel Almeida 2023-04-01 18:58:03 -03:00
commit 43c4fe7dfc
4 changed files with 10 additions and 12 deletions

View file

@ -1,14 +1,12 @@
from langflow.template import nodes from langflow.template import nodes
CUSTOM_NODES = { CUSTOM_NODES = {
"prompts": { "prompts": {"ZeroShotPrompt": nodes.ZeroShotPromptNode()},
**nodes.ZeroShotPromptNode().to_dict(), "tools": {"PythonFunction": nodes.PythonFunctionNode(), "Tool": nodes.ToolNode()},
},
"tools": {**nodes.PythonFunctionNode().to_dict(), **nodes.ToolNode().to_dict()},
"agents": { "agents": {
**nodes.JsonAgentNode().to_dict(), "JsonAgent": nodes.JsonAgentNode(),
**nodes.CSVAgentNode().to_dict(), "CSVAgent": nodes.CSVAgentNode(),
**nodes.InitializeAgentNode().to_dict(), "InitializeAgent": nodes.InitializeAgentNode(),
}, },
} }

View file

@ -1,5 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional, Union
from pydantic import BaseModel from pydantic import BaseModel
@ -20,7 +20,7 @@ class LangChainTypeCreator(BaseModel, ABC):
return self.type_dict return self.type_dict
@abstractmethod @abstractmethod
def get_signature(self, name: str) -> Optional[Dict[Any, Any]]: def get_signature(self, name: str) -> Union[Optional[Dict[Any, Any]], FrontendNode]:
pass pass
@abstractmethod @abstractmethod
@ -42,6 +42,8 @@ class LangChainTypeCreator(BaseModel, ABC):
signature = self.get_signature(name) signature = self.get_signature(name)
if signature is None: if signature is None:
raise ValueError(f"{name} not found") raise ValueError(f"{name} not found")
if isinstance(signature, FrontendNode):
return signature
fields = [ fields = [
TemplateField( TemplateField(
name=key, name=key,

View file

@ -54,8 +54,6 @@ class TemplateFieldCreator(BaseModel, ABC):
if "List" in _type: if "List" in _type:
_type = _type.replace("List[", "")[:-1] _type = _type.replace("List[", "")[:-1]
self.is_list = True self.is_list = True
else:
self.is_list = False
# Replace 'Mapping' with 'dict' # Replace 'Mapping' with 'dict'
if "Mapping" in _type: if "Mapping" in _type:

View file

@ -153,7 +153,7 @@ class JsonAgentNode(FrontendNode):
class InitializeAgentNode(FrontendNode): class InitializeAgentNode(FrontendNode):
name: str = "InializeAgent" name: str = "InitializeAgent"
template: Template = Template( template: Template = Template(
type_name="initailize_agent", type_name="initailize_agent",
fields=[ fields=[