Spaces:
Sleeping
Sleeping
File size: 1,862 Bytes
1cff1e5 03faf26 1cff1e5 e39cad1 1cff1e5 e39cad1 1cff1e5 03faf26 1cff1e5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | from pydantic_settings import BaseSettings
from pydantic import field_validator
from functools import lru_cache
import os
from dotenv import load_dotenv
# Load .env from backend directory
load_dotenv(os.path.join(os.path.dirname(__file__), ".env"))
class Settings(BaseSettings):
# App
APP_ENV: str = "production"
APP_HOST: str = "0.0.0.0"
APP_PORT: int = 8000
# Gemini
GEMINI_API_KEY: str
GEMINI_MODEL: str = "gemini-2.5-flash"
GEMINI_FALLBACK_MODELS: str = ""
# MongoDB Atlas
MONGO_URI: str
MONGO_DB_NAME: str = "interview_bot"
# Redis
REDIS_URL: str
# JWT
JWT_SECRET: str
JWT_ALGORITHM: str = "HS256"
JWT_EXPIRY: int = 3600
# File Storage
UPLOAD_DIR: str = "./uploads"
# Frontend
NEXT_PUBLIC_API_URL: str = "http://localhost:3000"
class Config:
env_file = ".env"
extra = "ignore"
@field_validator("MONGO_URI")
@classmethod
def validate_mongo_uri(cls, value: str) -> str:
v = (value or "").strip().lower()
if "localhost" in v or "127.0.0.1" in v:
raise ValueError("MONGO_URI must point to MongoDB Atlas, not localhost")
if not v.startswith("mongodb+srv://"):
raise ValueError("MONGO_URI must use mongodb+srv:// for cloud deployment")
return value
@field_validator("REDIS_URL")
@classmethod
def validate_redis_url(cls, value: str) -> str:
v = (value or "").strip().lower()
if "localhost" in v or "127.0.0.1" in v:
raise ValueError("REDIS_URL must point to a cloud Redis instance, not localhost")
if not (v.startswith("redis://") or v.startswith("rediss://")):
raise ValueError("REDIS_URL must start with redis:// or rediss://")
return value
@lru_cache()
def get_settings() -> Settings:
return Settings()
|