Spaces:
Sleeping
Sleeping
| """ | |
| Quick setup verification script | |
| Run this to check if your environment is configured correctly | |
| """ | |
| import sys | |
| import os | |
| from pathlib import Path | |
| def check_env_file(): | |
| """Check if .env file exists and has required variables""" | |
| env_path = Path(__file__).parent / ".env" | |
| if not env_path.exists(): | |
| print("β .env file not found!") | |
| print(" Create it by copying .env.example and adding your credentials") | |
| return False | |
| print("β .env file exists") | |
| # Read and check for required variables | |
| with open(env_path) as f: | |
| content = f.read() | |
| required_vars = { | |
| 'OPENAI_API_KEY': 'OpenAI API key', | |
| } | |
| missing = [] | |
| for var, description in required_vars.items(): | |
| if var not in content: | |
| missing.append(f" - {var} ({description})") | |
| elif f"{var}=your_" in content or f"{var}=" in content and len(content.split(f"{var}=")[1].split('\n')[0].strip()) < 10: | |
| print(f"β οΈ {var} appears to be a placeholder - please set your actual {description}") | |
| missing.append(f" - {var} needs to be set") | |
| if missing: | |
| print("β Missing or invalid environment variables:") | |
| for m in missing: | |
| print(m) | |
| return False | |
| print("β Required environment variables are set") | |
| return True | |
| def check_dependencies(): | |
| """Check if required packages are installed""" | |
| required_packages = [ | |
| 'fastapi', | |
| 'uvicorn', | |
| 'openai', | |
| 'qdrant_client', | |
| 'sqlalchemy', | |
| 'pydantic', | |
| 'pydantic_settings' | |
| ] | |
| missing = [] | |
| for package in required_packages: | |
| try: | |
| __import__(package.replace('-', '_')) | |
| print(f"β {package} installed") | |
| except ImportError: | |
| missing.append(package) | |
| print(f"β {package} not installed") | |
| if missing: | |
| print("\nβ Missing packages. Install them with:") | |
| print(" pip install -r requirements.txt") | |
| return False | |
| return True | |
| def check_openai_key(): | |
| """Test if OpenAI API key is valid""" | |
| try: | |
| from app.config import settings | |
| if not settings.OPENAI_API_KEY or settings.OPENAI_API_KEY.startswith('your_'): | |
| print("β OPENAI_API_KEY is not set or is a placeholder") | |
| print(" Please set your actual OpenAI API key in .env file") | |
| return False | |
| print("β OPENAI_API_KEY is configured") | |
| print(f" Key starts with: {settings.OPENAI_API_KEY[:10]}...") | |
| return True | |
| except Exception as e: | |
| print(f"β Error loading config: {e}") | |
| return False | |
| def main(): | |
| print("=" * 60) | |
| print("Backend Setup Verification") | |
| print("=" * 60) | |
| print() | |
| checks = [ | |
| ("Environment File", check_env_file), | |
| ("Dependencies", check_dependencies), | |
| ("OpenAI Configuration", check_openai_key), | |
| ] | |
| results = [] | |
| for name, check_func in checks: | |
| print(f"\nπ Checking: {name}") | |
| print("-" * 60) | |
| try: | |
| result = check_func() | |
| results.append(result) | |
| except Exception as e: | |
| print(f"β Error during check: {e}") | |
| results.append(False) | |
| print("\n" + "=" * 60) | |
| if all(results): | |
| print("β All checks passed! You're ready to run the backend.") | |
| print("\nStart the server with:") | |
| print(" .\\run.bat") | |
| print("\nOr manually:") | |
| print(" .\\.venv\\Scripts\\activate") | |
| print(" uvicorn app.main:app --reload --host 0.0.0.0 --port 8000") | |
| else: | |
| print("β Some checks failed. Please fix the issues above.") | |
| print("\nQuick fixes:") | |
| print("1. Make sure .env file exists with your OpenAI API key") | |
| print("2. Install dependencies: pip install -r requirements.txt") | |
| print("3. Check SETUP_GUIDE.md for detailed instructions") | |
| print("=" * 60) | |
| if __name__ == "__main__": | |
| main() | |