forked from atharv1945/Context
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_api.py
More file actions
49 lines (40 loc) Β· 1.6 KB
/
start_api.py
File metadata and controls
49 lines (40 loc) Β· 1.6 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
#!/usr/bin/env python3
"""
Startup script for the Context Search API.
This script ensures the database is initialized before starting the API server.
"""
import sys
import os
# Add the current directory to Python path so we can import our modules
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def main():
"""Start the API server with proper initialization."""
print("π Starting Context Search API Server")
print("=" * 50)
# Import and initialize the database manager to ensure it's ready
try:
from src.database_manager import COLLECTION, CLIENT
if CLIENT is None or COLLECTION is None:
print("β Database initialization failed. Please check your ChromaDB setup.")
return
print("β
Database initialized successfully")
except Exception as e:
print(f"β Error initializing database: {e}")
return
# Import and start the API server
try:
import uvicorn
from api_server import app
print("β
API server ready")
print("π Server will be available at: http://127.0.0.1:8000")
print("π API documentation at: http://127.0.0.1:8000/docs")
print("π Test the API with: python test_api.py")
print("\nPress Ctrl+C to stop the server")
print("=" * 50)
uvicorn.run(app, host="127.0.0.1", port=8000, log_level="info")
except KeyboardInterrupt:
print("\nπ Server stopped by user")
except Exception as e:
print(f"β Error starting API server: {e}")
if __name__ == "__main__":
main()