From 0eaa86c5ca4c02d601192fc8cbbf2676f7e57081 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 11 Jun 2023 11:14:43 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(=5F=5Fmain=5F=5F.py):=20ad?= =?UTF-8?q?d=20support=20for=20loading=20environment=20variables=20from=20?= =?UTF-8?q?a=20.env=20file=20The=20`load=5Fdotenv`=20function=20from=20the?= =?UTF-8?q?=20`dotenv`=20package=20is=20now=20used=20to=20load=20environme?= =?UTF-8?q?nt=20variables=20from=20a=20`.env`=20file.=20This=20allows=20fo?= =?UTF-8?q?r=20a=20more=20flexible=20configuration=20of=20the=20applicatio?= =?UTF-8?q?n=20as=20environment=20variables=20can=20be=20loaded=20from=20a?= =?UTF-8?q?=20file=20instead=20of=20being=20hardcoded=20in=20the=20code.?= =?UTF-8?q?=20The=20`.env`=20file=20path=20can=20be=20specified=20via=20th?= =?UTF-8?q?e=20`env=5Ffile`=20parameter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 4a00802c9..ff99699c4 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -15,7 +15,7 @@ from langflow.main import create_app from langflow.settings import settings from langflow.utils.logger import configure, logger import webbrowser - +from dotenv import load_dotenv app = typer.Typer() @@ -85,6 +85,10 @@ def serve( timeout: int = typer.Option(60, help="Worker timeout in seconds."), port: int = typer.Option(7860, help="Port to listen on."), config: str = typer.Option("config.yaml", help="Path to the configuration file."), + # .env file param + env_file: Path = typer.Option( + ".env", help="Path to the .env file containing environment variables." + ), log_level: str = typer.Option("critical", help="Logging level."), log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file."), jcloud: bool = typer.Option(False, help="Deploy on Jina AI Cloud"), @@ -99,11 +103,27 @@ def serve( ): """ Run the Langflow server. + + Args: + host (str): Host to bind the server to. + workers (int): Number of worker processes. + timeout (int): Worker timeout in seconds. + port (int): Port to listen on. + config (str): Path to the configuration file. + env_file (Path): Path to the .env file containing environment variables. + log_level (str): Logging level. + log_file (Path): Path to the log file. + jcloud (bool): Deploy on Jina AI Cloud. + dev (bool): Run in development mode (may contain bugs). + path (str): Path to the frontend directory containing build files. This is for development purposes only. + open_browser (bool): Open the browser after starting the server. """ if jcloud: return serve_on_jcloud() + load_dotenv(env_file) + configure(log_level=log_level, log_file=log_file) update_settings(config, dev=dev) app = create_app()