📦 feat(JSONDocumentBuilder.py): add JSONDocumentBuilder component to build a Document containing a JSON object using a key and another Document page content

📝 docs(JSONDocumentBuilder.py): add description and field configuration for JSONDocumentBuilder component
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-22 11:56:01 -03:00
commit b8b9bb25bc

View file

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