🔧 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:
parent
8b3fe49e51
commit
2513cbcdd9
1 changed files with 9 additions and 0 deletions
|
|
@ -5,6 +5,12 @@ from langflow.interface.custom.component import Component
|
||||||
|
|
||||||
from langflow.utils import validate
|
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):
|
class CustomComponent(Component):
|
||||||
code: Optional[str]
|
code: Optional[str]
|
||||||
|
|
@ -126,5 +132,8 @@ class CustomComponent(Component):
|
||||||
def get_function(self):
|
def get_function(self):
|
||||||
return validate.create_function(self.code, self.function_entrypoint_name)
|
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):
|
def build(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue