Add Decision class for decision making components
This commit is contained in:
parent
ef78b5eeb6
commit
ba93c25ff4
3 changed files with 23 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langflow.field_typing import Text
|
from langflow.field_typing import Text
|
||||||
|
from langflow.schema import Decision
|
||||||
|
|
||||||
|
|
||||||
class BranchComponent(CustomComponent):
|
class BranchComponent(CustomComponent):
|
||||||
|
|
@ -11,4 +12,5 @@ class BranchComponent(CustomComponent):
|
||||||
return {"param": {"display_name": "Parameter"}}
|
return {"param": {"display_name": "Parameter"}}
|
||||||
|
|
||||||
def build(self, param: Text) -> Text:
|
def build(self, param: Text) -> Text:
|
||||||
return {"path": True, "result": param}
|
|
||||||
|
return Decision(path=True, result=param)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ from langchain_core.prompts import PromptTemplate
|
||||||
|
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langflow.field_typing import BaseLanguageModel, Prompt
|
from langflow.field_typing import BaseLanguageModel, Prompt
|
||||||
|
from langflow.schema import Decision
|
||||||
|
|
||||||
|
|
||||||
class ShouldRunNext(CustomComponent):
|
class ShouldRunNext(CustomComponent):
|
||||||
|
|
@ -49,4 +50,5 @@ 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"
|
bool_result = result.lower() == "true"
|
||||||
return {"path": bool_result, "result": kwargs}
|
|
||||||
|
return Decision(path=bool_result, result=kwargs)
|
||||||
|
|
|
||||||
|
|
@ -68,3 +68,20 @@ def docs_to_records(documents: list[Document]) -> list[Record]:
|
||||||
list[Record]: The converted list of Records.
|
list[Record]: The converted list of Records.
|
||||||
"""
|
"""
|
||||||
return [Record.from_document(document) for document in documents]
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue