Add DocumentToRecordComponent to convert documents to records

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-25 19:23:16 -03:00
commit 4100266aa6

View file

@ -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