Daniel.y commited on
Commit
8409ff3
·
unverified ·
2 Parent(s): a5cd590 f1ce9cb

Merge pull request #1221 from danielaskdd/main

Browse files

Refactor: Standardize .env loading behavior across modules

lightrag/api/auth.py CHANGED
@@ -5,7 +5,10 @@ from fastapi import HTTPException, status
5
  from pydantic import BaseModel
6
  from dotenv import load_dotenv
7
 
8
- load_dotenv()
 
 
 
9
 
10
 
11
  class TokenPayload(BaseModel):
 
5
  from pydantic import BaseModel
6
  from dotenv import load_dotenv
7
 
8
+ # use the .env that is inside the current folder
9
+ # allows to use different .env file for each lightrag instance
10
+ # the OS environment variables take precedence over the .env file
11
+ load_dotenv(dotenv_path=".env", override=False)
12
 
13
 
14
  class TokenPayload(BaseModel):
lightrag/api/lightrag_server.py CHANGED
@@ -47,10 +47,10 @@ from lightrag.kg.shared_storage import (
47
  from fastapi.security import OAuth2PasswordRequestForm
48
  from lightrag.api.auth import auth_handler
49
 
50
- # Load environment variables
51
- # Updated to use the .env that is inside the current folder
52
- # This update allows the user to put a different.env file for each lightrag folder
53
- load_dotenv(".env")
54
 
55
  # Initialize config parser
56
  config = configparser.ConfigParser()
 
47
  from fastapi.security import OAuth2PasswordRequestForm
48
  from lightrag.api.auth import auth_handler
49
 
50
+ # use the .env that is inside the current folder
51
+ # allows to use different .env file for each lightrag instance
52
+ # the OS environment variables take precedence over the .env file
53
+ load_dotenv(dotenv_path=".env", override=False)
54
 
55
  # Initialize config parser
56
  config = configparser.ConfigParser()
lightrag/api/run_with_gunicorn.py CHANGED
@@ -11,9 +11,10 @@ from lightrag.api.utils_api import parse_args, display_splash_screen, check_env_
11
  from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
12
  from dotenv import load_dotenv
13
 
14
- # Updated to use the .env that is inside the current folder
15
- # This update allows the user to put a different.env file for each lightrag folder
16
- load_dotenv(".env")
 
17
 
18
 
19
  def check_and_install_dependencies():
 
11
  from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
12
  from dotenv import load_dotenv
13
 
14
+ # use the .env that is inside the current folder
15
+ # allows to use different .env file for each lightrag instance
16
+ # the OS environment variables take precedence over the .env file
17
+ load_dotenv(dotenv_path=".env", override=False)
18
 
19
 
20
  def check_and_install_dependencies():
lightrag/api/utils_api.py CHANGED
@@ -25,7 +25,7 @@ def check_env_file():
25
  """
26
  if not os.path.exists(".env"):
27
  warning_msg = (
28
- "Warning: .env file not found. Some features may not work properly."
29
  )
30
  ASCIIColors.yellow(warning_msg)
31
 
@@ -38,8 +38,10 @@ def check_env_file():
38
  return True
39
 
40
 
41
- # Load environment variables
42
- load_dotenv()
 
 
43
 
44
  global_args = {"main_args": None}
45
 
 
25
  """
26
  if not os.path.exists(".env"):
27
  warning_msg = (
28
+ "Warning: Startup directory must contain .env file for multi-instance support."
29
  )
30
  ASCIIColors.yellow(warning_msg)
31
 
 
38
  return True
39
 
40
 
41
+ # use the .env that is inside the current folder
42
+ # allows to use different .env file for each lightrag instance
43
+ # the OS environment variables take precedence over the .env file
44
+ load_dotenv(dotenv_path=".env", override=False)
45
 
46
  global_args = {"main_args": None}
47
 
lightrag/utils.py CHANGED
@@ -19,9 +19,10 @@ import tiktoken
19
  from lightrag.prompt import PROMPTS
20
  from dotenv import load_dotenv
21
 
22
- # Load environment variables
23
- load_dotenv(override=True)
24
-
 
25
 
26
  VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true"
27
 
 
19
  from lightrag.prompt import PROMPTS
20
  from dotenv import load_dotenv
21
 
22
+ # use the .env that is inside the current folder
23
+ # allows to use different .env file for each lightrag instance
24
+ # the OS environment variables take precedence over the .env file
25
+ load_dotenv(dotenv_path=".env", override=False)
26
 
27
  VERBOSE_DEBUG = os.getenv("VERBOSE", "false").lower() == "true"
28