diff --git a/src/backend/langflow/components/utilities/DocumentToRecord.py b/src/backend/langflow/components/utilities/DocumentToRecord.py new file mode 100644 index 000000000..8d6fadb54 --- /dev/null +++ b/src/backend/langflow/components/utilities/DocumentToRecord.py @@ -0,0 +1,21 @@ +from git import List +from langchain_core.documents import Document + +from langflow import CustomComponent +from langflow.schema import Record + + +class DocumentToRecordComponent(CustomComponent): + display_name = "Documents to Records" + description = "Convert documents to records." + + field_config = { + "documents": {"display_name": "Documents"}, + } + + def build(self, documents: List[Document]) -> List[Record]: + if isinstance(documents, Document): + documents = [documents] + records = [Record.from_document(document) for document in documents] + self.status = records + return records