refactor(run.py): remove unused process_graph function

refactor(test_graph.py): update get_result_and_steps to get_result_and_thought function name
This commit is contained in:
Gabriel Almeida 2023-05-10 11:31:06 -03:00
commit 31062f2a8c
2 changed files with 2 additions and 36 deletions

View file

@ -67,40 +67,6 @@ def build_langchain_object(data_graph):
return graph.build()
def process_graph(data_graph: Dict[str, Any]):
"""
Process graph by extracting input variables and replacing ZeroShotPrompt
with PromptTemplate,then run the graph and return the result and thought.
"""
# Load langchain object
logger.debug("Loading langchain object")
message = data_graph.pop("message", "")
is_first_message = len(data_graph.get("chatHistory", [])) == 0
computed_hash, langchain_object = load_langchain_object(
data_graph, is_first_message
)
logger.debug("Loaded langchain object")
if langchain_object is None:
# Raise user facing error
raise ValueError(
"There was an error loading the langchain_object. Please, check all the nodes and try again."
)
# Generate result and thought
logger.debug("Generating result and thought")
result, thought = get_result_and_steps(langchain_object, message)
logger.debug("Generated result and thought")
# Save langchain_object to cache
# We have to save it here because if the
# memory is updated we need to keep the new values
logger.debug("Saving langchain object to cache")
# save_cache(computed_hash, langchain_object, is_first_message)
logger.debug("Saved langchain object to cache")
return {"result": str(result), "thought": thought.strip()}
def process_graph_cached(data_graph: Dict[str, Any], message: str):
"""
Process graph by extracting input variables and replacing ZeroShotPrompt

View file

@ -14,7 +14,7 @@ from langflow.graph.nodes import (
ToolNode,
WrapperNode,
)
from langflow.interface.run import get_result_and_steps
from langflow.interface.run import get_result_and_thought
from langflow.utils.payload import get_root_node
# Test cases for the graph module
@ -335,7 +335,7 @@ def test_get_result_and_thought(basic_graph):
# now build again and check if FakeListLLM was used
# Get the result and thought
result, thought = get_result_and_steps(langchain_object, message)
result, thought = get_result_and_thought(langchain_object, message)
# The result should be a str
assert isinstance(result, str)
# The thought should be a Thought