🐛 fix(base.py): change 'suffixes' to 'fileTypes' in Vertex and LangChainTypeCreator classes to improve consistency and readability

🐛 fix(base.py): remove 'suffixes' attribute from TemplateFieldCreator class as it is duplicate and not used

🐛 fix(base.py): change 'suffixes' to 'file_types' in TOOL_INPUTS dictionary to improve consistency and readability

🐛 fix(base.py): remove 'suffixes' attribute from TemplateFieldCreator class as it is duplicate and not used

🐛 fix(frontend_node/base.py): remove 'suffixes' attribute from FrontendNode class as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from build_file_field function as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from file_path_templates dictionary as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from build_file_field function as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from file_path_templates dictionary as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from build_file_field function as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from file_path_templates dictionary as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from build_file_field function as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from file_path_templates dictionary as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from build_file_field function as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from file_path_templates dictionary as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from build_file_field function as it is duplicate and not used

🐛 fix(frontend_node/documentloaders.py): remove 'suffixes' attribute from
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-17 16:03:23 -03:00
commit 2532581e02
13 changed files with 75 additions and 60 deletions

View file

@ -157,7 +157,7 @@ class Vertex:
# If the type is not transformable to a python base class
# then we need to get the edge that connects to this node
if value.get("type") == "file":
# Load the type in value.get('suffixes') using
# Load the type in value.get('fileTypes') using
# what is inside value.get('content')
# value.get('value') is the file name
if file_path := value.get("file_path"):

View file

@ -83,7 +83,6 @@ class LangChainTypeCreator(BaseModel, ABC):
show=value.get("show", True),
multiline=value.get("multiline", False),
value=value.get("value", None),
suffixes=value.get("suffixes", []),
file_types=value.get("fileTypes", []),
file_path=value.get("file_path", None),
)

View file

@ -54,8 +54,7 @@ TOOL_INPUTS = {
is_list=False,
show=True,
value="",
suffixes=[".json", ".yaml", ".yml"],
file_types=["json", "yaml", "yml"],
file_types=[".json", ".yaml", ".yml"],
),
}

View file

@ -26,9 +26,6 @@ class TemplateFieldCreator(BaseModel, ABC):
value: Any = None
"""The value of the field. Default is None."""
suffixes: list[str] = []
"""List of suffixes for a file field. Default is an empty list."""
file_types: list[str] = []
"""List of file types associated with the field. Default is an empty list. (duplicate)"""

View file

@ -144,8 +144,7 @@ class CSVAgentNode(FrontendNode):
show=True,
name="path",
value="",
suffixes=[".csv"],
file_types=["csv"],
file_types=[".csv"],
),
TemplateField(
field_type="BaseLanguageModel",

View file

@ -2,16 +2,13 @@ import re
from collections import defaultdict
from typing import ClassVar, DefaultDict, Dict, List, Optional
from pydantic import BaseModel, Field
from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.constants import (
CLASSES_TO_REMOVE,
FORCE_SHOW_FIELDS,
)
from langflow.template.frontend_node.constants import (CLASSES_TO_REMOVE,
FORCE_SHOW_FIELDS)
from langflow.template.frontend_node.formatter import field_formatters
from langflow.template.template.base import Template
from langflow.utils import constants
from pydantic import BaseModel, Field
class FieldFormatters(BaseModel):
@ -138,9 +135,12 @@ class FrontendNode(BaseModel):
"""Handles 'dict' type by replacing it with 'code' or 'file' based on the field name."""
if "dict" in _type.lower() and field.name == "dict_":
field.field_type = "file"
field.suffixes = [".json", ".yaml", ".yml"]
field.file_types = ["json", "yaml", "yml"]
elif _type.startswith("Dict") or _type.startswith("Mapping") or _type.startswith("dict"):
field.file_types = [".json", ".yaml", ".yml"]
elif (
_type.startswith("Dict")
or _type.startswith("Mapping")
or _type.startswith("dict")
):
field.field_type = "dict"
return _type

View file

@ -1,9 +1,10 @@
from typing import ClassVar, Dict, Optional
from typing import ClassVar, Dict
from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.base import FrontendNode
def build_file_field(suffixes: list, fileTypes: list, name: str = "file_path") -> TemplateField:
def build_file_field(fileTypes: list, name: str = "file_path") -> TemplateField:
"""Build a template field for a document loader."""
return TemplateField(
field_type="file",
@ -11,7 +12,6 @@ def build_file_field(suffixes: list, fileTypes: list, name: str = "file_path") -
show=True,
name=name,
value="",
suffixes=suffixes,
file_types=fileTypes,
)
@ -22,25 +22,52 @@ class DocumentLoaderFrontNode(FrontendNode):
self.output_types = ["Document"]
file_path_templates: ClassVar[Dict] = {
"AirbyteJSONLoader": build_file_field(suffixes=[".json"], fileTypes=["json"]),
"CoNLLULoader": build_file_field(suffixes=[".csv"], fileTypes=["csv"]),
"CSVLoader": build_file_field(suffixes=[".csv"], fileTypes=["csv"]),
"UnstructuredEmailLoader": build_file_field(suffixes=[".eml"], fileTypes=["eml"]),
"EverNoteLoader": build_file_field(suffixes=[".xml"], fileTypes=["xml"]),
"FacebookChatLoader": build_file_field(suffixes=[".json"], fileTypes=["json"]),
"BSHTMLLoader": build_file_field(suffixes=[".html"], fileTypes=["html"]),
"UnstructuredHTMLLoader": build_file_field(suffixes=[".html"], fileTypes=["html"]),
"UnstructuredImageLoader": build_file_field(
suffixes=[".jpg", ".jpeg", ".png", ".gif", ".bmp"],
fileTypes=["jpg", "jpeg", "png", "gif", "bmp"],
"AirbyteJSONLoader": build_file_field(
fileTypes=[".json"],
),
"CoNLLULoader": build_file_field(
fileTypes=[".csv"],
),
"CSVLoader": build_file_field(
fileTypes=[".csv"],
),
"UnstructuredEmailLoader": build_file_field(
fileTypes=[".eml"],
),
"EverNoteLoader": build_file_field(
fileTypes=[".xml"],
),
"FacebookChatLoader": build_file_field(
fileTypes=[".json"],
),
"BSHTMLLoader": build_file_field(
fileTypes=[".html"],
),
"UnstructuredHTMLLoader": build_file_field(fileTypes=[".html"]),
"UnstructuredImageLoader": build_file_field(
fileTypes=[".jpg", ".jpeg", ".png", ".gif", ".bmp"],
),
"UnstructuredMarkdownLoader": build_file_field(
fileTypes=[".md"],
),
"PyPDFLoader": build_file_field(
fileTypes=[".pdf"],
),
"UnstructuredPowerPointLoader": build_file_field(
fileTypes=[".pptx", ".ppt"],
),
"SRTLoader": build_file_field(
fileTypes=[".srt"],
),
"TelegramChatLoader": build_file_field(
fileTypes=[".json"],
),
"TextLoader": build_file_field(
fileTypes=[".txt"],
),
"UnstructuredWordDocumentLoader": build_file_field(
fileTypes=[".docx", ".doc"],
),
"UnstructuredMarkdownLoader": build_file_field(suffixes=[".md"], fileTypes=["md"]),
"PyPDFLoader": build_file_field(suffixes=[".pdf"], fileTypes=["pdf"]),
"UnstructuredPowerPointLoader": build_file_field(suffixes=[".pptx", ".ppt"], fileTypes=["pptx", "ppt"]),
"SRTLoader": build_file_field(suffixes=[".srt"], fileTypes=["srt"]),
"TelegramChatLoader": build_file_field(suffixes=[".json"], fileTypes=["json"]),
"TextLoader": build_file_field(suffixes=[".txt"], fileTypes=["txt"]),
"UnstructuredWordDocumentLoader": build_file_field(suffixes=[".docx", ".doc"], fileTypes=["docx", "doc"]),
}
def add_extra_fields(self) -> None:
@ -101,8 +128,7 @@ class DocumentLoaderFrontNode(FrontendNode):
name="zip_path",
value="",
display_name="Path to zip file",
suffixes=[".zip"],
file_types=["zip"],
file_types=[".zip"],
)
)
self.template.add_field(

View file

@ -15,8 +15,7 @@ class EmbeddingFrontendNode(FrontendNode):
show=True,
name="credentials",
value="",
suffixes=[".json"],
file_types=["json"],
file_types=[".json"],
)
)

View file

@ -1,14 +1,11 @@
import re
from typing import ClassVar, Dict, Optional
from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS
from langflow.template.frontend_node.formatter.base import FieldFormatter
import re
from langflow.utils.constants import (
ANTHROPIC_MODELS,
CHAT_OPENAI_MODELS,
OPENAI_MODELS,
)
from langflow.utils.constants import (ANTHROPIC_MODELS, CHAT_OPENAI_MODELS,
OPENAI_MODELS)
class OpenAIAPIKeyFormatter(FieldFormatter):
@ -152,7 +149,10 @@ class DictCodeFileFormatter(FieldFormatter):
_type = value["type"]
if "dict" in _type.lower() and key == "dict_":
field.field_type = "file"
field.suffixes = [".json", ".yaml", ".yml"]
field.file_types = ["json", "yaml", "yml"]
elif _type.startswith("Dict") or _type.startswith("Mapping") or _type.startswith("dict"):
field.file_types = [".json", ".yaml", ".yml"]
elif (
_type.startswith("Dict")
or _type.startswith("Mapping")
or _type.startswith("dict")
):
field.field_type = "dict"

View file

@ -18,8 +18,7 @@ class LLMFrontendNode(FrontendNode):
show=True,
name="credentials",
value="",
suffixes=[".json"],
file_types=["json"],
file_types=[".json"],
)
)

View file

@ -403,8 +403,7 @@ def set_dict_file_attributes(value: Dict[str, Any]) -> None:
Sets the file attributes for the 'dict_' key.
"""
value["type"] = "file"
value["suffixes"] = [".json", ".yaml", ".yml"]
value["fileTypes"] = ["json", "yaml", "yml"]
value["fileTypes"] = [".json", ".yaml", ".yml"]
def replace_default_value_with_actual(value: Dict[str, Any]) -> None:

View file

@ -169,8 +169,7 @@ def test_csv_agent(client: TestClient, logged_in_headers):
"show": True,
"multiline": False,
"value": "",
"suffixes": [".csv"],
"fileTypes": ["csv"],
"fileTypes": [".csv"],
"password": False,
"name": "path",
"type": "file",

View file

@ -32,7 +32,6 @@ def test_template_field_defaults(sample_template_field: TemplateField):
assert sample_template_field.show is True
assert sample_template_field.multiline is False
assert sample_template_field.value is None
assert sample_template_field.suffixes == []
assert sample_template_field.file_types == []
assert sample_template_field.file_path is None
assert sample_template_field.password is False