-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
79 lines (66 loc) · 1.99 KB
/
start.py
File metadata and controls
79 lines (66 loc) · 1.99 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
#!/usr/bin/env python3
"""
Startup script for ContextAgent
"""
import os
import sys
import uvicorn
from dotenv import load_dotenv
def check_environment():
"""Check if required environment variables are set."""
load_dotenv()
required_vars = ["OPENAI_API_KEY"]
missing_vars = []
for var in required_vars:
if not os.getenv(var):
missing_vars.append(var)
if missing_vars:
print("❌ Missing required environment variables:")
for var in missing_vars:
print(f" - {var}")
print("\n💡 Please create a .env file with your API keys:")
print(" cp env.example .env")
print(" # Then edit .env and add your OpenAI API key")
return False
print("✅ Environment variables configured")
return True
def check_dependencies():
"""Check if required packages are installed."""
try:
import fastapi
import langchain
import openai
import chromadb
print("✅ All dependencies are installed")
return True
except ImportError as e:
print(f"❌ Missing dependency: {e}")
print("💡 Please install dependencies:")
print(" pip install -r requirements.txt")
return False
def main():
"""Main startup function."""
print("🚀 Starting ContextAgent...")
print("=" * 50)
# Check environment
if not check_environment():
sys.exit(1)
# Check dependencies
if not check_dependencies():
sys.exit(1)
print("\n🎯 Starting server...")
print("📖 API Documentation: http://localhost:8000/docs")
print("🔍 Health Check: http://localhost:8000/health")
print("🧪 Test Script: python test_api.py")
print("\nPress Ctrl+C to stop the server")
print("=" * 50)
# Start the server
uvicorn.run(
"app.main:app",
host="0.0.0.0",
port=8000,
reload=True,
log_level="info"
)
if __name__ == "__main__":
main()