From 40664f561a709edf614c4b68266539f5e117240f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 7 Dec 2023 13:58:49 -0300 Subject: [PATCH 1/5] Fix WebSocket host configuration --- src/frontend/src/modals/formModal/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 6c8a733ef..b04ac8dd0 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -197,8 +197,8 @@ export default function FormModal({ const isSecureProtocol = window.location.protocol === "https:" || window.location.port === "443"; const webSocketProtocol = isSecureProtocol ? "wss" : "ws"; - // const host = isDevelopment ? "localhost:7860" : window.location.host; - const host = window.location.host; + const host = isDevelopment ? "localhost:7860" : window.location.host; + const chatEndpoint = `/api/v1/chat/${chatId}`; return `${ From 79c93bcfe9c0c27559772104a6ec2e3c7d086b1a Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 7 Dec 2023 14:00:51 -0300 Subject: [PATCH 2/5] Refactor database URL handling and add logger messages --- src/backend/langflow/settings.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/backend/langflow/settings.py b/src/backend/langflow/settings.py index ab9217d2c..284e810fc 100644 --- a/src/backend/langflow/settings.py +++ b/src/backend/langflow/settings.py @@ -1,13 +1,13 @@ import contextlib import json import os -from typing import Optional, List from pathlib import Path +from typing import List, Optional import yaml -from pydantic import validator, model_validator -from pydantic_settings import BaseSettings from langflow.utils.logger import logger +from pydantic import model_validator, validator +from pydantic_settings import BaseSettings BASE_COMPONENTS_PATH = str(Path(__file__).parent / "components") @@ -46,11 +46,8 @@ class Settings(BaseSettings): value = langflow_database_url logger.debug("Using LANGFLOW_DATABASE_URL env variable.") else: - # logger.debug("No DATABASE_URL env variable, using sqlite database") - logger.debug("No DATABASE_URL env variable, using custom database from secrets of {}".format(os.environ["host"])) - # value = "sqlite:///./langflow.db" - value = "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"]) - + logger.debug("No DATABASE_URL env variable, using sqlite database") + value = "sqlite:///./langflow.db" return value @validator("COMPONENTS_PATH", pre=True) @@ -58,7 +55,7 @@ class Settings(BaseSettings): if os.getenv("LANGFLOW_COMPONENTS_PATH"): logger.debug("Adding LANGFLOW_COMPONENTS_PATH to components_path") langflow_component_path = os.getenv("LANGFLOW_COMPONENTS_PATH") - if ( + if langflow_component_path and ( Path(langflow_component_path).exists() and langflow_component_path not in value ): From 501ba416d14076330abd8ad29c5bed0372391b58 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 7 Dec 2023 14:02:41 -0300 Subject: [PATCH 3/5] Refactor database connection logic in base settings --- .../langflow/services/settings/base.py | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/backend/langflow/services/settings/base.py b/src/backend/langflow/services/settings/base.py index 1f30aa3e0..91b0044b6 100644 --- a/src/backend/langflow/services/settings/base.py +++ b/src/backend/langflow/services/settings/base.py @@ -1,15 +1,15 @@ import contextlib import json -import orjson import os -from shutil import copy2 -from typing import Optional, List from pathlib import Path +from shutil import copy2 +from typing import List, Optional +import orjson import yaml +from loguru import logger from pydantic import field_validator, validator from pydantic_settings import BaseSettings, SettingsConfigDict -from loguru import logger # BASE_COMPONENTS_PATH = str(Path(__file__).parent / "components") BASE_COMPONENTS_PATH = str(Path(__file__).parent.parent.parent / "components") @@ -86,31 +86,29 @@ class Settings(BaseSettings): value = langflow_database_url logger.debug("Using LANGFLOW_DATABASE_URL env variable.") else: - # logger.debug("No DATABASE_URL env variable, using sqlite database") - logger.debug("No DATABASE_URL env variable, using custom database from secrets of {}".format(os.environ["host"])) + logger.debug("No DATABASE_URL env variable, using sqlite database") # Originally, we used sqlite:///./langflow.db # so we need to migrate to the new format # if there is a database in that location - # if not values["CONFIG_DIR"]: - # raise ValueError( - # "CONFIG_DIR not set, please set it or provide a DATABASE_URL" - # ) + if not values["CONFIG_DIR"]: + raise ValueError( + "CONFIG_DIR not set, please set it or provide a DATABASE_URL" + ) - # new_path = f"{values['CONFIG_DIR']}/langflow.db" - # if Path("./langflow.db").exists(): - # if Path(new_path).exists(): - # logger.debug(f"Database already exists at {new_path}, using it") - # else: - # try: - # logger.debug("Copying existing database to new location") - # copy2("./langflow.db", new_path) - # logger.debug(f"Copied existing database to {new_path}") - # except Exception: - # logger.error("Failed to copy database, using default path") - # new_path = "./langflow.db" + new_path = f"{values['CONFIG_DIR']}/langflow.db" + if Path("./langflow.db").exists(): + if Path(new_path).exists(): + logger.debug(f"Database already exists at {new_path}, using it") + else: + try: + logger.debug("Copying existing database to new location") + copy2("./langflow.db", new_path) + logger.debug(f"Copied existing database to {new_path}") + except Exception: + logger.error("Failed to copy database, using default path") + new_path = "./langflow.db" - # value = f"sqlite:///{new_path}" - value = "mysql+pymysql://{}:{}@{}:3306/{}".format(os.environ["username"],os.environ["password"],os.environ["host"],os.environ["dbname"]) + value = f"sqlite:///{new_path}" return value From 1e1e49b862340b7b0e8e74f628f788148fdafc7a Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 7 Dec 2023 14:03:20 -0300 Subject: [PATCH 4/5] Update database URL in alembic.ini --- src/backend/langflow/alembic.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/alembic.ini b/src/backend/langflow/alembic.ini index cba482993..379661422 100644 --- a/src/backend/langflow/alembic.ini +++ b/src/backend/langflow/alembic.ini @@ -63,7 +63,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne # This is the path to the db in the root of the project. # When the user runs the Langflow the database url will # be set dinamically. -# sqlalchemy.url = sqlite:///../../../langflow.db +sqlalchemy.url = sqlite:///../../../langflow.db [post_write_hooks] From 4e9ef4c83141c3c5c6fde4c435f57d82e4265dff Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 7 Dec 2023 14:05:42 -0300 Subject: [PATCH 5/5] Fix typo in README.md --- scripts/aws/README.md | 51 +++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/scripts/aws/README.md b/scripts/aws/README.md index 06c475ae8..9190046a3 100644 --- a/scripts/aws/README.md +++ b/scripts/aws/README.md @@ -1,8 +1,9 @@ # Deploy Langflow on AWS -**Duraration**: 30 minutes +**Duration**: 30 minutes ## Introduction + In this tutorial, you will learn how to deploy langflow on AWS using [AWS Cloud Development Kit](https://aws.amazon.com/cdk/?nc2=type_a) (CDK). This tutorial assumes you have an AWS account and basic knowledge of AWS. @@ -15,36 +16,38 @@ The Fargate task is divided into a frontend and a backend, which communicate thr If you just want to deploy resources, you do not need in-depth knowledge of each of the above services. # How to set up your environment and deploy langflow + 1. Open [AWS CloudShell](https://us-east-1.console.aws.amazon.com/cloudshell/home?region=us-east-1). 1. Run the following commands in Cloudshell: - ```shell - git clone https://github.com/aws-samples/cloud9-setup-for-prototyping - cd cloud9-setup-for-prototyping - ./bin/bootstrap - ``` + ```shell + git clone https://github.com/aws-samples/cloud9-setup-for-prototyping + cd cloud9-setup-for-prototyping + ./bin/bootstrap + ``` 1. When you see `Done!` in Cloudshell, open `cloud9-for-prototyping` from [AWS Cloud9](https://us-east-1.console.aws.amazon.com/cloud9control/home?region=us-east-1#/). - ![make-cloud9](./img/langflow-cloud9-en.png) + ![make-cloud9](./img/langflow-cloud9-en.png) 1. Run the following command in the Cloud9 terminal. - ```shell - git clone -b aws-cdk-dev2 https://github.com/kazuki306/langflow - cd langflow/scripts/aws - cp .env.example .env # Edit this file if you need environment settings - npm ci - cdk bootstrap - cdk deploy - ``` + ```shell + git clone -b aws-cdk-dev2 https://github.com/kazuki306/langflow + cd langflow/scripts/aws + cp .env.example .env # Edit this file if you need environment settings + npm ci + cdk bootstrap + cdk deploy + ``` 1. Access the URL displayed. - ```shell - Outputs: - LangflowAppStack.NetworkURLXXXXXX = http://alb-XXXXXXXXXXX.elb.amazonaws.com - ``` + ```shell + Outputs: + LangflowAppStack.NetworkURLXXXXXX = http://alb-XXXXXXXXXXX.elb.amazonaws.com + ``` 1. Enter your user name and password to sign in. If you have not set a user name and password in your `.env` file, the user name will be set to `admin` and the password to `123456`. - ![signin-langflow](./img/langflow-signin.png) + ![signin-langflow](./img/langflow-signin.png) # Cleanup + 1. Run the following command in the Cloud9 terminal. - ```shell - bash delete-resources.sh - ``` + ```shell + bash delete-resources.sh + ``` 1. Open [AWS CloudFormation](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/getting-started), select `aws-cloud9-cloud9-for-prototyping-XXXX` and delete it. -![delete-cfn](./img/langflow-cfn.png) \ No newline at end of file + ![delete-cfn](./img/langflow-cfn.png)