fix: refactor FlowTool to use run_until_complete for async flow execution (#3845)
Refactor `FlowTool` to use `run_until_complete` for async flow execution
This commit is contained in:
parent
aaa5cef20a
commit
4a518307b7
1 changed files with 7 additions and 5 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
from typing import Any, List, Optional, Type
|
from typing import Any, List, Optional, Type
|
||||||
|
|
||||||
from asyncer import syncify
|
|
||||||
from langchain_core.runnables import RunnableConfig
|
from langchain_core.runnables import RunnableConfig
|
||||||
from langchain_core.tools import BaseTool, ToolException
|
from langchain_core.tools import BaseTool, ToolException
|
||||||
from pydantic.v1 import BaseModel
|
from pydantic.v1 import BaseModel
|
||||||
|
|
@ -9,6 +8,7 @@ from langflow.base.flow_processing.utils import build_data_from_result_data, for
|
||||||
from langflow.graph.graph.base import Graph
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.graph.vertex.base import Vertex
|
from langflow.graph.vertex.base import Vertex
|
||||||
from langflow.helpers.flow import build_schema_from_inputs, get_arg_names, get_flow_inputs, run_flow
|
from langflow.helpers.flow import build_schema_from_inputs, get_arg_names, get_flow_inputs, run_flow
|
||||||
|
from langflow.utils.async_helpers import run_until_complete
|
||||||
|
|
||||||
|
|
||||||
class FlowTool(BaseTool):
|
class FlowTool(BaseTool):
|
||||||
|
|
@ -49,11 +49,13 @@ class FlowTool(BaseTool):
|
||||||
)
|
)
|
||||||
tweaks = {arg["component_name"]: kwargs[arg["arg_name"]] for arg in args_names}
|
tweaks = {arg["component_name"]: kwargs[arg["arg_name"]] for arg in args_names}
|
||||||
|
|
||||||
run_outputs = syncify(run_flow, raise_sync_error=False)(
|
run_outputs = run_until_complete(
|
||||||
|
run_flow(
|
||||||
tweaks={key: {"input_value": value} for key, value in tweaks.items()},
|
tweaks={key: {"input_value": value} for key, value in tweaks.items()},
|
||||||
flow_id=self.flow_id,
|
flow_id=self.flow_id,
|
||||||
user_id=self.user_id,
|
user_id=self.user_id,
|
||||||
)
|
)
|
||||||
|
)
|
||||||
if not run_outputs:
|
if not run_outputs:
|
||||||
return "No output"
|
return "No output"
|
||||||
run_output = run_outputs[0]
|
run_output = run_outputs[0]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue