fix: environment variable initialization issue (#2971)
* feat: apply singleton pattern to class * fix: remove code that overrides environment vars * feat: remove unused imports
This commit is contained in:
parent
53084bcf92
commit
169664cf1b
2 changed files with 9 additions and 26 deletions
|
|
@ -4,12 +4,12 @@ import sys
|
|||
import time
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Optional
|
||||
|
||||
import click
|
||||
import httpx
|
||||
import typer
|
||||
from dotenv import dotenv_values, load_dotenv
|
||||
from dotenv import load_dotenv
|
||||
from multiprocess import cpu_count # type: ignore
|
||||
from multiprocess.context import Process # type: ignore
|
||||
from packaging import version as pkg_version
|
||||
|
|
@ -127,33 +127,9 @@ def run(
|
|||
|
||||
configure(log_level=log_level, log_file=log_file)
|
||||
set_var_for_macos_issue()
|
||||
# override env variables with .env file
|
||||
|
||||
if env_file:
|
||||
load_dotenv(env_file, override=True)
|
||||
env_vars = dotenv_values(env_file)
|
||||
|
||||
# Define a mapping of environment variables to their corresponding variables and types
|
||||
env_var_mapping: dict[str, tuple[str, type | Callable[[Any], bool]]] = {
|
||||
"LANGFLOW_HOST": ("host", str),
|
||||
"LANGFLOW_PORT": ("port", int),
|
||||
"LANGFLOW_WORKERS": ("workers", int),
|
||||
"LANGFLOW_WORKER_TIMEOUT": ("timeout", int),
|
||||
"LANGFLOW_COMPONENTS_PATH": ("components_path", Path),
|
||||
"LANGFLOW_LOG_LEVEL": ("log_level", str),
|
||||
"LANGFLOW_LOG_FILE": ("log_file", Path),
|
||||
"LANGFLOW_LANGCHAIN_CACHE": ("cache", str),
|
||||
"LANGFLOW_FRONTEND_PATH": ("path", str),
|
||||
"LANGFLOW_OPEN_BROWSER": ("open_browser", lambda x: x.lower() == "true"),
|
||||
"LANGFLOW_REMOVE_API_KEYS": ("remove_api_keys", lambda x: x.lower() == "true"),
|
||||
"LANGFLOW_BACKEND_ONLY": ("backend_only", lambda x: x.lower() == "true"),
|
||||
"LANGFLOW_STORE": ("store", lambda x: x.lower() == "true"),
|
||||
}
|
||||
|
||||
# Update variables based on environment variables
|
||||
for env_var, (var_name, var_type) in env_var_mapping.items():
|
||||
if env_var in env_vars:
|
||||
locals()[var_name] = var_type(env_vars[env_var])
|
||||
|
||||
update_settings(
|
||||
dev=dev,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,13 @@ from langflow.services.settings.service import SettingsService
|
|||
|
||||
|
||||
class SettingsServiceFactory(ServiceFactory):
|
||||
_instance = None
|
||||
|
||||
def __new__(cls):
|
||||
if cls._instance is None:
|
||||
cls._instance = super().__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(SettingsService)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue