Skip to content

Commit

Permalink
fix: refactor FlowTool to use run_until_complete for async flow execu…
Browse files Browse the repository at this point in the history
…tion (#3845)

Refactor `FlowTool` to use `run_until_complete` for async flow execution
  • Loading branch information
ogabrielluiz authored Sep 19, 2024
1 parent aaa5cef commit 4a51830
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/backend/base/langflow/base/tools/flow_tool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, List, Optional, Type

from asyncer import syncify
from langchain_core.runnables import RunnableConfig
from langchain_core.tools import BaseTool, ToolException
from pydantic.v1 import BaseModel
Expand All @@ -9,6 +8,7 @@
from langflow.graph.graph.base import Graph
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.utils.async_helpers import run_until_complete


class FlowTool(BaseTool):
Expand Down Expand Up @@ -49,10 +49,12 @@ def _run(
)
tweaks = {arg["component_name"]: kwargs[arg["arg_name"]] for arg in args_names}

run_outputs = syncify(run_flow, raise_sync_error=False)(
tweaks={key: {"input_value": value} for key, value in tweaks.items()},
flow_id=self.flow_id,
user_id=self.user_id,
run_outputs = run_until_complete(
run_flow(
tweaks={key: {"input_value": value} for key, value in tweaks.items()},
flow_id=self.flow_id,
user_id=self.user_id,
)
)
if not run_outputs:
return "No output"
Expand Down

0 comments on commit 4a51830

Please sign in to comment.