Spaces:
Sleeping
Sleeping
File size: 4,058 Bytes
600f3a7 | 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | """
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()
|