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:
yangdx
2025-03-29 03:37:23 +08:00
parent f165b4011d
commit c590d5878c
5 changed files with 20 additions and 13 deletions

View File

@@ -5,7 +5,10 @@ from fastapi import HTTPException, status
from pydantic import BaseModel
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):

View File

@@ -47,10 +47,10 @@ from lightrag.kg.shared_storage import (
from fastapi.security import OAuth2PasswordRequestForm
from lightrag.api.auth import auth_handler
# Load environment variables
# Updated to use the .env that is inside the current folder
# This update allows the user to put a different.env file for each lightrag folder
load_dotenv(".env")
# 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)
# Initialize config parser
config = configparser.ConfigParser()

View File

@@ -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 dotenv import load_dotenv
# Updated to use the .env that is inside the current folder
# This update allows the user to put a different.env file for each lightrag folder
load_dotenv(".env")
# 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)
def check_and_install_dependencies():

View File

@@ -38,8 +38,10 @@ def check_env_file():
return True
# Load environment variables
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)
global_args = {"main_args": None}