Refactor directory_reader utils.py
This commit is contained in:
parent
5c210f609e
commit
8aaa0ee91a
1 changed files with 21 additions and 8 deletions
|
|
@ -1,11 +1,18 @@
|
||||||
from langflow.interface.custom.directory_reader import DirectoryReader
|
|
||||||
from langflow.template.frontend_node.custom_components import CustomComponentFrontendNode
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
from langflow.interface.custom.directory_reader import DirectoryReader
|
||||||
|
from langflow.template.frontend_node.custom_components import (
|
||||||
|
CustomComponentFrontendNode,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def merge_nested_dicts_with_renaming(dict1, dict2):
|
def merge_nested_dicts_with_renaming(dict1, dict2):
|
||||||
for key, value in dict2.items():
|
for key, value in dict2.items():
|
||||||
if key in dict1 and isinstance(value, dict) and isinstance(dict1.get(key), dict):
|
if (
|
||||||
|
key in dict1
|
||||||
|
and isinstance(value, dict)
|
||||||
|
and isinstance(dict1.get(key), dict)
|
||||||
|
):
|
||||||
for sub_key, sub_value in value.items():
|
for sub_key, sub_value in value.items():
|
||||||
# if sub_key in dict1[key]:
|
# if sub_key in dict1[key]:
|
||||||
# new_key = get_new_key(dict1[key], sub_key)
|
# new_key = get_new_key(dict1[key], sub_key)
|
||||||
|
|
@ -62,7 +69,9 @@ def build_custom_component_list_from_path(path: str):
|
||||||
file_list = load_files_from_path(path)
|
file_list = load_files_from_path(path)
|
||||||
reader = DirectoryReader(path, False)
|
reader = DirectoryReader(path, False)
|
||||||
|
|
||||||
valid_components, invalid_components = build_and_validate_all_files(reader, file_list)
|
valid_components, invalid_components = build_and_validate_all_files(
|
||||||
|
reader, file_list
|
||||||
|
)
|
||||||
|
|
||||||
valid_menu = build_valid_menu(valid_components)
|
valid_menu = build_valid_menu(valid_components)
|
||||||
invalid_menu = build_invalid_menu(invalid_components)
|
invalid_menu = build_invalid_menu(invalid_components)
|
||||||
|
|
@ -109,7 +118,9 @@ def build_invalid_menu_items(menu_item):
|
||||||
menu_items[component_name] = component_template
|
menu_items[component_name] = component_template
|
||||||
logger.debug(f"Added {component_name} to invalid menu.")
|
logger.debug(f"Added {component_name} to invalid menu.")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.exception(f"Error while creating custom component [{component_name}]: {str(exc)}")
|
logger.exception(
|
||||||
|
f"Error while creating custom component [{component_name}]: {str(exc)}"
|
||||||
|
)
|
||||||
return menu_items
|
return menu_items
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -136,12 +147,14 @@ def determine_component_name(component):
|
||||||
def build_menu_items(menu_item):
|
def build_menu_items(menu_item):
|
||||||
"""Build menu items for a given menu."""
|
"""Build menu items for a given menu."""
|
||||||
menu_items = {}
|
menu_items = {}
|
||||||
|
logger.debug(f"Building menu items for {menu_item['name']}")
|
||||||
|
logger.debug(f"Loading {len(menu_item['components'])} components")
|
||||||
for component_name, component_template, component in menu_item["components"]:
|
for component_name, component_template, component in menu_item["components"]:
|
||||||
try:
|
try:
|
||||||
menu_items[component_name] = component_template
|
menu_items[component_name] = component_template
|
||||||
logger.debug(f"Added {component_name} to valid menu.")
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error(f"Error loading Component: {component['output_types']}")
|
logger.error(f"Error loading Component: {component['output_types']}")
|
||||||
logger.exception(f"Error while building custom component {component['output_types']}: {exc}")
|
logger.exception(
|
||||||
return menu_items
|
f"Error while building custom component {component['output_types']}: {exc}"
|
||||||
|
)
|
||||||
return menu_items
|
return menu_items
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue