Merge branch 'form_io' of github.com:logspace-ai/langflow into form_io
This commit is contained in:
commit
91fc931081
2 changed files with 27 additions and 2 deletions
|
|
@ -14,6 +14,23 @@ def build_langchain_object_with_caching(data_graph):
|
||||||
return graph.build()
|
return graph.build()
|
||||||
|
|
||||||
|
|
||||||
|
@memoize_dict(maxsize=10)
|
||||||
|
def build_sorted_vertices_with_caching(data_graph):
|
||||||
|
"""
|
||||||
|
Build langchain object from data_graph.
|
||||||
|
"""
|
||||||
|
|
||||||
|
logger.debug("Building langchain object")
|
||||||
|
graph = Graph.from_payload(data_graph)
|
||||||
|
sorted_vertices = graph.topological_sort()
|
||||||
|
artifacts = {}
|
||||||
|
for vertex in sorted_vertices:
|
||||||
|
vertex.build()
|
||||||
|
if vertex.artifacts:
|
||||||
|
artifacts.update(vertex.artifacts)
|
||||||
|
return graph.build(), artifacts
|
||||||
|
|
||||||
|
|
||||||
def build_langchain_object(data_graph):
|
def build_langchain_object(data_graph):
|
||||||
"""
|
"""
|
||||||
Build langchain object from data_graph.
|
Build langchain object from data_graph.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
||||||
from langchain.schema import AgentAction
|
from langchain.schema import AgentAction
|
||||||
import json
|
import json
|
||||||
from langflow.interface.run import (
|
from langflow.interface.run import (
|
||||||
build_langchain_object_with_caching,
|
build_sorted_vertices_with_caching,
|
||||||
get_memory_key,
|
get_memory_key,
|
||||||
update_memory_keys,
|
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.
|
with PromptTemplate,then run the graph and return the result and thought.
|
||||||
"""
|
"""
|
||||||
# Load langchain object
|
# 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")
|
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:
|
if langchain_object is None:
|
||||||
# Raise user facing error
|
# Raise user facing error
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue