From a408dd2b26f6e479cb3b02704572db9c80f4f4d9 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 1 Nov 2023 11:12:08 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(FileLoader.py):=20fix=20type?= =?UTF-8?q?=20annotation=20for=20loaders=5Finfo=20variable=20to=20improve?= =?UTF-8?q?=20code=20readability=20and=20maintainability=20=F0=9F=90=9B=20?= =?UTF-8?q?fix(FileLoader.py):=20fix=20type=20annotation=20for=20loader=5F?= =?UTF-8?q?import=20variable=20to=20improve=20code=20readability=20and=20m?= =?UTF-8?q?aintainability=20=F0=9F=90=9B=20fix(FileLoader.py):=20handle=20?= =?UTF-8?q?case=20when=20selected=5Floader=5Finfo=20is=20not=20a=20dict=20?= =?UTF-8?q?to=20prevent=20potential=20errors=20=F0=9F=90=9B=20fix(UrlLoade?= =?UTF-8?q?r.py):=20fix=20type=20annotation=20for=20build=20method=20retur?= =?UTF-8?q?n=20value=20to=20improve=20code=20readability=20and=20maintaina?= =?UTF-8?q?bility=20=F0=9F=90=9B=20fix(UrlLoader.py):=20fix=20type=20annot?= =?UTF-8?q?ation=20for=20loader=5Finstance=20variables=20to=20improve=20co?= =?UTF-8?q?de=20readability=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/documentloaders/FileLoader.py | 11 ++++++++--- .../components/documentloaders/UrlLoader.py | 17 +++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/backend/langflow/components/documentloaders/FileLoader.py b/src/backend/langflow/components/documentloaders/FileLoader.py index 824bd773c..04f43d60b 100644 --- a/src/backend/langflow/components/documentloaders/FileLoader.py +++ b/src/backend/langflow/components/documentloaders/FileLoader.py @@ -1,7 +1,8 @@ from langflow import CustomComponent from langchain.schema import Document +from typing import Any, Dict, List -loaders_info = [ +loaders_info: List[Dict[str, Any]] = [ { "loader": "AirbyteJSONLoader", "name": "Airbyte JSON (.jsonl)", @@ -210,8 +211,12 @@ class FileLoaderComponent(CustomComponent): raise ValueError(f"No default loader found for file type: {file_type}") selected_loader_info = default_loader_info - - loader_import = selected_loader_info["import"] + if isinstance(selected_loader_info, dict): + loader_import: str = selected_loader_info["import"] + else: + raise ValueError( + f"Loader info for {loader} is not a dict\nLoader info:\n{selected_loader_info}" + ) module_name, class_name = loader_import.rsplit(".", 1) try: diff --git a/src/backend/langflow/components/documentloaders/UrlLoader.py b/src/backend/langflow/components/documentloaders/UrlLoader.py index 710ae20e5..94004e545 100644 --- a/src/backend/langflow/components/documentloaders/UrlLoader.py +++ b/src/backend/langflow/components/documentloaders/UrlLoader.py @@ -1,3 +1,4 @@ +from typing import List from langflow import CustomComponent from langchain.document_loaders import AZLyricsLoader from langchain.document_loaders import CollegeConfidentialLoader @@ -39,21 +40,21 @@ class UrlLoaderComponent(CustomComponent): "code": {"show": False}, } - def build(self, web_path: str, loader: str) -> Document: + def build(self, web_path: str, loader: str) -> List[Document]: if loader == "AZLyricsLoader": - loader_instance = AZLyricsLoader(web_path=web_path) + loader_instance = AZLyricsLoader(web_path=web_path) # type: ignore elif loader == "CollegeConfidentialLoader": - loader_instance = CollegeConfidentialLoader(web_path=web_path) + loader_instance = CollegeConfidentialLoader(web_path=web_path) # type: ignore elif loader == "GitbookLoader": - loader_instance = GitbookLoader(web_path=web_path) + loader_instance = GitbookLoader(web_page=web_path) # type: ignore elif loader == "HNLoader": - loader_instance = HNLoader(web_path=web_path) + loader_instance = HNLoader(web_path=web_path) # type: ignore elif loader == "IFixitLoader": - loader_instance = IFixitLoader(web_path=web_path) + loader_instance = IFixitLoader(web_path=web_path) # type: ignore elif loader == "IMSDbLoader": - loader_instance = IMSDbLoader(web_path=web_path) + loader_instance = IMSDbLoader(web_path=web_path) # type: ignore elif loader == "WebBaseLoader": - loader_instance = WebBaseLoader(web_path=web_path) + loader_instance = WebBaseLoader(web_path=web_path) # type: ignore if loader_instance is None: raise ValueError(f"No loader found for: {web_path}")