From 92b398d29b78dfe9c1f3dda399dddafabb9d506b Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Mon, 10 Jun 2024 11:35:40 -0300 Subject: [PATCH 1/2] Refactor: block non supported file types --- .../chatView/chatInput/hooks/use-drag-and-drop.tsx | 4 ++-- .../chatInput/hooks/use-handle-file-change.tsx | 4 ++-- .../chatView/chatInput/hooks/use-upload.tsx | 11 ++--------- .../components/chatView/fileComponent/index.tsx | 2 ++ 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-drag-and-drop.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-drag-and-drop.tsx index b9f1e2635..7abc8d6e3 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-drag-and-drop.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-drag-and-drop.tsx @@ -4,7 +4,7 @@ import useAlertStore from "../../../../../../stores/alertStore"; const fsErrorText = "Please ensure your file has one of the following extensions:"; -const snErrorTxt = "png, jpg, jpeg, gif, bmp, webp"; +const snErrorTxt = "png, jpg, jpeg"; const useDragAndDrop = ( setIsDragging, @@ -49,7 +49,7 @@ const useDragAndDrop = ( const handleFiles = (files, setFiles, currentFlowId, setErrorData) => { if (files) { - const allowedExtensions = ["png", "jpg", "jpeg", "gif", "bmp", "webp"]; + const allowedExtensions = ["png", "jpg", "jpeg"]; const file = files?.[0]; const fileExtension = file.name.split(".").pop()?.toLowerCase(); if (!fileExtension || !allowedExtensions.includes(fileExtension)) { diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-handle-file-change.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-handle-file-change.tsx index 6e16587f2..796f99c75 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-handle-file-change.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-handle-file-change.tsx @@ -4,7 +4,7 @@ import useAlertStore from "../../../../../../stores/alertStore"; const fsErrorText = "Please ensure your file has one of the following extensions:"; -const snErrorTxt = "png, jpg, jpeg, gif, bmp, webp"; +const snErrorTxt = "png, jpg, jpeg"; export const useHandleFileChange = (setFiles, currentFlowId) => { const setErrorData = useAlertStore((state) => state.setErrorData); @@ -14,7 +14,7 @@ export const useHandleFileChange = (setFiles, currentFlowId) => { const fileInput = event.target; const file = fileInput.files?.[0]; if (file) { - const allowedExtensions = ["png", "jpg", "jpeg", "gif", "bmp", "webp"]; + const allowedExtensions = ["png", "jpg", "jpeg"]; const fileExtension = file.name.split(".").pop()?.toLowerCase(); if (!fileExtension || !allowedExtensions.includes(fileExtension)) { diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-upload.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-upload.tsx index f41cada11..a45fd171f 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-upload.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-upload.tsx @@ -5,7 +5,7 @@ import useAlertStore from "../../../../../../stores/alertStore"; const fsErrorText = "Please ensure your file has one of the following extensions:"; -const snErrorTxt = "png, jpg, jpeg, gif, bmp, webp"; +const snErrorTxt = "png, jpg, jpeg"; const useUpload = (uploadFile, currentFlowId, setFiles, lockChat) => { const setErrorData = useAlertStore((state) => state.setErrorData); @@ -21,14 +21,7 @@ const useUpload = (uploadFile, currentFlowId, setFiles, lockChat) => { const uid = new ShortUniqueId({ length: 3 }); const blob = items[i].getAsFile(); if (blob) { - const allowedExtensions = [ - "png", - "jpg", - "jpeg", - "gif", - "bmp", - "webp", - ]; + const allowedExtensions = ["png", "jpg", "jpeg"]; const fileExtension = blob.name.split(".").pop()?.toLowerCase(); if (!fileExtension || !allowedExtensions.includes(fileExtension)) { diff --git a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx index b62e0f763..a034b1c40 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx @@ -32,6 +32,8 @@ export default function FileCard({ BACKEND_URL.length - 1, )}${BASE_URL_API}files/images/${content}`; + console.log(imgSrc); + if (showFile) { if (imgTypes.has(fileType)) { return ( From 7557c7979c2366f3ba53b8406557e73bf5da72b6 Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Mon, 10 Jun 2024 12:02:53 -0300 Subject: [PATCH 2/2] refactor: add utility function for converting chroma collection to records --- .../langflow/base/vectorstores/__init__.py | 0 .../base/langflow/base/vectorstores/utils.py | 24 +++++++++++++++++++ .../components/vectorstores/Chroma.py | 5 +++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/backend/base/langflow/base/vectorstores/__init__.py create mode 100644 src/backend/base/langflow/base/vectorstores/utils.py diff --git a/src/backend/base/langflow/base/vectorstores/__init__.py b/src/backend/base/langflow/base/vectorstores/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/backend/base/langflow/base/vectorstores/utils.py b/src/backend/base/langflow/base/vectorstores/utils.py new file mode 100644 index 000000000..e8d93ff37 --- /dev/null +++ b/src/backend/base/langflow/base/vectorstores/utils.py @@ -0,0 +1,24 @@ +from langflow.schema import Record + + +def chroma_collection_to_records(collection_dict: dict): + """ + Converts a collection of chroma vectors into a list of records. + + Args: + collection_dict (dict): A dictionary containing the collection of chroma vectors. + + Returns: + list: A list of records, where each record represents a document in the collection. + """ + records = [] + for i, doc in enumerate(collection_dict["documents"]): + record_dict = { + "id": collection_dict["ids"][i], + "document": doc, + } + if "metadatas" in collection_dict: + for key, value in collection_dict["metadatas"][i].items(): + record_dict[key] = value + records.append(Record(**record_dict)) + return records diff --git a/src/backend/base/langflow/components/vectorstores/Chroma.py b/src/backend/base/langflow/components/vectorstores/Chroma.py index 5742aad7b..b7cfad7d4 100644 --- a/src/backend/base/langflow/components/vectorstores/Chroma.py +++ b/src/backend/base/langflow/components/vectorstores/Chroma.py @@ -6,7 +6,7 @@ from langchain_chroma import Chroma from langchain_core.embeddings import Embeddings from langchain_core.retrievers import BaseRetriever from langchain_core.vectorstores import VectorStore - +from langflow.base.vectorstores.utils import chroma_collection_to_records from langflow.custom import CustomComponent from langflow.schema import Record @@ -121,4 +121,7 @@ class ChromaComponent(CustomComponent): client=client, embedding_function=embedding, ) + + store = chroma.get() + self.status = chroma_collection_to_records(store) return chroma