🔀 refactor(process.py): rename build_langchain_object_with_caching to build_sorted_vertices_with_caching for better clarity

🐛 fix(process.py): handle missing inputs in process_graph_cached function
The function `build_langchain_object_with_caching` has been renamed to `build_sorted_vertices_with_caching` to provide a more descriptive name that accurately reflects its purpose. Additionally, the `process_graph_cached` function now handles cases where the `inputs` parameter is missing or empty by populating it with values from the `artifacts` dictionary. This ensures that all required inputs are properly set before running the graph.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-29 22:49:32 -03:00
commit af84dd2c68

View file

@ -2,7 +2,7 @@ from pathlib import Path
from langchain.schema import AgentAction
import json
from langflow.interface.run import (
build_langchain_object_with_caching,
build_sorted_vertices_with_caching,
get_memory_key,
update_memory_keys,
)
@ -88,8 +88,16 @@ def process_graph_cached(data_graph: Dict[str, Any], inputs: Optional[dict] = No
with PromptTemplate,then run the graph and return the result and thought.
"""
# Load langchain object
langchain_object = build_langchain_object_with_caching(data_graph)
langchain_object, artifacts = build_sorted_vertices_with_caching(data_graph)
logger.debug("Loaded LangChain object")
if inputs is None:
inputs = {}
for (
key,
value,
) in artifacts.items():
if key not in inputs or not inputs[key]:
inputs[key] = value
if langchain_object is None:
# Raise user facing error