From fbdde257e0930d61344ed7790b84cba0a1eaff66 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sat, 8 Jul 2023 14:52:59 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(types.py):=20fix=20indentati?= =?UTF-8?q?on=20issue=20in=20the=20repr=20method=20of=20DocumentLoaderVert?= =?UTF-8?q?ex=20and=20TextSplitterVertex=20classes=20=F0=9F=94=A7=20fix(ty?= =?UTF-8?q?pes.py):=20calculate=20average=20document=20length=20in=20the?= =?UTF-8?q?=20repr=20method=20of=20DocumentLoaderVertex=20and=20TextSplitt?= =?UTF-8?q?erVertex=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/types.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/langflow/graph/vertex/types.py b/src/backend/langflow/graph/vertex/types.py index a8b38bb3f..9f57ed09b 100644 --- a/src/backend/langflow/graph/vertex/types.py +++ b/src/backend/langflow/graph/vertex/types.py @@ -93,7 +93,11 @@ class DocumentLoaderVertex(Vertex): # show how many documents are in the list? if self._built_object: + avg_length = sum(len(doc.page_content) for doc in self._built_object) / len( + self._built_object + ) return f"""{self.vertex_type}({len(self._built_object)} documents) + \nAvg. Document Length (characters): {avg_length} Documents: {self._built_object[:3]}...""" return f"{self.vertex_type}()" @@ -125,8 +129,13 @@ class TextSplitterVertex(Vertex): def _built_object_repr(self): # This built_object is a list of documents. Maybe we should # show how many documents are in the list? + if self._built_object: + avg_length = sum(len(doc.page_content) for doc in self._built_object) / len( + self._built_object + ) return f"""{self.vertex_type}({len(self._built_object)} documents) + \nAvg. Document Length (characters): {avg_length} \nDocuments: {self._built_object[:3]}...""" return f"{self.vertex_type}()"