🔧 fix(utils.py): import CustomComponent class and add import_custom_component function
🔧 fix(types.py): process field_type to convert "Prompt" to "prompt"
The `utils.py` file was missing an import statement for the `CustomComponent` class from the `langflow.interface.custom.custom` module. This import statement has been added to the top of the file. Additionally, a new function `import_custom_component` has been added to import a custom component based on its name.
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.
This commit is contained in:
parent
99bc9f01ba
commit
c49b764fc0
2 changed files with 13 additions and 0 deletions
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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", "")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue