Repository navigation
Expand file tree
/
Copy pathrun_ui.py
More file actions
executable file
·121 lines (100 loc) · 3.47 KB
/
Copy pathrun_ui.py
File metadata and controls
executable file
·121 lines (100 loc) · 3.47 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
#!/usr/bin/env python3
"""Launch script for the Agentic RAG UI."""
import subprocess
import sys
import time
import webbrowser
import os
def check_services():
"""Pre-flight check for required services."""
print("🔍 Checking services...")
# Check if .env exists
if not os.path.exists(".env"):
print(" ⚠️ .env file not found")
print(" Copy .env.example to .env and configure it")
return False
# Check Elasticsearch
try:
from agentic_rag.config import get_config
from agentic_rag.elasticsearch_client import get_elasticsearch_client
config = get_config()
es_client = get_elasticsearch_client(
config.elasticsearch_url, config.elasticsearch_api_key
)
es_client.info()
print(" ✅ Elasticsearch connected")
except Exception as e:
print(f" ❌ Elasticsearch not available: {e}")
print(" Run: docker-compose up -d")
return False
# Check SpiceDB
try:
from agentic_rag.grpc_helpers import get_spicedb_client
spicedb_client = get_spicedb_client(config.spicedb_endpoint, config.spicedb_token)
print(" ✅ SpiceDB connected")
except Exception as e:
print(f" ❌ SpiceDB not available: {e}")
print(" Run: docker-compose up -d")
return False
# Check Mistral key
if not config.mistral_api_key or config.mistral_api_key == "your-mistral-api-key-here":
print(" ❌ MISTRAL_API_KEY not configured")
print(" Set it in .env file")
return False
print(" ✅ Mistral API key configured")
# Check if documents are loaded
try:
if es_client.indices.exists(index="documents"):
count = es_client.count(index="documents")["count"]
if count > 0:
print(" ✅ Documents loaded in Elasticsearch")
else:
print(" ⚠️ No documents found in Elasticsearch")
print(" Run: python examples/setup_environment.py")
return False
else:
print(" ⚠️ documents index does not exist in Elasticsearch")
print(" Run: python examples/setup_environment.py")
return False
except Exception as e:
print(f" ⚠️ Could not verify documents: {e}")
return True
def main():
"""Launch the UI."""
print("🚀 Agentic RAG UI Launcher")
print("=" * 50)
if not check_services():
print("\n❌ Pre-flight checks failed. Please fix the issues above.")
sys.exit(1)
print("\n✅ All services ready!")
print("\n🌐 Starting FastAPI server...")
print(" URL: http://localhost:8000")
print(" API Docs: http://localhost:8000/docs")
print(" Press Ctrl+C to stop\n")
# Open browser after 2 seconds
def open_browser():
time.sleep(2)
print("🌐 Opening browser...")
webbrowser.open("http://localhost:8000")
import threading
threading.Thread(target=open_browser, daemon=True).start()
# Start uvicorn
try:
subprocess.run(
[
sys.executable,
"-m",
"uvicorn",
"api.main:app",
"--host",
"0.0.0.0",
"--port",
"8000",
"--reload",
]
)
except KeyboardInterrupt:
print("\n\n👋 Shutting down...")
sys.exit(0)
if __name__ == "__main__":
main()