/ start_ai_proxy_fixed.py
start_ai_proxy_fixed.py
1 #!/usr/bin/env python3 2 """ 3 FIXED AI PROXY - No port conflicts 4 """ 5 6 import os 7 import sys 8 from fastapi import FastAPI 9 import uvicorn 10 11 # Kill anything on port 8345 first 12 os.system("fuser -k 8345/tcp 2>/dev/null") 13 os.system("pkill -f 'python.*8345' 2>/dev/null") 14 15 app = FastAPI() 16 17 @app.get("/") 18 def root(): 19 return { 20 "service": "AI Proxy Orchestrator", 21 "port": 8345, 22 "status": "running", 23 "endpoints": { 24 "/": "this page", 25 "/health": "health check", 26 "/orchestrate/{text}": "orchestrate AI query", 27 "/test": "test endpoint" 28 } 29 } 30 31 @app.get("/health") 32 def health(): 33 return {"healthy": True, "timestamp": "now"} 34 35 @app.get("/test") 36 def test(): 37 return {"message": "✅ AI Proxy is working!"} 38 39 @app.get("/orchestrate/{prompt}") 40 def orchestrate(prompt: str): 41 return { 42 "prompt": prompt, 43 "response": f"AI Response to: {prompt}", 44 "source": "AI Proxy v2.0" 45 } 46 47 if __name__ == "__main__": 48 print("=" * 50) 49 print("🤖 AI PROXY STARTING ON PORT 8345") 50 print("=" * 50) 51 print("✅ Web UI: http://localhost:8345") 52 print("✅ Health: http://localhost:8345/health") 53 print("✅ Test: http://localhost:8345/test") 54 print("=" * 50) 55 56 try: 57 uvicorn.run(app, host="0.0.0.0", port=8345, log_level="info") 58 except OSError as e: 59 if "address already in use" in str(e): 60 print(f"❌ ERROR: Port 8345 is already in use!") 61 print("Run this command to fix:") 62 print(" sudo lsof -ti:8345 | xargs kill -9") 63 sys.exit(1) 64 else: 65 raise