🐛 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:
parent
0f9827564e
commit
2532581e02
13 changed files with 75 additions and 60 deletions
|
|
@ -157,7 +157,7 @@ class Vertex:
|
||||||
# If the type is not transformable to a python base class
|
# If the type is not transformable to a python base class
|
||||||
# then we need to get the edge that connects to this node
|
# then we need to get the edge that connects to this node
|
||||||
if value.get("type") == "file":
|
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')
|
# what is inside value.get('content')
|
||||||
# value.get('value') is the file name
|
# value.get('value') is the file name
|
||||||
if file_path := value.get("file_path"):
|
if file_path := value.get("file_path"):
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,6 @@ class LangChainTypeCreator(BaseModel, ABC):
|
||||||
show=value.get("show", True),
|
show=value.get("show", True),
|
||||||
multiline=value.get("multiline", False),
|
multiline=value.get("multiline", False),
|
||||||
value=value.get("value", None),
|
value=value.get("value", None),
|
||||||
suffixes=value.get("suffixes", []),
|
|
||||||
file_types=value.get("fileTypes", []),
|
file_types=value.get("fileTypes", []),
|
||||||
file_path=value.get("file_path", None),
|
file_path=value.get("file_path", None),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,7 @@ TOOL_INPUTS = {
|
||||||
is_list=False,
|
is_list=False,
|
||||||
show=True,
|
show=True,
|
||||||
value="",
|
value="",
|
||||||
suffixes=[".json", ".yaml", ".yml"],
|
file_types=[".json", ".yaml", ".yml"],
|
||||||
file_types=["json", "yaml", "yml"],
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,6 @@ class TemplateFieldCreator(BaseModel, ABC):
|
||||||
value: Any = None
|
value: Any = None
|
||||||
"""The value of the field. Default is 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] = []
|
file_types: list[str] = []
|
||||||
"""List of file types associated with the field. Default is an empty list. (duplicate)"""
|
"""List of file types associated with the field. Default is an empty list. (duplicate)"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,7 @@ class CSVAgentNode(FrontendNode):
|
||||||
show=True,
|
show=True,
|
||||||
name="path",
|
name="path",
|
||||||
value="",
|
value="",
|
||||||
suffixes=[".csv"],
|
file_types=[".csv"],
|
||||||
file_types=["csv"],
|
|
||||||
),
|
),
|
||||||
TemplateField(
|
TemplateField(
|
||||||
field_type="BaseLanguageModel",
|
field_type="BaseLanguageModel",
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,13 @@ import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import ClassVar, DefaultDict, Dict, List, Optional
|
from typing import ClassVar, DefaultDict, Dict, List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.template.frontend_node.constants import (
|
from langflow.template.frontend_node.constants import (CLASSES_TO_REMOVE,
|
||||||
CLASSES_TO_REMOVE,
|
FORCE_SHOW_FIELDS)
|
||||||
FORCE_SHOW_FIELDS,
|
|
||||||
)
|
|
||||||
from langflow.template.frontend_node.formatter import field_formatters
|
from langflow.template.frontend_node.formatter import field_formatters
|
||||||
from langflow.template.template.base import Template
|
from langflow.template.template.base import Template
|
||||||
from langflow.utils import constants
|
from langflow.utils import constants
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
class FieldFormatters(BaseModel):
|
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."""
|
"""Handles 'dict' type by replacing it with 'code' or 'file' based on the field name."""
|
||||||
if "dict" in _type.lower() and field.name == "dict_":
|
if "dict" in _type.lower() and field.name == "dict_":
|
||||||
field.field_type = "file"
|
field.field_type = "file"
|
||||||
field.suffixes = [".json", ".yaml", ".yml"]
|
field.file_types = [".json", ".yaml", ".yml"]
|
||||||
field.file_types = ["json", "yaml", "yml"]
|
elif (
|
||||||
elif _type.startswith("Dict") or _type.startswith("Mapping") or _type.startswith("dict"):
|
_type.startswith("Dict")
|
||||||
|
or _type.startswith("Mapping")
|
||||||
|
or _type.startswith("dict")
|
||||||
|
):
|
||||||
field.field_type = "dict"
|
field.field_type = "dict"
|
||||||
return _type
|
return _type
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.field.base import TemplateField
|
||||||
from langflow.template.frontend_node.base import FrontendNode
|
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."""
|
"""Build a template field for a document loader."""
|
||||||
return TemplateField(
|
return TemplateField(
|
||||||
field_type="file",
|
field_type="file",
|
||||||
|
|
@ -11,7 +12,6 @@ def build_file_field(suffixes: list, fileTypes: list, name: str = "file_path") -
|
||||||
show=True,
|
show=True,
|
||||||
name=name,
|
name=name,
|
||||||
value="",
|
value="",
|
||||||
suffixes=suffixes,
|
|
||||||
file_types=fileTypes,
|
file_types=fileTypes,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -22,25 +22,52 @@ class DocumentLoaderFrontNode(FrontendNode):
|
||||||
self.output_types = ["Document"]
|
self.output_types = ["Document"]
|
||||||
|
|
||||||
file_path_templates: ClassVar[Dict] = {
|
file_path_templates: ClassVar[Dict] = {
|
||||||
"AirbyteJSONLoader": build_file_field(suffixes=[".json"], fileTypes=["json"]),
|
"AirbyteJSONLoader": build_file_field(
|
||||||
"CoNLLULoader": build_file_field(suffixes=[".csv"], fileTypes=["csv"]),
|
fileTypes=[".json"],
|
||||||
"CSVLoader": build_file_field(suffixes=[".csv"], fileTypes=["csv"]),
|
),
|
||||||
"UnstructuredEmailLoader": build_file_field(suffixes=[".eml"], fileTypes=["eml"]),
|
"CoNLLULoader": build_file_field(
|
||||||
"EverNoteLoader": build_file_field(suffixes=[".xml"], fileTypes=["xml"]),
|
fileTypes=[".csv"],
|
||||||
"FacebookChatLoader": build_file_field(suffixes=[".json"], fileTypes=["json"]),
|
),
|
||||||
"BSHTMLLoader": build_file_field(suffixes=[".html"], fileTypes=["html"]),
|
"CSVLoader": build_file_field(
|
||||||
"UnstructuredHTMLLoader": build_file_field(suffixes=[".html"], fileTypes=["html"]),
|
fileTypes=[".csv"],
|
||||||
"UnstructuredImageLoader": build_file_field(
|
),
|
||||||
suffixes=[".jpg", ".jpeg", ".png", ".gif", ".bmp"],
|
"UnstructuredEmailLoader": build_file_field(
|
||||||
fileTypes=["jpg", "jpeg", "png", "gif", "bmp"],
|
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:
|
def add_extra_fields(self) -> None:
|
||||||
|
|
@ -101,8 +128,7 @@ class DocumentLoaderFrontNode(FrontendNode):
|
||||||
name="zip_path",
|
name="zip_path",
|
||||||
value="",
|
value="",
|
||||||
display_name="Path to zip file",
|
display_name="Path to zip file",
|
||||||
suffixes=[".zip"],
|
file_types=[".zip"],
|
||||||
file_types=["zip"],
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.template.add_field(
|
self.template.add_field(
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ class EmbeddingFrontendNode(FrontendNode):
|
||||||
show=True,
|
show=True,
|
||||||
name="credentials",
|
name="credentials",
|
||||||
value="",
|
value="",
|
||||||
suffixes=[".json"],
|
file_types=[".json"],
|
||||||
file_types=["json"],
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
|
import re
|
||||||
from typing import ClassVar, Dict, Optional
|
from typing import ClassVar, Dict, Optional
|
||||||
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS
|
from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS
|
||||||
from langflow.template.frontend_node.formatter.base import FieldFormatter
|
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):
|
class OpenAIAPIKeyFormatter(FieldFormatter):
|
||||||
|
|
@ -152,7 +149,10 @@ class DictCodeFileFormatter(FieldFormatter):
|
||||||
_type = value["type"]
|
_type = value["type"]
|
||||||
if "dict" in _type.lower() and key == "dict_":
|
if "dict" in _type.lower() and key == "dict_":
|
||||||
field.field_type = "file"
|
field.field_type = "file"
|
||||||
field.suffixes = [".json", ".yaml", ".yml"]
|
field.file_types = [".json", ".yaml", ".yml"]
|
||||||
field.file_types = ["json", "yaml", "yml"]
|
elif (
|
||||||
elif _type.startswith("Dict") or _type.startswith("Mapping") or _type.startswith("dict"):
|
_type.startswith("Dict")
|
||||||
|
or _type.startswith("Mapping")
|
||||||
|
or _type.startswith("dict")
|
||||||
|
):
|
||||||
field.field_type = "dict"
|
field.field_type = "dict"
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,7 @@ class LLMFrontendNode(FrontendNode):
|
||||||
show=True,
|
show=True,
|
||||||
name="credentials",
|
name="credentials",
|
||||||
value="",
|
value="",
|
||||||
suffixes=[".json"],
|
file_types=[".json"],
|
||||||
file_types=["json"],
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -403,8 +403,7 @@ def set_dict_file_attributes(value: Dict[str, Any]) -> None:
|
||||||
Sets the file attributes for the 'dict_' key.
|
Sets the file attributes for the 'dict_' key.
|
||||||
"""
|
"""
|
||||||
value["type"] = "file"
|
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:
|
def replace_default_value_with_actual(value: Dict[str, Any]) -> None:
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,7 @@ def test_csv_agent(client: TestClient, logged_in_headers):
|
||||||
"show": True,
|
"show": True,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "",
|
"value": "",
|
||||||
"suffixes": [".csv"],
|
"fileTypes": [".csv"],
|
||||||
"fileTypes": ["csv"],
|
|
||||||
"password": False,
|
"password": False,
|
||||||
"name": "path",
|
"name": "path",
|
||||||
"type": "file",
|
"type": "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.show is True
|
||||||
assert sample_template_field.multiline is False
|
assert sample_template_field.multiline is False
|
||||||
assert sample_template_field.value is None
|
assert sample_template_field.value is None
|
||||||
assert sample_template_field.suffixes == []
|
|
||||||
assert sample_template_field.file_types == []
|
assert sample_template_field.file_types == []
|
||||||
assert sample_template_field.file_path is None
|
assert sample_template_field.file_path is None
|
||||||
assert sample_template_field.password is False
|
assert sample_template_field.password is False
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue