Fix State Service not loading when using load_flow_from_json (#1661)
* Refactor test_loading.py to improve code readability and maintainability * Refactor code in test_template.py, __main__.py, and utils.py to improve code readability and maintainability * Fix logger.configure() to disable logging when disable flag is True * Refactor validate_icon function to use emoji library for emoji validation in model.py * Refactor import statements in base.py files to improve code organization and maintainability * Refactor state_manager.py to handle error when getting state service and use InMemoryStateService as fallback * Refactor load_flow_from_json function in load.py to configure logs and load services * Add test_run_flow_from_json_object function to test_loading.py * Refactor langflow.processing.process.py and langflow.schema.graph.py * Set all streaming to false in run_flow_from_json function * Refactor import statements in base.py files to improve code organization and maintainability * Refactor arun function in base.py to handle event loop and async execution * Add docstring to run_flow_from_json * Refactor import statements in base.py files to use logger in langflow interface * Refactor build method in ChatOutput and TextInput classes to use build_with_record * Refactor import statements in base.py files to improve code organization and maintainability * Refactor import statements in PythonREPLTool.py for improved code organization and maintainability * Refactor build method in TextOutput class to include optional record_template parameter * Refactor build method in ChatComponent class to include build_no_record method * Refactor input_value parameter in TextInput build method to use Text type * Refactor import statements in FlowTool.py for improved code organization and maintainability * Bump langflow-base version to 0.0.25 and add asyncer dependency * Refactor code in multiple files for improved organization and maintainability * Refactor import statements in multiple files for improved code organization and maintainability
This commit is contained in:
parent
98d9190eee
commit
b0308336c2
55 changed files with 3856 additions and 4439 deletions
|
|
@ -10,10 +10,6 @@ import orjson
|
|||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from httpx import AsyncClient
|
||||
from sqlmodel import Session, SQLModel, create_engine, select
|
||||
from sqlmodel.pool import StaticPool
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from langflow.graph.graph.base import Graph
|
||||
from langflow.initial_setup.setup import STARTER_FOLDER_NAME
|
||||
from langflow.services.auth.utils import get_password_hash
|
||||
|
|
@ -22,6 +18,9 @@ from langflow.services.database.models.flow.model import Flow, FlowCreate
|
|||
from langflow.services.database.models.user.model import User, UserCreate
|
||||
from langflow.services.database.utils import session_getter
|
||||
from langflow.services.deps import get_db_service
|
||||
from sqlmodel import Session, SQLModel, create_engine, select
|
||||
from sqlmodel.pool import StaticPool
|
||||
from typer.testing import CliRunner
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langflow.services.database.service import DatabaseService
|
||||
|
|
@ -204,25 +203,28 @@ def complex_graph_with_groups():
|
|||
|
||||
|
||||
@pytest.fixture(name="client", autouse=True)
|
||||
def client_fixture(session: Session, monkeypatch):
|
||||
def client_fixture(session: Session, monkeypatch, request):
|
||||
# Set the database url to a test database
|
||||
db_dir = tempfile.mkdtemp()
|
||||
db_path = Path(db_dir) / "test.db"
|
||||
monkeypatch.setenv("LANGFLOW_DATABASE_URL", f"sqlite:///{db_path}")
|
||||
monkeypatch.setenv("LANGFLOW_AUTO_LOGIN", "false")
|
||||
if "noclient" in request.keywords:
|
||||
yield
|
||||
else:
|
||||
db_dir = tempfile.mkdtemp()
|
||||
db_path = Path(db_dir) / "test.db"
|
||||
monkeypatch.setenv("LANGFLOW_DATABASE_URL", f"sqlite:///{db_path}")
|
||||
monkeypatch.setenv("LANGFLOW_AUTO_LOGIN", "false")
|
||||
|
||||
from langflow.main import create_app
|
||||
from langflow.main import create_app
|
||||
|
||||
app = create_app()
|
||||
app = create_app()
|
||||
|
||||
# app.dependency_overrides[get_session] = get_session_override
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
# app.dependency_overrides.clear()
|
||||
monkeypatch.undo()
|
||||
# clear the temp db
|
||||
with suppress(FileNotFoundError):
|
||||
db_path.unlink()
|
||||
# app.dependency_overrides[get_session] = get_session_override
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
# app.dependency_overrides.clear()
|
||||
monkeypatch.undo()
|
||||
# clear the temp db
|
||||
with suppress(FileNotFoundError):
|
||||
db_path.unlink()
|
||||
|
||||
|
||||
# create a fixture for session_getter above
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import pytest
|
||||
|
||||
from langflow.graph import Graph
|
||||
from langflow.processing.load import load_flow_from_json
|
||||
from langflow.graph.schema import RunOutputs
|
||||
from langflow.initial_setup.setup import load_starter_projects
|
||||
from langflow.processing.load import load_flow_from_json, run_flow_from_json
|
||||
|
||||
|
||||
@pytest.mark.noclient
|
||||
def test_load_flow_from_json():
|
||||
"""Test loading a flow from a json file"""
|
||||
loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH)
|
||||
|
|
@ -11,9 +13,30 @@ def test_load_flow_from_json():
|
|||
assert isinstance(loaded, Graph)
|
||||
|
||||
|
||||
@pytest.mark.noclient
|
||||
def test_load_flow_from_json_with_tweaks():
|
||||
"""Test loading a flow from a json file and applying tweaks"""
|
||||
tweaks = {"dndnode_82": {"model_name": "gpt-3.5-turbo-16k-0613"}}
|
||||
loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH, tweaks=tweaks)
|
||||
assert loaded is not None
|
||||
assert isinstance(loaded, Graph)
|
||||
|
||||
|
||||
@pytest.mark.noclient
|
||||
def test_load_flow_from_json_object():
|
||||
"""Test loading a flow from a json file and applying tweaks"""
|
||||
_, projects = zip(*load_starter_projects())
|
||||
project = projects[0]
|
||||
loaded = load_flow_from_json(project)
|
||||
assert loaded is not None
|
||||
assert isinstance(loaded, Graph)
|
||||
|
||||
|
||||
@pytest.mark.noclient
|
||||
def test_run_flow_from_json_object():
|
||||
"""Test loading a flow from a json file and applying tweaks"""
|
||||
_, projects = zip(*load_starter_projects())
|
||||
project = projects[0]
|
||||
results = run_flow_from_json(project, input_value="test")
|
||||
assert results is not None
|
||||
assert all(isinstance(result, RunOutputs) for result in results)
|
||||
|
|
|
|||
|
|
@ -2,14 +2,9 @@ import importlib
|
|||
from typing import Dict, List, Optional
|
||||
|
||||
import pytest
|
||||
from langflow.interface.utils import build_template_from_class
|
||||
from langflow.utils.constants import CHAT_OPENAI_MODELS, OPENAI_MODELS
|
||||
from langflow.utils.util import (
|
||||
build_template_from_class,
|
||||
build_template_from_function,
|
||||
format_dict,
|
||||
get_base_classes,
|
||||
get_default_factory,
|
||||
)
|
||||
from langflow.utils.util import build_template_from_function, format_dict, get_base_classes, get_default_factory
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue