Refactor component filtering in DirectoryReader class

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-01-09 10:17:10 -03:00
commit 5677dd9ad3

View file

@ -66,18 +66,18 @@ class DirectoryReader:
def filter_loaded_components(self, data: dict, with_errors: bool) -> dict: def filter_loaded_components(self, data: dict, with_errors: bool) -> dict:
from langflow.interface.custom.utils import build_component from langflow.interface.custom.utils import build_component
items = [ items = []
{ for menu in data["menu"]:
"name": menu["name"], components = []
"path": menu["path"], for component in menu["components"]:
"components": [ try:
(*build_component(component), component) if component["error"] if with_errors else not component["error"]:
for component in menu["components"] component_tuple = (*build_component(component), component)
if (component["error"] if with_errors else not component["error"]) components.append(component_tuple)
], except Exception as e:
} logger.error(f"Error while loading component: {e}")
for menu in data["menu"] continue
] items.append({"name": menu["name"], "path": menu["path"], "components": components})
filtered = [menu for menu in items if menu["components"]] filtered = [menu for menu in items if menu["components"]]
logger.debug(f'Filtered components {"with errors" if with_errors else ""}: {len(filtered)}') logger.debug(f'Filtered components {"with errors" if with_errors else ""}: {len(filtered)}')
return {"menu": filtered} return {"menu": filtered}