From c49b764fc004db61a01ad99ad119a9a4a0af2ed8 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 7 Jul 2023 01:34:51 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(utils.py):=20import=20Custom?= =?UTF-8?q?Component=20class=20and=20add=20import=5Fcustom=5Fcomponent=20f?= =?UTF-8?q?unction=20=F0=9F=94=A7=20fix(types.py):=20process=20field=5Ftyp?= =?UTF-8?q?e=20to=20convert=20"Prompt"=20to=20"prompt"=20The=20`utils.py`?= =?UTF-8?q?=20file=20was=20missing=20an=20import=20statement=20for=20the?= =?UTF-8?q?=20`CustomComponent`=20class=20from=20the=20`langflow.interface?= =?UTF-8?q?.custom.custom`=20module.=20This=20import=20statement=20has=20b?= =?UTF-8?q?een=20added=20to=20the=20top=20of=20the=20file.=20Additionally,?= =?UTF-8?q?=20a=20new=20function=20`import=5Fcustom=5Fcomponent`=20has=20b?= =?UTF-8?q?een=20added=20to=20import=20a=20custom=20component=20based=20on?= =?UTF-8?q?=20its=20name.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the `types.py` file, a new function `process_type` has been added to convert the field_type "Prompt" to "prompt". This is done to ensure consistency in the field types used throughout the codebase. --- src/backend/langflow/interface/importing/utils.py | 7 +++++++ src/backend/langflow/interface/types.py | 6 ++++++ 2 files changed, 13 insertions(+) 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", "")