📦 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:
parent
fb028e55b8
commit
b8b9bb25bc
1 changed files with 34 additions and 0 deletions
|
|
@ -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})
|
||||||
Loading…
Add table
Add a link
Reference in a new issue