Merge pull request #1195 from danielaskdd/env-file-check

feat: add .env file check on startup
This commit is contained in:
Daniel.y
2025-03-26 21:13:40 +08:00
committed by GitHub
3 changed files with 29 additions and 1 deletions

View File

@@ -22,7 +22,9 @@ from lightrag.api.utils_api import (
parse_args,
get_default_host,
display_splash_screen,
check_env_file,
)
import sys
from lightrag import LightRAG, __version__ as core_version
from lightrag.api import __api_version__
from lightrag.types import GPTKeywordExtractionFormat
@@ -595,6 +597,10 @@ def main():
print("Running under Gunicorn - worker management handled by Gunicorn")
return
# Check .env file
if not check_env_file():
sys.exit(1)
# Check and install dependencies
check_and_install_dependencies()

View File

@@ -7,7 +7,7 @@ import os
import sys
import signal
import pipmaster as pm
from lightrag.api.utils_api import parse_args, display_splash_screen
from lightrag.api.utils_api import parse_args, display_splash_screen, check_env_file
from lightrag.kg.shared_storage import initialize_share_data, finalize_share_data
from dotenv import load_dotenv
@@ -47,6 +47,10 @@ def signal_handler(sig, frame):
def main():
# Check .env file
if not check_env_file():
sys.exit(1)
# Check and install dependencies
check_and_install_dependencies()

View File

@@ -6,6 +6,7 @@ import os
import argparse
from typing import Optional, List, Tuple
import sys
from ascii_colors import ASCIIColors
import logging
from ascii_colors import ASCIIColors
from lightrag.api import __api_version__
@@ -16,6 +17,23 @@ from starlette.status import HTTP_403_FORBIDDEN
from .auth import auth_handler
from ..prompt import PROMPTS
def check_env_file():
"""
Check if .env file exists and handle user confirmation if needed.
Returns True if should continue, False if should exit.
"""
if not os.path.exists(".env"):
warning_msg = "Warning: .env file not found. Some features may not work properly."
ASCIIColors.yellow(warning_msg)
# Check if running in interactive terminal
if sys.stdin.isatty():
response = input("Do you want to continue? (yes/no): ")
if response.lower() != "yes":
ASCIIColors.red("Server startup cancelled")
return False
return True
# Load environment variables
load_dotenv()