From b8b9bb25bc253c2eb4e5d19a1470775b2b134dc8 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 22 Aug 2023 11:56:01 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20feat(JSONDocumentBuilder.py):=20?= =?UTF-8?q?add=20JSONDocumentBuilder=20component=20to=20build=20a=20Docume?= =?UTF-8?q?nt=20containing=20a=20JSON=20object=20using=20a=20key=20and=20a?= =?UTF-8?q?nother=20Document=20page=20content=20=F0=9F=93=9D=20docs(JSONDo?= =?UTF-8?q?cumentBuilder.py):=20add=20description=20and=20field=20configur?= =?UTF-8?q?ation=20for=20JSONDocumentBuilder=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utilities/JSONDocumentBuilder.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/backend/langflow/components/utilities/JSONDocumentBuilder.py diff --git a/src/backend/langflow/components/utilities/JSONDocumentBuilder.py b/src/backend/langflow/components/utilities/JSONDocumentBuilder.py new file mode 100644 index 000000000..0336dcc1b --- /dev/null +++ b/src/backend/langflow/components/utilities/JSONDocumentBuilder.py @@ -0,0 +1,34 @@ +### JSON Document Builder + +# Build a Document containing a JSON object using a key and another Document page content. + +# **Params** + +# - **Key:** The key to use for the JSON object. +# - **Document:** The Document page to use for the JSON object. + +# **Output** + +# - **Document:** The Document containing the JSON object. + +from langflow import CustomComponent +from langchain.schema import Document + + +class JSONDocumentBuilder(CustomComponent): + display_name: str = "JSON Document Builder" + description: str = "Build a Document containing a JSON object using a key and another Document page content." + output_types: list[str] = ["Document"] + beta = True + + field_config = { + "key": {"display_name": "Key"}, + "document": {"display_name": "Document"}, + } + + def build( + self, + key: str, + document: Document, + ) -> Document: + return Document(page_content={key: document.page_content})