-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_server.py
More file actions
44 lines (39 loc) · 1.43 KB
/
start_server.py
File metadata and controls
44 lines (39 loc) · 1.43 KB
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
#!/usr/bin/env python3
"""
Simple script to start the FastAPI server.
"""
import os
from pathlib import Path
from dotenv import load_dotenv
import uvicorn
from logging_config import get_logger
logger = get_logger(__name__)
# Load environment variables from .env file
env_path = Path(__file__).parent / ".env"
if env_path.exists():
load_dotenv(env_path)
logger.info(f"Loaded environment variables from {env_path}")
else:
# Try loading from parent directory
load_dotenv()
logger.info("Loaded environment variables from .env (if exists)")
# Check for required environment variables
if not os.getenv("OPENAI_API_KEY"):
logger.warning("OPENAI_API_KEY is not set. CrewAI requires this to function.")
logger.warning("Create a .env file with OPENAI_API_KEY=your-key-here")
logger.warning("See env.example for reference")
if __name__ == "__main__":
# Cloud Run injects PORT; default to 8000 locally
port = int(os.getenv("PORT", "8000"))
# Allow disabling reload for production by setting DISABLE_RELOAD=1
reload = os.getenv("DISABLE_RELOAD", "").lower() not in ("1", "true", "yes")
if not reload:
logger.info("Starting server without auto-reload (production mode)")
else:
logger.info("Starting server with auto-reload enabled (development mode). Set DISABLE_RELOAD=1 to disable.")
uvicorn.run(
"api.server:app",
host="0.0.0.0",
port=port,
reload=reload
)