🔧 chore(conftest.py): add new path for vector_store_grouped.json file to improve test coverage 🆕 feat(Vector Store): add Vector Store agent and Vector Store Info node The Vector Store agent allows querying a Vector Store. It can be used to construct an agent from a Vector Store. The Vector Store Info node provides information about a Vector Store. The Vector Store agent and Vector Store Info node are added to support the functionality of querying a Vector Store. 🔧 chore: update configuration options in the code 📝 docs: add information about the OpenAI API Base configuration option in the code comments 🔧 chore: update configuration for ChatOpenAI and Chroma nodes 📝 docs: update documentation for ChatOpenAI and Chroma nodes 🔧 chore(config): update OpenAIEmbeddings-YwSvx configuration options The OpenAIEmbeddings-YwSvx configuration options have been updated to include new fields and values. This commit updates the configuration file to reflect these changes. 🔧 chore(config): update configuration options for OpenAIEmbeddings and Chroma 🔧 chore(config): update configuration options for OpenAIEmbeddings and Chroma to improve flexibility and customization 🔧 chore(config): update configuration options for RecursiveCharacterTextSplitter and WebBaseLoader 📝 docs(config): update configuration options for RecursiveCharacterTextSplitter and WebBaseLoader in documentation 🔧 chore(OpenAIEmbeddings): update OpenAIEmbeddings configuration options The OpenAIEmbeddings node configuration options have been updated to include the following changes: - `allowed_special` and `disallowed_special` now accept a list of values instead of a single value - `chunk_size` now accepts an integer value - `deployment` now accepts a string value - `embedding_ctx_length` now accepts an integer value - `headers` now supports multiline values - `max_retries` now accepts an integer value - `model` now accepts a string value - `model_kwargs` now accepts code input - `openai_api_base` now accepts a password input - `openai_api_key` now accepts a password input - `openai_api_type` now accepts a password input - `openai_api_version` now accepts a password input - `openai_organization` has been removed from the configuration options 🔧 chore: update OpenAIEmbeddings configuration options in the UI The OpenAIEmbeddings configuration options in the UI have been updated to include the following changes: - Added the `openai_organization` option to specify the OpenAI organization. - Added the `openai_proxy` option to configure the OpenAI proxy. - Added the `request_timeout` option to set the request timeout. - Added the `show_progress_bar` option to control the display of progress bars. - Added the `tiktoken_model_name` option to specify the Tiktoken model name. These changes improve the flexibility and customization of the OpenAI embedding models. 🔧 chore: clean up unused code and remove unnecessary fields in the configuration file 📝 docs: update documentation link for the Chroma vectorstore module 🔧 fix: fix formatting issue in chunk_size field in RecursiveCharacterTextSplitter node configuration 🔧 fix: fix formatting issue in separator_type field in RecursiveCharacterTextSplitter node configuration 🔧 fix: fix formatting issue in separators field in RecursiveCharacterTextSplitter node configuration 📝 chore(vector_store_grouped.json): add vector_store_grouped.json test data file 🔀 chore(vector_store_grouped.json): add vector_store_grouped.json test data file ✅ test(graph.py): add test case for processing flow with grouped nodes and vector store 🔍 test(graph.py): add assertions to verify the correctness of the processed flow with grouped nodes and vector store 🔧 test(graph.py): update test case for updating template to make a deep copy of sample_nodes to keep it unchanged
237 lines
6 KiB
Python
237 lines
6 KiB
Python
from contextlib import contextmanager
|
|
import json
|
|
from pathlib import Path
|
|
from typing import AsyncGenerator, TYPE_CHECKING
|
|
from langflow.api.v1.flows import get_session
|
|
|
|
from langflow.graph.graph.base import Graph
|
|
from langflow.services.auth.utils import get_password_hash
|
|
from langflow.services.database.models.flow.flow import Flow
|
|
from langflow.services.database.models.user.user import User, UserCreate
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from httpx import AsyncClient
|
|
from sqlmodel import SQLModel, Session, create_engine
|
|
from sqlmodel.pool import StaticPool
|
|
from typer.testing import CliRunner
|
|
|
|
if TYPE_CHECKING:
|
|
from langflow.services.database.manager import DatabaseManager
|
|
|
|
|
|
def pytest_configure():
|
|
pytest.BASIC_EXAMPLE_PATH = (
|
|
Path(__file__).parent.absolute() / "data" / "basic_example.json"
|
|
)
|
|
pytest.COMPLEX_EXAMPLE_PATH = (
|
|
Path(__file__).parent.absolute() / "data" / "complex_example.json"
|
|
)
|
|
pytest.OPENAPI_EXAMPLE_PATH = (
|
|
Path(__file__).parent.absolute() / "data" / "Openapi.json"
|
|
)
|
|
pytest.GROUPED_CHAT_EXAMPLE_PATH = (
|
|
Path(__file__).parent.absolute() / "data" / "grouped_chat.json"
|
|
)
|
|
pytest.ONE_GROUPED_CHAT_EXAMPLE_PATH = (
|
|
Path(__file__).parent.absolute() / "data" / "one_group_chat.json"
|
|
)
|
|
pytest.VECTOR_STORE_GROUPED_EXAMPLE_PATH = (
|
|
Path(__file__).parent.absolute() / "data" / "vector_store_grouped.json"
|
|
)
|
|
|
|
pytest.CODE_WITH_SYNTAX_ERROR = """
|
|
def get_text():
|
|
retun "Hello World"
|
|
"""
|
|
|
|
|
|
@pytest.fixture()
|
|
async def async_client() -> AsyncGenerator:
|
|
from langflow.main import create_app
|
|
|
|
app = create_app()
|
|
async with AsyncClient(app=app, base_url="http://testserver") as client:
|
|
yield client
|
|
|
|
|
|
# Create client fixture for FastAPI
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
def client():
|
|
from langflow.main import create_app
|
|
|
|
app = create_app()
|
|
|
|
with TestClient(app) as client:
|
|
yield client
|
|
|
|
|
|
def get_graph(_type="basic"):
|
|
"""Get a graph from a json file"""
|
|
|
|
if _type == "basic":
|
|
path = pytest.BASIC_EXAMPLE_PATH
|
|
elif _type == "complex":
|
|
path = pytest.COMPLEX_EXAMPLE_PATH
|
|
elif _type == "openapi":
|
|
path = pytest.OPENAPI_EXAMPLE_PATH
|
|
|
|
with open(path, "r") as f:
|
|
flow_graph = json.load(f)
|
|
data_graph = flow_graph["data"]
|
|
nodes = data_graph["nodes"]
|
|
edges = data_graph["edges"]
|
|
return Graph(nodes, edges)
|
|
|
|
|
|
@pytest.fixture
|
|
def basic_graph_data():
|
|
with open(pytest.BASIC_EXAMPLE_PATH, "r") as f:
|
|
return json.load(f)
|
|
|
|
|
|
@pytest.fixture
|
|
def basic_graph():
|
|
return get_graph()
|
|
|
|
|
|
@pytest.fixture
|
|
def complex_graph():
|
|
return get_graph("complex")
|
|
|
|
|
|
@pytest.fixture
|
|
def openapi_graph():
|
|
return get_graph("openapi")
|
|
|
|
|
|
@pytest.fixture
|
|
def json_flow():
|
|
with open(pytest.BASIC_EXAMPLE_PATH, "r") as f:
|
|
return f.read()
|
|
|
|
|
|
@pytest.fixture
|
|
def grouped_chat_json_flow():
|
|
with open(pytest.GROUPED_CHAT_EXAMPLE_PATH, "r") as f:
|
|
return f.read()
|
|
|
|
|
|
@pytest.fixture
|
|
def one_grouped_chat_json_flow():
|
|
with open(pytest.ONE_GROUPED_CHAT_EXAMPLE_PATH, "r") as f:
|
|
return f.read()
|
|
|
|
|
|
@pytest.fixture
|
|
def vector_store_grouped_json_flow():
|
|
with open(pytest.VECTOR_STORE_GROUPED_EXAMPLE_PATH, "r") as f:
|
|
return f.read()
|
|
|
|
|
|
@pytest.fixture(name="session")
|
|
def session_fixture():
|
|
engine = create_engine(
|
|
"sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool
|
|
)
|
|
SQLModel.metadata.create_all(engine)
|
|
with Session(engine) as session:
|
|
yield session
|
|
|
|
|
|
@pytest.fixture(name="client")
|
|
def client_fixture(session: Session):
|
|
def get_session_override():
|
|
return session
|
|
|
|
from langflow.main import create_app
|
|
|
|
app = create_app()
|
|
|
|
app.dependency_overrides[get_session] = get_session_override
|
|
with TestClient(app) as client:
|
|
yield client
|
|
app.dependency_overrides.clear()
|
|
|
|
|
|
# @contextmanager
|
|
# def session_getter():
|
|
# try:
|
|
# session = Session(engine)
|
|
# yield session
|
|
# except Exception as e:
|
|
# print("Session rollback because of exception:", e)
|
|
# session.rollback()
|
|
# raise
|
|
# finally:
|
|
# session.close()
|
|
|
|
|
|
# create a fixture for session_getter above
|
|
@pytest.fixture(name="session_getter")
|
|
def session_getter_fixture(client):
|
|
engine = create_engine(
|
|
"sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool
|
|
)
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
@contextmanager
|
|
def blank_session_getter(db_manager: "DatabaseManager"):
|
|
with Session(db_manager.engine) as session:
|
|
yield session
|
|
|
|
yield blank_session_getter
|
|
|
|
|
|
@pytest.fixture
|
|
def runner():
|
|
return CliRunner()
|
|
|
|
|
|
@pytest.fixture
|
|
def test_user(client):
|
|
user_data = UserCreate(
|
|
username="testuser",
|
|
password="testpassword",
|
|
)
|
|
response = client.post("/api/v1/user", json=user_data.dict())
|
|
return response.json()
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def active_user(client, session):
|
|
user = User(
|
|
username="activeuser",
|
|
password=get_password_hash(
|
|
"testpassword"
|
|
), # Assuming password needs to be hashed
|
|
is_active=True,
|
|
is_superuser=False,
|
|
)
|
|
session.add(user)
|
|
session.commit()
|
|
return user
|
|
|
|
|
|
@pytest.fixture
|
|
def logged_in_headers(client, active_user):
|
|
login_data = {"username": active_user.username, "password": "testpassword"}
|
|
response = client.post("/api/v1/login", data=login_data)
|
|
assert response.status_code == 200
|
|
tokens = response.json()
|
|
a_token = tokens["access_token"]
|
|
return {"Authorization": f"Bearer {a_token}"}
|
|
|
|
|
|
@pytest.fixture
|
|
def flow(client, json_flow: str, session, active_user):
|
|
from langflow.services.database.models.flow.flow import FlowCreate
|
|
|
|
loaded_json = json.loads(json_flow)
|
|
flow_data = FlowCreate(
|
|
name="test_flow", data=loaded_json.get("data"), user_id=active_user.id
|
|
)
|
|
flow = Flow(**flow_data.dict())
|
|
session.add(flow)
|
|
session.commit()
|
|
|
|
return flow
|