-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_api.py
More file actions
149 lines (125 loc) · 7.32 KB
/
run_api.py
File metadata and controls
149 lines (125 loc) · 7.32 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
"""
AgentOps API Server Entry Point
This starts the complete AgentOps system:
1. FastAPI server (API layer)
2. Ray engine (distributed processing) - if available
3. EventBus (real-time event streaming)
Architecture:
┌─────────────────────────────────────────────────────────────┐
│ API Layer (FastAPI) │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ REST API │ │ WebSocket │ │ File Upload │ │
│ │ /api/* │ │ /api/ws │ │ /api/upload │ │
│ └──────┬──────┘ └──────┬──────┘ └──────────┬──────────┘ │
│ │ │ │ │
│ └────────────────┼─────────────────────┘ │
│ │ │
│ ┌─────▼─────┐ │
│ │ EventBus │ (Real-time events) │
│ └─────┬─────┘ │
└──────────────────────────┼───────────────────────────────────┘
│
┌──────────────────────────▼───────────────────────────────────┐
│ Engine Layer (Ray) │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Orchestrator│──│ SubMasters │──│ Workers │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Mapper │ │ MasterAgent │ │ Report Generator │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
└───────────────────────────────────────────────────────────────┘
Run with: python run_api.py
"""
import logging
import sys
import os
# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import uvicorn
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(levelname)-8s | %(name)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger("AgentOps")
def print_banner():
"""Print startup banner."""
banner = """
╔═══════════════════════════════════════════════════════════════╗
║ ║
║ █████╗ ██████╗ ███████╗███╗ ██╗████████╗ ██████╗ ██████╗███████╗
║ ██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
║ ███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║ ██║ ██║██████╔╝███████╗
║ ██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║ ██║ ██║██╔═══╝ ╚════██║
║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║ ╚██████╔╝██║ ███████║
║ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝
║ ║
║ Document Processing Engine ║
╚═══════════════════════════════════════════════════════════════╝
"""
print(banner)
def check_dependencies():
"""Check and report on available dependencies."""
deps = {
"ray": False,
"fastapi": False,
"uvicorn": False,
"pydantic": False,
}
try:
import ray
deps["ray"] = f"v{ray.__version__}"
except ImportError:
deps["ray"] = "NOT INSTALLED (distributed processing disabled)"
try:
import fastapi
deps["fastapi"] = f"v{fastapi.__version__}"
except ImportError:
deps["fastapi"] = "NOT INSTALLED"
try:
import uvicorn
deps["uvicorn"] = f"v{uvicorn.__version__}"
except ImportError:
deps["uvicorn"] = "NOT INSTALLED"
try:
import pydantic
deps["pydantic"] = f"v{pydantic.__version__}"
except ImportError:
deps["pydantic"] = "NOT INSTALLED"
print("\n📦 Dependencies:")
for name, status in deps.items():
icon = "✅" if not isinstance(status, str) or "NOT" not in status else "⚠️"
print(f" {icon} {name}: {status}")
print()
def main():
"""Start the FastAPI server with the AgentOps engine."""
print_banner()
check_dependencies()
host = os.getenv("API_HOST", "0.0.0.0")
port = int(os.getenv("API_PORT", "8000"))
reload = os.getenv("API_RELOAD", "false").lower() == "true"
print("🚀 Starting AgentOps Server...")
print(f" Host: {host}")
print(f" Port: {port}")
print(f" Reload: {reload}")
print()
print("📡 Endpoints:")
print(f" API Documentation: http://{host}:{port}/docs")
print(f" Health Check: http://{host}:{port}/health")
print(f" Upload PDF: POST http://{host}:{port}/api/upload")
print(f" Start Pipeline: POST http://{host}:{port}/api/pipeline/start")
print(f" WebSocket Events: ws://{host}:{port}/api/ws")
print()
print("=" * 60)
uvicorn.run(
"api.main:app",
host=host,
port=port,
reload=reload,
log_level="info",
)
if __name__ == "__main__":
main()