Update conditional paths in BranchComponent and ShouldRunNext
This commit is contained in:
parent
3fcedc8a07
commit
b450e66046
6 changed files with 36 additions and 13 deletions
|
|
@ -6,11 +6,11 @@ from langflow.schema import Decision
|
||||||
class BranchComponent(CustomComponent):
|
class BranchComponent(CustomComponent):
|
||||||
display_name: str = "Branch Component"
|
display_name: str = "Branch Component"
|
||||||
documentation: str = "http://docs.langflow.org/components/custom"
|
documentation: str = "http://docs.langflow.org/components/custom"
|
||||||
is_conditional = True
|
conditional_paths: list[str] = ["True", "False"]
|
||||||
|
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
return {"param": {"display_name": "Parameter"}}
|
return {"param": {"display_name": "Parameter"}}
|
||||||
|
|
||||||
def build(self, param: Text) -> Text:
|
def build(self, param: Text) -> Text:
|
||||||
|
|
||||||
return Decision(path=True, result=param)
|
return Decision(path="True", result=param)
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,9 @@ class ShouldRunNext(CustomComponent):
|
||||||
)
|
)
|
||||||
# The string should be the words true or false
|
# The string should be the words true or false
|
||||||
# if not raise an error
|
# if not raise an error
|
||||||
bool_result = result.lower() == "true"
|
if result.lower() not in ["true", "false"]:
|
||||||
|
raise ValueError(
|
||||||
|
"The prompt should generate a boolean response (True or False)."
|
||||||
|
)
|
||||||
|
|
||||||
return Decision(path=bool_result, result=kwargs)
|
return Decision(path=result, result=kwargs)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@ def getattr_return_bool(value):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def getattr_return_list_of_str(value):
|
||||||
|
if isinstance(value, list):
|
||||||
|
return [str(val) for val in value]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
ATTR_FUNC_MAPPING: dict[str, Callable] = {
|
ATTR_FUNC_MAPPING: dict[str, Callable] = {
|
||||||
"display_name": getattr_return_str,
|
"display_name": getattr_return_str,
|
||||||
"description": getattr_return_str,
|
"description": getattr_return_str,
|
||||||
|
|
@ -40,5 +46,5 @@ ATTR_FUNC_MAPPING: dict[str, Callable] = {
|
||||||
"pinned": getattr_return_bool,
|
"pinned": getattr_return_bool,
|
||||||
"is_input": getattr_return_bool,
|
"is_input": getattr_return_bool,
|
||||||
"is_output": getattr_return_bool,
|
"is_output": getattr_return_bool,
|
||||||
"is_conditional": getattr_return_bool,
|
"conditional_paths": getattr_return_list_of_str,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,8 @@ class CustomComponent(Component):
|
||||||
"""The selected output type of the component. Defaults to None."""
|
"""The selected output type of the component. Defaults to None."""
|
||||||
vertex: Optional["Vertex"] = None
|
vertex: Optional["Vertex"] = None
|
||||||
"""The edge target parameter of the component. Defaults to None."""
|
"""The edge target parameter of the component. Defaults to None."""
|
||||||
is_conditional: Optional[bool] = False
|
conditional_paths: Optional[List[str]] = None
|
||||||
"""The conditional state of the component. Defaults to False."""
|
"""The conditional paths of the component. Defaults to None."""
|
||||||
code_class_base_inheritance: ClassVar[str] = "CustomComponent"
|
code_class_base_inheritance: ClassVar[str] = "CustomComponent"
|
||||||
function_entrypoint_name: ClassVar[str] = "build"
|
function_entrypoint_name: ClassVar[str] = "build"
|
||||||
function: Optional[Callable] = None
|
function: Optional[Callable] = None
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, field_validator
|
||||||
|
|
||||||
|
|
||||||
class Record(BaseModel):
|
class Record(BaseModel):
|
||||||
|
|
@ -79,9 +79,24 @@ class Decision(BaseModel):
|
||||||
Represents a decision made in the Graph.
|
Represents a decision made in the Graph.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
path (bool): The path taken in the Graph.
|
path (str): The path to take as a result of the decision.
|
||||||
result (dict): The result of the decision.
|
result (dict): The result of the decision.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path: bool
|
path: str
|
||||||
result: Any
|
result: Any
|
||||||
|
|
||||||
|
@field_validator("path")
|
||||||
|
def validate_path(cls, value: str) -> str:
|
||||||
|
"""
|
||||||
|
Validates the path.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (str): The path to validate.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The validated path.
|
||||||
|
"""
|
||||||
|
if isinstance(value, str):
|
||||||
|
return value
|
||||||
|
return str(value)
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,8 @@ class FrontendNode(BaseModel):
|
||||||
"""Field formatters for the frontend node."""
|
"""Field formatters for the frontend node."""
|
||||||
pinned: bool = False
|
pinned: bool = False
|
||||||
"""Whether the frontend node is pinned."""
|
"""Whether the frontend node is pinned."""
|
||||||
is_conditional: bool = False
|
conditional_paths: List[str] = []
|
||||||
"""Whether the frontend node is conditional. This is used for the frontend node to show two output handles."""
|
"""List of conditional paths for the frontend node."""
|
||||||
|
|
||||||
beta: bool = False
|
beta: bool = False
|
||||||
error: Optional[str] = None
|
error: Optional[str] = None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue