🔧 chore(__main__.py): add support for loading environment variables from a .env file

The `load_dotenv` function from the `dotenv` package is now used to load environment variables from a `.env` file. This allows for a more flexible configuration of the application as environment variables can be loaded from a file instead of being hardcoded in the code. The `.env` file path can be specified via the `env_file` parameter.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-11 11:14:43 -03:00
commit 0eaa86c5ca

View file

@ -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()