From d9891b9c86cd8e2b8b88942d1ba4c00ac0dc7b34 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 5 Jul 2023 17:00:50 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(base.py):=20refactor=20cod?= =?UTF-8?q?e=20to=20improve=20readability=20and=20handle=20optional=20para?= =?UTF-8?q?meters=20=F0=9F=93=9D=20chore(base.py):=20update=20comments=20a?= =?UTF-8?q?nd=20remove=20unused=20imports=20The=20code=20in=20the=20`Verte?= =?UTF-8?q?x`=20class=20has=20been=20refactored=20to=20improve=20readabili?= =?UTF-8?q?ty=20and=20handle=20optional=20parameters=20more=20effectively.?= =?UTF-8?q?=20The=20code=20now=20checks=20if=20a=20parameter=20is=20of=20t?= =?UTF-8?q?ype=20"code",=20"str",=20or=20"prompt"=20and=20if=20it=20is=20n?= =?UTF-8?q?ot=20already=20set=20in=20the=20`params`=20dictionary,=20it=20s?= =?UTF-8?q?ets=20it=20to=20the=20corresponding=20value=20from=20the=20`val?= =?UTF-8?q?ue`=20dictionary.=20Additionally,=20if=20a=20parameter=20is=20n?= =?UTF-8?q?ot=20required=20and=20not=20set=20in=20the=20`params`=20diction?= =?UTF-8?q?ary,=20it=20checks=20if=20a=20default=20value=20is=20provided?= =?UTF-8?q?=20and=20sets=20it=20to=20the=20default=20value=20if=20availabl?= =?UTF-8?q?e,=20otherwise=20it=20removes=20the=20parameter=20from=20the=20?= =?UTF-8?q?`params`=20dictionary.=20This=20change=20improves=20the=20handl?= =?UTF-8?q?ing=20of=20optional=20parameters=20and=20makes=20the=20code=20m?= =?UTF-8?q?ore=20maintainable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/base.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 34654b371..66361e48a 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -1,5 +1,6 @@ from langflow.interface.initialize import loading from langflow.interface.listing import ALL_TYPES_DICT +from langflow.utils.constants import DIRECT_TYPES from langflow.utils.logger import logger from langflow.utils.util import sync_to_async @@ -110,11 +111,14 @@ class Vertex: file_path = value.get("file_path") params[key] = file_path - elif ( - value.get("type") in ["code", "str", "prompt"] - and params.get(key) is None - ): + elif value.get("type") in DIRECT_TYPES and params.get(key) is None: params[key] = value.get("value") + + if not value.get("required") and params.get(key) is None: + if value.get("default"): + params[key] = value.get("default") + else: + params.pop(key, None) # Add _type to params self.params = params