Refactor ShouldRunNext component to handle boolean response properly

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-29 23:09:42 -03:00
commit 603bca019c

View file

@ -1,5 +1,6 @@
# Implement ShouldRunNext component # Implement ShouldRunNext component
from typing import Text from typing import Text
from langchain_core.prompts import PromptTemplate from langchain_core.prompts import PromptTemplate
from langflow import CustomComponent from langflow import CustomComponent
@ -42,8 +43,10 @@ class ShouldRunNext(CustomComponent):
result = result.get("response") result = result.get("response")
if result.lower() not in ["true", "false"]: if result.lower() not in ["true", "false"]:
raise ValueError("The prompt should generate a boolean response (True or False).") raise ValueError(
"The prompt should generate a boolean response (True or False)."
)
# 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 {"condition": bool_result, "result": kwargs} return {"path": bool_result, "result": kwargs}