researcher / dev_run.py
sccastillo's picture
update
476e500
#!/usr/bin/env python3
"""
Development runner for the FastAPI TextGen application.
This script helps run the application locally with development configurations.
"""
import os
import sys
import uvicorn
from pathlib import Path
def setup_environment():
"""Setup environment variables for local development."""
# Check if .env file exists
env_file = Path(".env")
if not env_file.exists():
print("⚠️ No .env file found!")
print("📝 Please create a .env file with the following content:")
print()
print("OPENAI_API_KEY=your_openai_api_key_here")
print()
# Ask user if they want to continue with environment variable
openai_key = os.getenv("OPENAI_API_KEY")
if not openai_key:
print("❌ OPENAI_API_KEY environment variable not set either.")
print("Please either:")
print("1. Create a .env file with OPENAI_API_KEY=your_key")
print("2. Set the environment variable: export OPENAI_API_KEY=your_key")
sys.exit(1)
else:
print("✅ Found OPENAI_API_KEY in environment variables")
else:
print("✅ Found .env file")
def main():
"""Main function to run the development server."""
print("🚀 Starting FastAPI TextGen Development Server")
print("=" * 50)
# Setup environment
setup_environment()
print("🔧 Development server starting...")
print("📍 API will be available at: http://localhost:8000")
print("📚 API documentation at: http://localhost:8000/docs")
print("🔄 Auto-reload enabled for development")
print()
print("Press Ctrl+C to stop the server")
print("=" * 50)
# Run the development server
try:
uvicorn.run(
"app:app",
host="127.0.0.1",
port=8000,
reload=True,
log_level="info"
)
except KeyboardInterrupt:
print("\n👋 Development server stopped")
if __name__ == "__main__":
main()