Merge branch 'dev' into vecstores

This commit is contained in:
Ibis Prevedello 2023-04-10 10:20:56 -03:00
commit fee2e52ec1
15 changed files with 325 additions and 213 deletions

View file

@ -29,6 +29,7 @@ llms:
# - AzureOpenAI
- ChatOpenAI
- HuggingFaceHub
- LlamaCpp
tools:
- Search

View file

@ -4,6 +4,7 @@
# - Build each inner agent first, then build the outer agent
import types
import warnings
from copy import deepcopy
from typing import Any, Dict, List, Optional
@ -119,7 +120,13 @@ class Node:
params[key] = edges[0].source
elif value["required"] or value.get("value"):
params[key] = value["value"]
# If value does not have value this still passes
# but then gives a keyError
# so we need to check if value has value
new_value = value.get("value")
if new_value is None:
warnings.warn(f"Value for {key} in {self.node_type} is None. ")
params[key] = new_value
# Add _type to params
self.params = params

View file

@ -1 +1 @@
DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any"]
DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any", "prompt"]

View file

@ -54,7 +54,10 @@ class PromptNode(Node):
tools: Optional[Union[List[Node], List[ToolNode]]] = None,
) -> Any:
if not self._built or force:
if "input_variables" not in self.params:
if (
"input_variables" not in self.params
or self.params["input_variables"] is None
):
self.params["input_variables"] = []
# Check if it is a ZeroShotPrompt and needs a tool
if "ShotPrompt" in self.node_type:
@ -74,7 +77,6 @@ class PromptNode(Node):
for param in prompt_params:
prompt_text = self.params[param]
variables = extract_input_variables_from_prompt(prompt_text)
self.params["input_variables"].extend(variables)
self.params["input_variables"] = list(set(self.params["input_variables"]))

View file

@ -1,9 +1,10 @@
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Type
from langflow.custom.customs import get_custom_nodes
from langflow.interface.base import LangChainTypeCreator
from langflow.interface.custom_lists import chain_type_to_cls_dict
from langflow.settings import settings
from langflow.template.nodes import ChainFrontendNode
from langflow.utils.util import build_template_from_class
# Assuming necessary imports for Field, Template, and FrontendNode classes
@ -12,6 +13,10 @@ from langflow.utils.util import build_template_from_class
class ChainCreator(LangChainTypeCreator):
type_name: str = "chains"
@property
def frontend_node_class(self) -> Type[ChainFrontendNode]:
return ChainFrontendNode
@property
def type_to_loader_dict(self) -> Dict:
if self.type_dict is None:

View file

@ -1,14 +1,19 @@
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Type
from langflow.interface.base import LangChainTypeCreator
from langflow.interface.custom_lists import llm_type_to_cls_dict
from langflow.settings import settings
from langflow.template.nodes import LLMFrontendNode
from langflow.utils.util import build_template_from_class
class LLMCreator(LangChainTypeCreator):
type_name: str = "llms"
@property
def frontend_node_class(self) -> Type[LLMFrontendNode]:
return LLMFrontendNode
@property
def type_to_loader_dict(self) -> Dict:
if self.type_dict is None:

View file

@ -73,9 +73,14 @@ class ToolCreator(LangChainTypeCreator):
base_classes = ["Tool"]
all_tools = {}
for tool in self.type_to_loader_dict.keys():
if tool_params := get_tool_params(get_tool_by_name(tool)):
tool_fcn = get_tool_by_name(tool)
if tool_params := get_tool_params(tool_fcn):
tool_name = tool_params.get("name") or str(tool)
all_tools[tool_name] = {"type": tool, "params": tool_params}
all_tools[tool_name] = {
"type": tool,
"params": tool_params,
"fcn": tool_fcn,
}
# Raise error if name is not in tools
if name not in all_tools.keys():
@ -83,15 +88,21 @@ class ToolCreator(LangChainTypeCreator):
tool_type: str = all_tools[name]["type"] # type: ignore
if tool_type in _BASE_TOOLS:
if all_tools[tool_type]["fcn"] in _BASE_TOOLS.values():
params = []
elif tool_type in _LLM_TOOLS:
elif all_tools[tool_type]["fcn"] in _LLM_TOOLS.values():
params = ["llm"]
elif tool_type in _EXTRA_LLM_TOOLS:
_, extra_keys = _EXTRA_LLM_TOOLS[tool_type]
elif all_tools[tool_type]["fcn"] in [
val[0] for val in _EXTRA_LLM_TOOLS.values()
]:
n_dict = {val[0]: val[1] for val in _EXTRA_LLM_TOOLS.values()}
extra_keys = n_dict[all_tools[tool_type]["fcn"]]
params = ["llm"] + extra_keys
elif tool_type in _EXTRA_OPTIONAL_TOOLS:
_, extra_keys = _EXTRA_OPTIONAL_TOOLS[tool_type]
elif all_tools[tool_type]["fcn"] in [
val[0] for val in _EXTRA_OPTIONAL_TOOLS.values()
]:
n_dict = {val[0]: val[1] for val in _EXTRA_OPTIONAL_TOOLS.values()} # type: ignore
extra_keys = n_dict[all_tools[tool_type]["fcn"]]
params = extra_keys
elif tool_type == "Tool":
params = ["name", "description", "func"]
@ -104,7 +115,6 @@ class ToolCreator(LangChainTypeCreator):
elif tool_type in FILE_TOOLS:
params = all_tools[name]["params"] # type: ignore
base_classes += [name]
else:
params = []

View file

@ -345,3 +345,41 @@ class MemoryFrontendNode(FrontendNode):
field.field_type = "int"
field.value = 10
field.display_name = "Memory Size"
class ChainFrontendNode(FrontendNode):
@staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
FrontendNode.format_field(field, name)
if "key" in field.name:
field.password = False
field.show = False
class LLMFrontendNode(FrontendNode):
@staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
display_names_dict = {
"huggingfacehub_api_token": "HuggingFace Hub API Token",
}
FrontendNode.format_field(field, name)
SHOW_FIELDS = ["repo_id", "task", "model_kwargs"]
if field.name in SHOW_FIELDS:
field.show = True
if "api" in field.name and ("key" in field.name or "token" in field.name):
field.password = True
field.show = True
field.required = True
if field.name == "task":
field.required = True
field.show = True
field.is_list = True
field.options = ["text-generation", "text2text-generation"]
if display_name := display_names_dict.get(field.name):
field.display_name = display_name
if field.name == "model_kwargs":
field.field_type = "code"