File size: 2,508 Bytes
b30f068
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""

Simple script to run the Agentic AI API server without Docker.

Just run: python run_api.py

"""

import sys
import os
from pathlib import Path

# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))

def check_dependencies():
    """Check if we have the required packages."""
    missing = []
    
    try:
        import fastapi
        print("βœ… FastAPI available")
    except ImportError:
        missing.append("fastapi")
    
    try:
        import uvicorn
        print("βœ… Uvicorn available")
    except ImportError:
        missing.append("uvicorn")
    
    try:
        import spacy
        nlp = spacy.load("en_core_web_sm")
        print("βœ… spaCy model available")
    except (ImportError, OSError):
        missing.append("spacy model")
    
    if missing:
        print(f"\\n❌ Missing: {', '.join(missing)}")
        print("\\nπŸ“¦ Install missing packages:")
        if "fastapi" in missing or "uvicorn" in missing:
            print("   pip install fastapi uvicorn python-multipart")
        if "spacy model" in missing:
            print("   python -m spacy download en_core_web_sm")
        return False
    
    return True

def main():
    """Run the API server."""
    print("πŸ€– Agentic AI System - Simple API Server")
    print("=" * 50)
    
    # Check dependencies
    if not check_dependencies():
        print("\\nπŸ’‘ Install dependencies first, then run again.")
        return
    
    print("\\nπŸš€ Starting API server...")
    print("πŸ“ Server: http://localhost:8000")
    print("πŸ“š Docs: http://localhost:8000/docs")
    print("❀️  Health: http://localhost:8000/health")
    print("\\nπŸ”‘ API Keys for testing:")
    print("   Demo: demo-key-12345")
    print("   Admin: admin-key-67890")
    print("\\nπŸ“ API Key Configuration:")
    print("   πŸ“„ Primary: config/api_keys.json")
    print("   πŸ”„ Fallback: api_server.py")
    print("   πŸ”§ Reload: POST /api-keys/reload (admin only)")
    print("\\n" + "=" * 50)
    
    # Import and run
    try:
        import uvicorn
        from api_server import app
        
        uvicorn.run(
            app,
            host="0.0.0.0",
            port=8000,
            log_level="info"
        )
    except KeyboardInterrupt:
        print("\\nπŸ›‘ Server stopped")
    except Exception as e:
        print(f"\\n❌ Error: {e}")

if __name__ == "__main__":
    main()