From 209e31da26dd95c4e6c274a3f0b0ab17dd3679e5 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Rosalino Date: Sun, 28 May 2023 02:05:32 -0300 Subject: [PATCH 1/2] feat: adds NotionDirectoryLoader --- src/backend/langflow/config.yaml | 1 + .../interface/document_loaders/base.py | 2 +- .../inputDirectoryComponent/index.tsx | 98 +++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/frontend/src/components/inputDirectoryComponent/index.tsx diff --git a/src/backend/langflow/config.yaml b/src/backend/langflow/config.yaml index b1da1b622..6dadc7a88 100644 --- a/src/backend/langflow/config.yaml +++ b/src/backend/langflow/config.yaml @@ -42,6 +42,7 @@ documentloaders: - IMSDbLoader - GitbookLoader - ReadTheDocsLoader + - NotionDirectoryLoader embeddings: - OpenAIEmbeddings - HuggingFaceEmbeddings diff --git a/src/backend/langflow/interface/document_loaders/base.py b/src/backend/langflow/interface/document_loaders/base.py index aab017c0f..a13d5cd5b 100644 --- a/src/backend/langflow/interface/document_loaders/base.py +++ b/src/backend/langflow/interface/document_loaders/base.py @@ -118,7 +118,7 @@ class DocumentLoaderCreator(LangChainTypeCreator): "value": "", "display_name": "Web Page", } - elif name in {"ReadTheDocsLoader"}: + elif name in {"ReadTheDocsLoader", "NotionDirectoryLoader"}: signature["template"]["path"] = { "type": "str", "required": True, diff --git a/src/frontend/src/components/inputDirectoryComponent/index.tsx b/src/frontend/src/components/inputDirectoryComponent/index.tsx new file mode 100644 index 000000000..eb167bbee --- /dev/null +++ b/src/frontend/src/components/inputDirectoryComponent/index.tsx @@ -0,0 +1,98 @@ +import { DocumentMagnifyingGlassIcon } from "@heroicons/react/24/outline"; +import { useContext, useEffect, useState } from "react"; +import { alertContext } from "../../contexts/alertContext"; +import { FileComponentType } from "../../types/components"; + +export default function InputDirectoryComponent({ + value, + onChange, + disabled, + suffixes, + fileTypes, + onFileChange, +}: FileComponentType) { + const [myValue, setMyValue] = useState(value); + const { setErrorData } = useContext(alertContext); + useEffect(() => { + if (disabled) { + setMyValue(""); + onChange(""); + onFileChange(""); + } + }, [disabled, onChange]); + + function attachFiles(files) { + onFileChange(files); + } + + function checkFileType(fileName: string): boolean { + for (let index = 0; index < suffixes.length; index++) { + if (fileName.endsWith(suffixes[index])) { + return true; + } + } + return false; + } + + const handleDirectoryButtonClick = () => { + const input = document.createElement("input"); + input.type = "file"; + input.accept = suffixes.join(","); + input.style.display = "none"; + input.multiple = true; + input.webkitdirectory = true; + input.onchange = (e: Event) => { + const filesArray = []; + const inputElement = e.target as HTMLInputElement; + console.log(inputElement.webkitEntries); // Not working + const files = (e.target as HTMLInputElement).files; + const directory = (e.target as HTMLInputElement).dirName; // Not working + + console.log(directory); + if (files) { + for (let index = 0; index < files.length; index++) { + const file = files[index]; + if (checkFileType(file.name)) { + console.log("going in: ", file); + filesArray.push(file); + } + } + if (filesArray.length > 0) { + setMyValue(filesArray[0].webkitRelativePath); + onChange(filesArray[0].webkitRelativePath); + attachFiles(filesArray[0].webkitRelativePath); + } else { + setErrorData({ + title: + "Please select a valid directory. Only directories containing files with these file types are allowed:", + list: fileTypes, + }); + } + } + }; + input.click(); + }; + + return ( +
+
+ + {myValue !== "" ? myValue : "No directory"} + + +
+
+ ); +} From 36910ff1872ea26a20c29b5164b9320d313222e3 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Rosalino Date: Sun, 28 May 2023 02:13:24 -0300 Subject: [PATCH 2/2] chore: removed not needed inputDirectoryComponent --- .../inputDirectoryComponent/index.tsx | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 src/frontend/src/components/inputDirectoryComponent/index.tsx diff --git a/src/frontend/src/components/inputDirectoryComponent/index.tsx b/src/frontend/src/components/inputDirectoryComponent/index.tsx deleted file mode 100644 index eb167bbee..000000000 --- a/src/frontend/src/components/inputDirectoryComponent/index.tsx +++ /dev/null @@ -1,98 +0,0 @@ -import { DocumentMagnifyingGlassIcon } from "@heroicons/react/24/outline"; -import { useContext, useEffect, useState } from "react"; -import { alertContext } from "../../contexts/alertContext"; -import { FileComponentType } from "../../types/components"; - -export default function InputDirectoryComponent({ - value, - onChange, - disabled, - suffixes, - fileTypes, - onFileChange, -}: FileComponentType) { - const [myValue, setMyValue] = useState(value); - const { setErrorData } = useContext(alertContext); - useEffect(() => { - if (disabled) { - setMyValue(""); - onChange(""); - onFileChange(""); - } - }, [disabled, onChange]); - - function attachFiles(files) { - onFileChange(files); - } - - function checkFileType(fileName: string): boolean { - for (let index = 0; index < suffixes.length; index++) { - if (fileName.endsWith(suffixes[index])) { - return true; - } - } - return false; - } - - const handleDirectoryButtonClick = () => { - const input = document.createElement("input"); - input.type = "file"; - input.accept = suffixes.join(","); - input.style.display = "none"; - input.multiple = true; - input.webkitdirectory = true; - input.onchange = (e: Event) => { - const filesArray = []; - const inputElement = e.target as HTMLInputElement; - console.log(inputElement.webkitEntries); // Not working - const files = (e.target as HTMLInputElement).files; - const directory = (e.target as HTMLInputElement).dirName; // Not working - - console.log(directory); - if (files) { - for (let index = 0; index < files.length; index++) { - const file = files[index]; - if (checkFileType(file.name)) { - console.log("going in: ", file); - filesArray.push(file); - } - } - if (filesArray.length > 0) { - setMyValue(filesArray[0].webkitRelativePath); - onChange(filesArray[0].webkitRelativePath); - attachFiles(filesArray[0].webkitRelativePath); - } else { - setErrorData({ - title: - "Please select a valid directory. Only directories containing files with these file types are allowed:", - list: fileTypes, - }); - } - } - }; - input.click(); - }; - - return ( -
-
- - {myValue !== "" ? myValue : "No directory"} - - -
-
- ); -}