CoolFace
Apppublic

Programmer140/Hackathon

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
run_backend.py46 linesDownload Raw Back to root
1#!/usr/bin/env python32"""3Script to run the FastAPI backend with proper error handling4"""5 6import os7import subprocess8import sys9from secure_config import validate_config10 11def main():12    """13    Main function to run the backend API14    """15    print("Starting AI Assistant Backend...")16 17    # Validate configuration before starting the server18    try:19        validate_config()20        print("Configuration validated successfully")21    except ValueError as e:22        print(f"Configuration error: {e}")23        print("Please make sure all required environment variables are set in your .env file")24        print("Required variables: GEMINI_API_KEY, COHERE_API_KEY, QDRANT_URL, QDRANT_API_KEY")25        sys.exit(1)26 27    # Display API endpoints info28    print("\nAPI Endpoints:")29    print("   GET  /           - Health check")30    print("   POST /chat       - Chat endpoint")31    print("\nExample request to /chat endpoint:")32    print('   curl -X POST "http://localhost:8000/chat" -H "Content-Type: application/json" -d \'{"query": "Your question here"}\'')33    print()34 35    # Run the FastAPI application36    try:37        # Using uvicorn to run the app38        subprocess.run([sys.executable, "-m", "uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000", "--reload"])39    except KeyboardInterrupt:40        print("\nServer stopped by user")41    except Exception as e:42        print(f"Error running server: {e}")43        sys.exit(1)44 45if __name__ == "__main__":46    main()