| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import os
- from dotenv import load_dotenv
- import logging
- from httpx import get
- # Load environment variables from .env file
- load_dotenv()
- LOGS_FOLDER = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logs')
- if not os.path.exists(LOGS_FOLDER):
- os.makedirs(LOGS_FOLDER)
- LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()
- # Configure logging
- logging.basicConfig(
- level=getattr(logging, LOG_LEVEL),
- format='%(asctime)s - %(name)s:%(lineno)d - %(levelname)s - %(message)s',
- handlers=[
- logging.FileHandler(os.path.join(LOGS_FOLDER, 'app.log')),
- logging.StreamHandler()
- ]
- )
- # Configuration
- OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
- PORT = int(os.getenv("PORT", 6001))
- EXCLUDED_BEER_IDS = [14, 12, 11]
- # SECRET_KEY is crucial for signing session cookies.
- # Fallback to a default if not set, but warn that this is insecure for production.
- SECRET_KEY = os.getenv("SECRET_KEY", "your_very_very_secret_key_for_signing_cookies_python_v2")
- # Data paths
- BG_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),'data', 'llm_data.json')
- PRODUCTS_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),'data', 'products.json')
- def validate_config():
- logger = logging.getLogger(__name__)
- """Validate configuration and show warnings"""
- if SECRET_KEY == "your_very_very_secret_key_for_signing_cookies_python_v2":
- logger.warning("Using default SECRET_KEY. Please set a strong SECRET_KEY in your .env file for production.")
- if not OPENAI_API_KEY:
- logger.critical("CRITICAL ERROR: OPENAI_API_KEY environment variable not set. The application will not work correctly.")
- return False
- return True
|