🔀 refactor(base.py): import Chain from langchain.chains.base instead of importing it from langflow.graph.vertex.types 🔀 refactor(process.py): remove print statement from process_tweaks function 🔀 refactor(process.py): change load_flow_from_json function signature to accept optional tweaks parameter 🔀 refactor(process.py): change return type of build method in Graph class from List[Vertex] to Chain 🧪 test(loading.py): add test case for loading a flow from a JSON file and applying tweaks 🧪 test(loading.py): remove unused import statement The import statement for Chain in base.py is now more explicit and imports it from langchain.chains.base instead of importing it from langflow.graph.vertex.types. The load_flow_from_json function in process.py now accepts either a JSON file path or a JSON object. The print statement in process_tweaks function has been removed. The load_flow_from_json function in process.py now accepts an optional tweaks parameter. The return type of the build method in the Graph class has been changed from List[Vertex] to Chain. A new test case has been added to loading.py to test loading a flow from a JSON file and applying tweaks. An unused import statement has been removed from loading.py.
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import json
|
|
|
|
import pytest
|
|
from langchain.chains.base import Chain
|
|
from langflow.processing.process import load_flow_from_json
|
|
from langflow.graph import Graph
|
|
from langflow.utils.payload import get_root_node
|
|
|
|
|
|
def test_load_flow_from_json():
|
|
"""Test loading a flow from a json file"""
|
|
loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH)
|
|
assert loaded is not None
|
|
assert isinstance(loaded, Chain)
|
|
|
|
|
|
def test_load_flow_from_json_with_tweaks():
|
|
"""Test loading a flow from a json file and applying tweaks"""
|
|
tweaks = {"dndnode_82": {"model_name": "test model"}}
|
|
loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH, tweaks=tweaks)
|
|
assert loaded is not None
|
|
assert isinstance(loaded, Chain)
|
|
assert loaded.llm.model_name == "test model"
|
|
|
|
|
|
def test_get_root_node():
|
|
with open(pytest.BASIC_EXAMPLE_PATH, "r") as f:
|
|
flow_graph = json.load(f)
|
|
data_graph = flow_graph["data"]
|
|
nodes = data_graph["nodes"]
|
|
edges = data_graph["edges"]
|
|
graph = Graph(nodes, edges)
|
|
root = get_root_node(graph)
|
|
assert root is not None
|
|
assert hasattr(root, "id")
|
|
assert hasattr(root, "data")
|