diff --git a/src/backend/langflow/interface/importing/utils.py b/src/backend/langflow/interface/importing/utils.py index 5c40ed34c..bfcd18caa 100644 --- a/src/backend/langflow/interface/importing/utils.py +++ b/src/backend/langflow/interface/importing/utils.py @@ -9,6 +9,7 @@ from langchain.base_language import BaseLanguageModel from langchain.chains.base import Chain from langchain.chat_models.base import BaseChatModel from langchain.tools import BaseTool +from langflow.interface.custom.custom import CustomComponent from langflow.utils import validate @@ -46,6 +47,7 @@ def import_by_type(_type: str, name: str) -> Any: "utilities": import_utility, "output_parsers": import_output_parser, "retrievers": import_retriever, + "custom_components": import_custom_component, } if _type == "llms": key = "chat" if "chat" in name.lower() else "llm" @@ -56,6 +58,11 @@ def import_by_type(_type: str, name: str) -> Any: return loaded_func(name) +def import_custom_component(custom_component: str) -> CustomComponent: + """Import custom component from custom component name""" + return import_class(f"langflow.interface.custom.custom.{custom_component}") + + def import_output_parser(output_parser: str) -> Any: """Import output parser from output parser name""" return import_module(f"from langchain.output_parsers import {output_parser}") diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index f9d4f72ba..9b8b8cebe 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -72,6 +72,10 @@ def build_langchain_types_dict(): # sourcery skip: dict-assign-update-to-union return all_types +def process_type(field_type: str): + return "prompt" if field_type == "Prompt" else field_type + + # TODO: Move to correct place def add_new_custom_field( template, field_name: str, field_type: str, field_config: dict @@ -80,6 +84,8 @@ def add_new_custom_field( # if it is, update the value name = field_config.pop("name", field_name) field_type = field_config.pop("field_type", field_type) + field_type = process_type(field_type) + required = field_config.pop("required", True) placeholder = field_config.pop("placeholder", "")