From 513812900385d57d1b2af001b64de58fb340063c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 5 Jul 2023 15:41:49 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(=5F=5Fmain=5F=5F.py):=20ad?= =?UTF-8?q?d=20load=5Fparams()=20function=20to=20load=20parameters=20from?= =?UTF-8?q?=20environment=20variables=20The=20load=5Fparams()=20function?= =?UTF-8?q?=20is=20added=20to=20load=20the=20parameters=20from=20the=20env?= =?UTF-8?q?ironment=20variables.=20This=20allows=20for=20more=20flexibilit?= =?UTF-8?q?y=20and=20configurability=20of=20the=20application=20by=20allow?= =?UTF-8?q?ing=20the=20parameters=20to=20be=20set=20via=20environment=20va?= =?UTF-8?q?riables.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 15005585c..9002a20ee 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -48,6 +48,26 @@ def update_settings( settings.update_settings(cache=cache) +def load_params(): + """ + Load the parameters from the environment variables. + """ + global_vars = globals() + + for key, value in global_vars.items(): + env_key = f"LANGFLOW_{key.upper()}" + if env_key in os.environ: + if isinstance(value, bool): + # Handle booleans + global_vars[key] = os.getenv(env_key, str(value)).lower() == "true" + elif isinstance(value, int): + # Handle integers + global_vars[key] = int(os.getenv(env_key, str(value))) + elif isinstance(value, str) or value is None: + # Handle strings and None values + global_vars[key] = os.getenv(env_key, str(value)) + + def serve_on_jcloud(): """ Deploy Langflow server on Jina AI Cloud @@ -149,6 +169,7 @@ def serve( # override env variables with .env file if env_file: load_dotenv(env_file, override=True) + load_params() if jcloud: return serve_on_jcloud()