Add Decision class for decision making components

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-29 23:16:45 -03:00
commit ba93c25ff4
3 changed files with 23 additions and 2 deletions

View file

@ -1,5 +1,6 @@
from langflow import CustomComponent
from langflow.field_typing import Text
from langflow.schema import Decision
class BranchComponent(CustomComponent):
@ -11,4 +12,5 @@ class BranchComponent(CustomComponent):
return {"param": {"display_name": "Parameter"}}
def build(self, param: Text) -> Text:
return {"path": True, "result": param}
return Decision(path=True, result=param)

View file

@ -5,6 +5,7 @@ from langchain_core.prompts import PromptTemplate
from langflow import CustomComponent
from langflow.field_typing import BaseLanguageModel, Prompt
from langflow.schema import Decision
class ShouldRunNext(CustomComponent):
@ -49,4 +50,5 @@ class ShouldRunNext(CustomComponent):
# The string should be the words true or false
# if not raise an error
bool_result = result.lower() == "true"
return {"path": bool_result, "result": kwargs}
return Decision(path=bool_result, result=kwargs)

View file

@ -68,3 +68,20 @@ def docs_to_records(documents: list[Document]) -> list[Record]:
list[Record]: The converted list of Records.
"""
return [Record.from_document(document) for document in documents]
# {"path": bool_result, "result": kwargs}
# Create a class for the above dictionary
# with a good name that fits the context of
# a decision making component
class Decision(BaseModel):
"""
Represents a decision made in the Graph.
Attributes:
path (bool): The path taken in the Graph.
result (dict): The result of the decision.
"""
path: bool
result: Any