fix: add run_id parameter to set run ID in graph and handle exceptions in FlowTool (#3855)
* Add run_id setting to FlowTool with warning on failure * feat: Add try-except block to set run_id in FlowTool The try-except block is added to handle any exceptions that may occur when setting the run_id in the FlowTool class. If an exception occurs, a warning is issued and the run_id is set to None. This ensures that the code does not break if there is an error in setting the run_id.
This commit is contained in:
parent
4a518307b7
commit
667713f6c0
2 changed files with 11 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import warnings
|
||||||
from typing import Any, List, Optional, Type
|
from typing import Any, List, Optional, Type
|
||||||
|
|
||||||
from langchain_core.runnables import RunnableConfig
|
from langchain_core.runnables import RunnableConfig
|
||||||
|
|
@ -97,7 +98,11 @@ class FlowTool(BaseTool):
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Use the tool asynchronously."""
|
"""Use the tool asynchronously."""
|
||||||
tweaks = self.build_tweaks_dict(args, kwargs)
|
tweaks = self.build_tweaks_dict(args, kwargs)
|
||||||
run_id = self.graph.run_id if self.graph else None
|
try:
|
||||||
|
run_id = self.graph.run_id if self.graph else None
|
||||||
|
except Exception as e:
|
||||||
|
warnings.warn(f"Failed to set run_id: {e}")
|
||||||
|
run_id = None
|
||||||
run_outputs = await run_flow(
|
run_outputs = await 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,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import warnings
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from langflow.base.langchain_utilities.model import LCToolComponent
|
from langflow.base.langchain_utilities.model import LCToolComponent
|
||||||
|
|
@ -79,6 +80,10 @@ class FlowToolComponent(LCToolComponent):
|
||||||
if not flow_data:
|
if not flow_data:
|
||||||
raise ValueError("Flow not found.")
|
raise ValueError("Flow not found.")
|
||||||
graph = Graph.from_payload(flow_data.data["data"])
|
graph = Graph.from_payload(flow_data.data["data"])
|
||||||
|
try:
|
||||||
|
graph.set_run_id(self.graph.run_id)
|
||||||
|
except Exception as e:
|
||||||
|
warnings.warn(f"Failed to set run_id: {e}")
|
||||||
inputs = get_flow_inputs(graph)
|
inputs = get_flow_inputs(graph)
|
||||||
tool = FlowTool(
|
tool = FlowTool(
|
||||||
name=self.name,
|
name=self.name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue