From fedbf906d9c95927bf961244bad16c8e05adcb64 Mon Sep 17 00:00:00 2001 From: Mendon Kissling <59585235+mendonk@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:37:30 -0400 Subject: [PATCH 1/3] update-gif --- docs/docs/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/index.mdx b/docs/docs/index.mdx index 7fb912e98..54960502b 100644 --- a/docs/docs/index.mdx +++ b/docs/docs/index.mdx @@ -14,8 +14,8 @@ Its intuitive interface allows for easy manipulation of AI building blocks, enab From 22a7b7e75f6fb36e219674ab9831ada909e96980 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 4 Jun 2024 08:59:02 -0700 Subject: [PATCH 2/3] (refactor) Update pytest arguments in Makefile for better test execution (#2063) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: Update pytest arguments in Makefile for better test execution The Makefile has been modified to update the pytest arguments in the `tests` target. The `--instafail` flag has been replaced with `-ra -n auto -m "not api_key_required"`. This change allows for better test execution by including additional options for reporting, parallelization, and test selection. Note: The commit message has been generated based on the provided code changes and recent commits. * ✨ (test_endpoints.py): add pytest marker 'api_key_required' to mark tests that require an API key for authorization. This helps in easily identifying and managing tests that need special permissions. --- Makefile | 4 ++-- pyproject.toml | 2 +- tests/test_endpoints.py | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f62ecb411..878eeca80 100644 --- a/Makefile +++ b/Makefile @@ -48,8 +48,8 @@ coverage: # allow passing arguments to pytest tests: - poetry run pytest tests --instafail $(args) -# Use like: + poetry run pytest tests --instafail -ra -n auto -m "not api_key_required" $(args) + format: poetry run ruff check . --fix diff --git a/pyproject.toml b/pyproject.toml index bec91ee97..8c7f6c237 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -140,7 +140,7 @@ testpaths = ["tests", "integration"] console_output_style = "progress" filterwarnings = ["ignore::DeprecationWarning"] log_cli = true -markers = ["async_test"] +markers = ["async_test", "api_key_required"] [tool.ruff] diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index d23cfd06e..0a7d60069 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -4,6 +4,7 @@ from uuid import UUID, uuid4 import pytest from fastapi import status from fastapi.testclient import TestClient + from langflow.custom.directory_reader.directory_reader import DirectoryReader from langflow.services.deps import get_settings_service @@ -632,6 +633,7 @@ def test_successful_run_with_input_type_any(client, starter_project, created_api assert all([output.get("results").get("result") == "value1" for output in any_input_outputs]), any_input_outputs +@pytest.mark.api_key_required def test_run_with_inputs_and_outputs(client, starter_project, created_api_key): headers = {"x-api-key": created_api_key.api_key} flow_id = starter_project["id"] @@ -659,6 +661,7 @@ def test_invalid_flow_id(client, created_api_key): # Check if the error detail is as expected +@pytest.mark.api_key_required def test_run_flow_with_caching_success(client: TestClient, starter_project, created_api_key): flow_id = starter_project["id"] headers = {"x-api-key": created_api_key.api_key} @@ -676,6 +679,7 @@ def test_run_flow_with_caching_success(client: TestClient, starter_project, crea assert "session_id" in data +@pytest.mark.api_key_required def test_run_flow_with_caching_invalid_flow_id(client: TestClient, created_api_key): invalid_flow_id = uuid4() headers = {"x-api-key": created_api_key.api_key} @@ -687,6 +691,7 @@ def test_run_flow_with_caching_invalid_flow_id(client: TestClient, created_api_k assert f"Flow identifier {invalid_flow_id} not found" in data["detail"] +@pytest.mark.api_key_required def test_run_flow_with_caching_invalid_input_format(client: TestClient, starter_project, created_api_key): flow_id = starter_project["id"] headers = {"x-api-key": created_api_key.api_key} @@ -695,6 +700,7 @@ def test_run_flow_with_caching_invalid_input_format(client: TestClient, starter_ assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY +@pytest.mark.api_key_required def test_run_flow_with_session_id(client, starter_project, created_api_key): headers = {"x-api-key": created_api_key.api_key} flow_id = starter_project["id"] @@ -726,6 +732,7 @@ def test_run_flow_with_invalid_session_id(client, starter_project, created_api_k assert f"Session {payload['session_id']} not found" in data["detail"] +@pytest.mark.api_key_required def test_run_flow_with_invalid_tweaks(client, starter_project, created_api_key): headers = {"x-api-key": created_api_key.api_key} flow_id = starter_project["id"] From 82a3733ed7dbc017124a6fd8a0da269d1da39ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Tue, 4 Jun 2024 18:36:52 +0200 Subject: [PATCH 3/3] setting fallback_to_env_var should be respected in api calls (#2058) --- src/backend/base/langflow/helpers/flow.py | 6 ++++-- src/backend/base/langflow/processing/process.py | 4 ++++ src/backend/base/langflow/services/settings/base.py | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/helpers/flow.py b/src/backend/base/langflow/helpers/flow.py index 0f2a1e170..9a8a7c3b5 100644 --- a/src/backend/base/langflow/helpers/flow.py +++ b/src/backend/base/langflow/helpers/flow.py @@ -8,7 +8,7 @@ from sqlmodel import Session, select from langflow.graph.schema import RunOutputs from langflow.schema.schema import INPUT_FIELD_NAME, Record from langflow.services.database.models.flow import Flow -from langflow.services.deps import get_session, session_scope +from langflow.services.deps import get_session, get_settings_service, session_scope if TYPE_CHECKING: from langflow.graph.graph.base import Graph @@ -88,7 +88,9 @@ async def run_flow( inputs_components.append(input_dict.get("components", [])) types.append(input_dict.get("type", "chat")) - return await graph.arun(inputs_list, inputs_components=inputs_components, types=types) + fallback_to_env_vars = get_settings_service().settings.fallback_to_env_var + + return await graph.arun(inputs_list, inputs_components=inputs_components, types=types, fallback_to_env_vars=fallback_to_env_vars) def generate_function_for_flow( diff --git a/src/backend/base/langflow/processing/process.py b/src/backend/base/langflow/processing/process.py index d53b5e25f..aeff0f1a4 100644 --- a/src/backend/base/langflow/processing/process.py +++ b/src/backend/base/langflow/processing/process.py @@ -8,6 +8,7 @@ from langflow.graph.schema import RunOutputs from langflow.graph.vertex.base import Vertex from langflow.schema.graph import InputValue, Tweaks from langflow.schema.schema import INPUT_FIELD_NAME +from langflow.services.deps import get_settings_service from langflow.services.session.service import SessionService if TYPE_CHECKING: @@ -49,6 +50,8 @@ async def run_graph_internal( inputs_list.append({INPUT_FIELD_NAME: input_value_request.input_value}) types.append(input_value_request.type) + fallback_to_env_vars = get_settings_service().settings.fallback_to_env_var + run_outputs = await graph.arun( inputs_list, components, @@ -56,6 +59,7 @@ async def run_graph_internal( outputs or [], stream=stream, session_id=session_id_str or "", + fallback_to_env_vars=fallback_to_env_vars ) if session_id_str and session_service: await session_service.update_session(session_id_str, (graph, artifacts)) diff --git a/src/backend/base/langflow/services/settings/base.py b/src/backend/base/langflow/services/settings/base.py index 4f50cb756..259e10170 100644 --- a/src/backend/base/langflow/services/settings/base.py +++ b/src/backend/base/langflow/services/settings/base.py @@ -78,6 +78,7 @@ class Settings(BaseSettings): langchain_cache: str = "InMemoryCache" load_flows_path: Optional[str] = None + # Redis redis_host: str = "localhost" redis_port: int = 6379