Add custom component classes and methods

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-12-14 09:32:45 -03:00
commit e7e364be38
3 changed files with 10 additions and 7 deletions

View file

@ -0,0 +1,3 @@
from .custom_component import CustomComponent
__all__ = ["CustomComponent"]

View file

@ -1,22 +1,21 @@
import operator import operator
from typing import Any, Callable, ClassVar, List, Optional, Union from typing import Any, Callable, ClassVar, List, Optional, Union
from uuid import UUID from uuid import UUID
from langflow.interface.custom.code_parser.utils import extract_inner_type_from_generic_alias
import yaml import yaml
from cachetools import TTLCache, cachedmethod from cachetools import TTLCache, cachedmethod
from fastapi import HTTPException from fastapi import HTTPException
from langflow.interface.custom.component import Component
from langflow.interface.custom.directory_reader import DirectoryReader
from langflow.interface.custom.code_parser.utils import ( from langflow.interface.custom.code_parser.utils import (
extract_union_types_from_generic_alias, extract_inner_type_from_generic_alias,
) extract_union_types_from_generic_alias)
from langflow.interface.custom.directory_reader import DirectoryReader
from langflow.services.database.models.flow import Flow from langflow.services.database.models.flow import Flow
from langflow.services.database.utils import session_getter from langflow.services.database.utils import session_getter
from langflow.services.deps import get_credential_service, get_db_service from langflow.services.deps import get_credential_service, get_db_service
from langflow.utils import validate from langflow.utils import validate
from .component import Component
class CustomComponent(Component): class CustomComponent(Component):
display_name: Optional[str] = None display_name: Optional[str] = None
@ -218,7 +217,8 @@ class CustomComponent(Component):
return validate.create_function(self.code, self.function_entrypoint_name) return validate.create_function(self.code, self.function_entrypoint_name)
async def load_flow(self, flow_id: str, tweaks: Optional[dict] = None) -> Any: async def load_flow(self, flow_id: str, tweaks: Optional[dict] = None) -> Any:
from langflow.processing.process import build_sorted_vertices, process_tweaks from langflow.processing.process import (build_sorted_vertices,
process_tweaks)
db_service = get_db_service() db_service = get_db_service()
with session_getter(db_service) as session: with session_getter(db_service) as session: