Add ListFlows and RunFlow components
This commit is contained in:
parent
4421c8154d
commit
82bb7dc415
2 changed files with 62 additions and 0 deletions
19
src/backend/langflow/components/utilities/ListFlows.py
Normal file
19
src/backend/langflow/components/utilities/ListFlows.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from langflow import CustomComponent
|
||||||
|
from langflow.schema import Record
|
||||||
|
|
||||||
|
|
||||||
|
class ListFlowsComponent(CustomComponent):
|
||||||
|
display_name = "List Flows"
|
||||||
|
description = "A component to list all available flows."
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def build(
|
||||||
|
self,
|
||||||
|
) -> List[Record]:
|
||||||
|
flows = self.list_flows()
|
||||||
|
self.status = flows
|
||||||
|
return flows
|
||||||
43
src/backend/langflow/components/utilities/RunFlow.py
Normal file
43
src/backend/langflow/components/utilities/RunFlow.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from langflow import CustomComponent
|
||||||
|
from langflow.field_typing import NestedDict, Text
|
||||||
|
from langflow.graph.schema import ResultData
|
||||||
|
from langflow.schema import Record
|
||||||
|
|
||||||
|
|
||||||
|
class RunFlowComponent(CustomComponent):
|
||||||
|
display_name = "Run Flow"
|
||||||
|
description = "A component to run a flow."
|
||||||
|
|
||||||
|
def get_flow_names(self) -> List[str]:
|
||||||
|
flow_records = self.list_flows()
|
||||||
|
return [flow_record.data["name"] for flow_record in flow_records]
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
return {
|
||||||
|
"input_value": {
|
||||||
|
"display_name": "Input Value",
|
||||||
|
"multiline": True,
|
||||||
|
},
|
||||||
|
"flow_id": {
|
||||||
|
"display_name": "Flow ID",
|
||||||
|
"info": "The ID of the flow to run.",
|
||||||
|
"options": self.get_flow_names,
|
||||||
|
},
|
||||||
|
"tweaks": {
|
||||||
|
"display_name": "Tweaks",
|
||||||
|
"info": "Tweaks to apply to the flow.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
async def build(
|
||||||
|
self, input_value: Text, flow_id: str, tweaks: NestedDict
|
||||||
|
) -> Record:
|
||||||
|
input_dict = {"input_value": input_value}
|
||||||
|
result: List[Optional[ResultData]] = await self.run_flow(
|
||||||
|
input_value=input_dict, flow_id=flow_id, tweaks=tweaks
|
||||||
|
)
|
||||||
|
record = Record(data=result)
|
||||||
|
self.status = record
|
||||||
|
return record
|
||||||
Loading…
Add table
Add a link
Reference in a new issue