fix: validate flow_name presence in flow components before retrieving flow data (#3218)

* refactor: handle Data type in Vertex class

The code changes in `base.py` modify the `Vertex` class to handle the `Data` type. Specifically, it adds a condition to check if the value is an instance of `Data` and then unescapes the string using `val.get_text()`. This change improves the functionality and data management in the `Vertex` class.

* fix: skip artifacts without text in ComponentVertex processing

Added a check to continue if the message_dict does not have a "text" field in the ComponentVertex class

* fix: retrieve flow_name from attributes in SubFlowComponent

Updated SubFlowComponent to ensure flow_name is fetched correctly from attributes before execution

* fix: validate flow_name presence in RunFlowComponent before execution

Added a conditional check to ensure flow_name is provided in attributes

* fix: validate flow_name presence in FlowToolComponent before retrieving flow data

Added check to ensure flow_name is provided in attributes
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-08-07 10:33:27 -03:00 • committed by GitHub
commit d44505f589
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 6 deletions

View file

@ -1,12 +1,11 @@
from typing import Any, List, Optional
from langflow.base.langchain_utilities.model import LCToolComponent
from langflow.base.tools.flow_tool import FlowTool
from langflow.field_typing import Tool
from langflow.graph.graph.base import Graph
from langflow.helpers.flow import get_flow_inputs
from langflow.io import BoolInput, DropdownInput, StrInput, Output
from langflow.io import BoolInput, DropdownInput, Output, StrInput
from langflow.schema import Data
from langflow.schema.dotdict import dotdict
@ -73,7 +72,10 @@ class FlowToolComponent(LCToolComponent):
def build_tool(self) -> Tool:
FlowTool.update_forward_refs()
flow_data = self.get_flow(self.flow_name)
if "flow_name" not in self._attributes or not self._attributes["flow_name"]:
raise ValueError("Flow name is required")
flow_name = self._attributes["flow_name"]
flow_data = self.get_flow(flow_name)
if not flow_data:
raise ValueError("Flow not found.")
graph = Graph.from_payload(flow_data.data["data"])

View file

@ -48,8 +48,12 @@ class RunFlowComponent(Component):
]
async def generate_results(self) -> List[Data]:
if "flow_name" not in self._attributes or not self._attributes["flow_name"]:
raise ValueError("Flow name is required")
flow_name = self._attributes["flow_name"]
results: List[Optional[RunOutputs]] = await self.run_flow(
inputs={"input_value": self.input_value}, flow_name=self.flow_name, tweaks=self.tweaks
inputs={"input_value": self.input_value}, flow_name=flow_name, tweaks=self.tweaks
)
if isinstance(results, list):
data = []

View file

@ -89,10 +89,10 @@ class SubFlowComponent(Component):
if node not in tweaks.keys():
tweaks[node] = {}
tweaks[node][name] = self._attributes[field]
flow_name = self._attributes.get("flow_name")
run_outputs = await self.run_flow(
tweaks=tweaks,
flow_name=self.flow_name,
flow_name=flow_name,
output_type="all",
)
data: list[Data] = []

View file

@ -383,6 +383,8 @@ class Vertex:
params[field_name] = [unescape_string(v) for v in val]
elif isinstance(val, str):
params[field_name] = unescape_string(val)
elif isinstance(val, Data):
params[field_name] = unescape_string(val.get_text())
elif field.get("type") == "bool" and val is not None:
if isinstance(val, bool):
params[field_name] = val

View file

@ -138,6 +138,8 @@ class ComponentVertex(Vertex):
) and not isinstance(artifact, Message):
continue
message_dict = artifact if isinstance(artifact, dict) else artifact.model_dump()
if not message_dict.get("text"):
continue
try:
messages.append(
ChatOutputResponse(