File size: 2,045 Bytes
476e500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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()