refactor: standardize .env loading behavior across modules
- Use .env from current folder for each lightrag instance - Allow different .env files for different instances - Make OS env vars take precedence over .env file
This commit is contained in:
@@ -5,7 +5,10 @@ from fastapi import HTTPException, status
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
# use the .env that is inside the current folder
|
||||||
|
# allows to use different .env file for each lightrag instance
|
||||||
|
# the OS environment variables take precedence over the .env file
|
||||||
|
load_dotenv(dotenv_path=".env", override=False)
|
||||||
|
|
||||||
|
|
||||||
class TokenPayload(BaseModel):
|
class TokenPayload(BaseModel):
|
||||||
|
@@ -47,10 +47,10 @@ from lightrag.kg.shared_storage import (
|
|||||||
from fastapi.security import OAuth2PasswordRequestForm
|
from fastapi.security import OAuth2PasswordRequestForm
|
||||||
from lightrag.api.auth import auth_handler
|
from lightrag.api.auth import auth_handler
|
||||||
|
|
||||||
# Load environment variables
|
# use the .env that is inside the current folder
|
||||||
# Updated to use the .env that is inside the current folder
|
# allows to use different .env file for each lightrag instance
|
||||||
# This update allows the user to put a different.env file for each lightrag folder
|
# the OS environment variables take precedence over the .env file
|
||||||
load_dotenv(".env")
|
load_dotenv(dotenv_path=".env", override=False)
|
||||||
|
|
||||||
# Initialize config parser
|
# Initialize config parser
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@@ -11,9 +11,10 @@ from lightrag.api.utils_api import parse_args, display_splash_screen, check_env_
|
|||||||
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
|
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# Updated to use the .env that is inside the current folder
|
# use the .env that is inside the current folder
|
||||||
# This update allows the user to put a different.env file for each lightrag folder
|
# allows to use different .env file for each lightrag instance
|
||||||
load_dotenv(".env")
|
# the OS environment variables take precedence over the .env file
|
||||||
|
load_dotenv(dotenv_path=".env", override=False)
|
||||||
|
|
||||||
|
|
||||||
def check_and_install_dependencies():
|
def check_and_install_dependencies():
|
||||||
|
@@ -38,8 +38,10 @@ def check_env_file():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Load environment variables
|
# use the .env that is inside the current folder
|
||||||
load_dotenv()
|
# allows to use different .env file for each lightrag instance
|
||||||
|
# the OS environment variables take precedence over the .env file
|
||||||
|
load_dotenv(dotenv_path=".env", override=False)
|
||||||
|
|
||||||
global_args = {"main_args": None}
|
global_args = {"main_args": None}
|
||||||
|
|
||||||
|
@@ -19,9 +19,10 @@ import tiktoken
|
|||||||
from lightrag.prompt import PROMPTS
|
from lightrag.prompt import PROMPTS
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# Load environment variables
|
# use the .env that is inside the current folder
|
||||||
load_dotenv(override=True)
|
# allows to use different .env file for each lightrag instance
|
||||||
|
# the OS environment variables take precedence over the .env file
|
||||||
|
load_dotenv(dotenv_path=".env", override=False)
|
||||||
|
|
||||||
VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true"
|
VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user