🐛 fix(JSONDocumentBuilder.py): fix JSON serialization issue by using orjson_dumps function
🔒 chore(JSONDocumentBuilder.py): add type checking and raise TypeError for invalid input
This commit is contained in:
parent
0d53db1653
commit
8098cea405
1 changed files with 12 additions and 2 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langchain.schema import Document
|
from langchain.schema import Document
|
||||||
|
from langflow.database.models.base import orjson_dumps
|
||||||
|
|
||||||
|
|
||||||
class JSONDocumentBuilder(CustomComponent):
|
class JSONDocumentBuilder(CustomComponent):
|
||||||
|
|
@ -34,9 +35,18 @@ class JSONDocumentBuilder(CustomComponent):
|
||||||
documents = None
|
documents = None
|
||||||
if isinstance(document, list):
|
if isinstance(document, list):
|
||||||
documents = [
|
documents = [
|
||||||
Document(page_content={key: doc.page_content}) for doc in document
|
Document(
|
||||||
|
page_content=orjson_dumps({key: doc.page_content}, indent_2=False)
|
||||||
|
)
|
||||||
|
for doc in document
|
||||||
]
|
]
|
||||||
|
elif isinstance(document, Document):
|
||||||
|
documents = Document(
|
||||||
|
page_content=orjson_dumps({key: document.page_content}, indent_2=False)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
documents = Document(page_content={key: document.page_content})
|
raise TypeError(
|
||||||
|
f"Expected Document or list of Documents, got {type(document)}"
|
||||||
|
)
|
||||||
self.repr_value = documents
|
self.repr_value = documents
|
||||||
return documents
|
return documents
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue