From 2e0de1926e933e4123fc0e8626261768ecfc527c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 10 Aug 2023 17:59:30 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(endpoints.py):=20handle=20du?= =?UTF-8?q?plicate=20paths=20in=20settings.COMPONENTS=5FPATH=20to=20avoid?= =?UTF-8?q?=20processing=20the=20same=20path=20multiple=20times=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(settings.py):=20convert=20Path=20objects=20t?= =?UTF-8?q?o=20strings=20in=20settings.COMPONENTS=5FPATH=20to=20ensure=20c?= =?UTF-8?q?onsistency=20and=20avoid=20potential=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/endpoints.py | 16 ++++++++++++---- src/backend/langflow/settings.py | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/api/v1/endpoints.py b/src/backend/langflow/api/v1/endpoints.py index 24af55588..de8c69338 100644 --- a/src/backend/langflow/api/v1/endpoints.py +++ b/src/backend/langflow/api/v1/endpoints.py @@ -42,10 +42,18 @@ def get_all(): custom_components_from_file = {} if settings.COMPONENTS_PATH: logger.info(f"Building custom components from {settings.COMPONENTS_PATH}") - custom_component_dicts = [ - build_langchain_custom_component_list_from_path(str(path)) - for path in settings.COMPONENTS_PATH - ] + + custom_component_dicts = [] + processed_paths = [] + for path in settings.COMPONENTS_PATH: + if path in processed_paths: + continue + custom_component_dict = build_langchain_custom_component_list_from_path( + str(path) + ) + custom_component_dicts.append(custom_component_dict) + processed_paths.append(str(path)) + logger.info(f"Loading {len(custom_component_dicts)} category(ies)") for custom_component_dict in custom_component_dicts: # custom_component_dict is a dict of dicts diff --git a/src/backend/langflow/settings.py b/src/backend/langflow/settings.py index 439b3a1e4..5bbc02f51 100644 --- a/src/backend/langflow/settings.py +++ b/src/backend/langflow/settings.py @@ -129,6 +129,8 @@ class Settings(BaseSettings): value = json.loads(str(value)) if isinstance(value, list): for item in value: + if isinstance(item, Path): + item = str(item) if item not in getattr(self, key): getattr(self, key).append(item) logger.debug(f"Extended {key}")