🔀 refactor(custom_component.py): rename load_flow method parameter flow_id to graph_id for clarity

🔀 refactor(custom_component.py): add optional `tweaks` parameter to `load_flow` method to allow for processing tweaks on the graph data
🔀 refactor(custom_component.py): rename `data_graph` variable to `graph_data` for consistency and clarity
🔀 refactor(custom_component.py): add logic to process tweaks on the `graph_data` if `tweaks` parameter is provided
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-27 09:39:27 -03:00
commit 2b55b0c3b3

View file

@ -141,14 +141,17 @@ class CustomComponent(Component, extra=Extra.allow):
def get_function(self):
return validate.create_function(self.code, self.function_entrypoint_name)
def load_flow(self, flow_id: str):
def load_flow(self, flow_id: str, tweaks: Optional[dict] = None):
from langflow.processing.process import build_sorted_vertices_with_caching
from langflow.processing.process import process_tweaks
with session_getter() as session:
data_graph = flow.data if (flow := session.get(Flow, flow_id)) else None
if not data_graph:
graph_data = flow.data if (flow := session.get(Flow, flow_id)) else None
if not graph_data:
raise ValueError(f"Flow {flow_id} not found")
return build_sorted_vertices_with_caching(data_graph)
if tweaks:
graph_data = process_tweaks(graph_data=graph_data, tweaks=tweaks)
return build_sorted_vertices_with_caching(graph_data)
def list_flows(self):
with session_getter() as session: