🔧 chore(base.py): refactor code to improve readability and handle optional parameters

📝 chore(base.py): update comments and remove unused imports
The code in the `Vertex` class has been refactored to improve readability and handle optional parameters more effectively. The code now checks if a parameter is of type "code", "str", or "prompt" and if it is not already set in the `params` dictionary, it sets it to the corresponding value from the `value` dictionary. Additionally, if a parameter is not required and not set in the `params` dictionary, it checks if a default value is provided and sets it to the default value if available, otherwise it removes the parameter from the `params` dictionary. This change improves the handling of optional parameters and makes the code more maintainable.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-05 17:00:50 -03:00
commit d9891b9c86

View file

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