🔧 chore(custom_component.py): reformat code for better readability and maintainability

🚀 feat(custom_component.py): add `load_flow` method to load a flow from the database using session and flow_id
This commit is contained in:
gustavoschaedler 2023-07-20 18:35:53 +01:00
commit 2513cbcdd9

View file

@ -5,6 +5,12 @@ from langflow.interface.custom.component import Component
from langflow.utils import validate
from uuid import UUID
from sqlmodel import Session
from fastapi import Depends, HTTPException
from langflow.database.base import get_session
from langflow.database.models.flow import Flow
class CustomComponent(Component):
code: Optional[str]
@ -126,5 +132,8 @@ class CustomComponent(Component):
def get_function(self):
return validate.create_function(self.code, self.function_entrypoint_name)
def load_flow(self, session: Session = Depends(get_session), flow_id: UUID = None):
return flow if (flow := session.get(Flow, flow_id)) else "Flow not found"
def build(self):
raise NotImplementedError