From 6732cf94f69a5b6231e746c648e69d71c3cadc0a Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Tue, 28 May 2024 23:04:37 -0300 Subject: [PATCH] feat: Add Decision class to langflow schema --- src/backend/base/langflow/schema/__init__.py | 3 +- src/backend/base/langflow/schema/decision.py | 30 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/backend/base/langflow/schema/decision.py diff --git a/src/backend/base/langflow/schema/__init__.py b/src/backend/base/langflow/schema/__init__.py index 14230578c..9c374a730 100644 --- a/src/backend/base/langflow/schema/__init__.py +++ b/src/backend/base/langflow/schema/__init__.py @@ -1,4 +1,5 @@ from .dotdict import dotdict from .schema import Record +from .decision import Decision -__all__ = ["Record", "dotdict"] +__all__ = ["Record", "dotdict", "Decision"] diff --git a/src/backend/base/langflow/schema/decision.py b/src/backend/base/langflow/schema/decision.py new file mode 100644 index 000000000..bb4f0206b --- /dev/null +++ b/src/backend/base/langflow/schema/decision.py @@ -0,0 +1,30 @@ +from pydantic import field_validator, BaseModel +from typing import Any + + +class Decision(BaseModel): + """ + Represents a decision made in the Graph. + + Attributes: + path (str): The path to take as a result of the decision. + result (dict): The result of the decision. + """ + + path: str + 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)