✨ feat(custom): add custom component interface and base classes
🔧 chore(custom): create a custom component creator class to handle custom component creation and loading
The commit adds two new files: `__init__.py` and `base.py` under the `src/backend/langflow/interface/custom` directory. The `__init__.py` file imports the `CustomComponentCreator` and `CustomComponent` classes from the `base.py` file. The `base.py` file defines the `CustomComponentCreator` class, which is responsible for creating and loading custom components. It also includes necessary imports and a `CustomComponentFrontendNode` class.
The addition of these files is necessary to support custom components in the application. The `CustomComponentCreator` class provides a way to create and load custom components, and the `CustomComponent` class represents a custom component. This allows for the dynamic creation and usage of custom components in the application.
This commit is contained in:
parent
5e4507852c
commit
692994f100
2 changed files with 47 additions and 0 deletions
4
src/backend/langflow/interface/custom/__init__.py
Normal file
4
src/backend/langflow/interface/custom/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
from langflow.interface.custom.base import CustomComponentCreator
|
||||||
|
from langflow.interface.custom.custom import CustomComponent
|
||||||
|
|
||||||
|
__all__ = ["CustomComponentCreator", "CustomComponent"]
|
||||||
43
src/backend/langflow/interface/custom/base.py
Normal file
43
src/backend/langflow/interface/custom/base.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
from typing import Any, Dict, List, Optional, Type
|
||||||
|
|
||||||
|
from langflow.custom.customs import get_custom_nodes
|
||||||
|
from langflow.interface.base import LangChainTypeCreator
|
||||||
|
from langflow.interface.custom.custom import CustomComponent
|
||||||
|
from langflow.template.frontend_node.custom_components import (
|
||||||
|
CustomComponentFrontendNode,
|
||||||
|
)
|
||||||
|
from langflow.utils.logger import logger
|
||||||
|
|
||||||
|
# Assuming necessary imports for Field, Template, and FrontendNode classes
|
||||||
|
|
||||||
|
|
||||||
|
class CustomComponentCreator(LangChainTypeCreator):
|
||||||
|
type_name: str = "custom_components"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def frontend_node_class(self) -> Type[CustomComponentFrontendNode]:
|
||||||
|
return CustomComponentFrontendNode
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type_to_loader_dict(self) -> Dict:
|
||||||
|
if self.type_dict is None:
|
||||||
|
self.type_dict: dict[str, Any] = {
|
||||||
|
"CustomComponent": CustomComponent,
|
||||||
|
}
|
||||||
|
return self.type_dict
|
||||||
|
|
||||||
|
def get_signature(self, name: str) -> Optional[Dict]:
|
||||||
|
try:
|
||||||
|
if name in get_custom_nodes(self.type_name).keys():
|
||||||
|
return get_custom_nodes(self.type_name)[name]
|
||||||
|
except ValueError as exc:
|
||||||
|
raise ValueError(f"CustomComponent {name} not found: {exc}") from exc
|
||||||
|
except AttributeError as exc:
|
||||||
|
logger.error(f"CustomComponent {name} not loaded: {exc}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def to_list(self) -> List[str]:
|
||||||
|
return list(self.type_to_loader_dict.keys())
|
||||||
|
|
||||||
|
|
||||||
|
custom_component_creator = CustomComponentCreator()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue