-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_contextus.py
More file actions
204 lines (175 loc) Β· 6.55 KB
/
setup_contextus.py
File metadata and controls
204 lines (175 loc) Β· 6.55 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python3
"""
Contextus Setup Script for ScribeMD
Helps you get started with Contextus AI Second Brain integration
"""
import os
import requests
import json
from dotenv import load_dotenv
def setup_contextus():
"""
Interactive setup for Contextus integration.
"""
print("π€ Contextus AI Second Brain Setup for ScribeMD")
print("=" * 60)
# Load environment variables
load_dotenv()
# Get collection ID
collection_id = os.getenv("CONTEXTUS_COLLECTION_ID")
if not collection_id:
print("β CONTEXTUS_COLLECTION_ID not found in environment variables")
print("\nπ Setup Steps:")
print("1. Go to https://www.contextus.space/login")
print("2. Create a new Collection")
print("3. Copy the Collection ID")
print("4. Add it to your .env file:")
print(" echo 'CONTEXTUS_COLLECTION_ID=your-collection-id-here' >> .env")
print("\nπ Run this script again after setting up your Collection ID")
return False
print(f"β
Found Collection ID: {collection_id}")
# Test connection
print("\nπ Testing Contextus connection...")
try:
response = requests.get(f"https://www.contextus.space/v1/catalog?collection_id={collection_id}")
if response.status_code == 200:
print("β
Connection successful!")
else:
print(f"β Connection failed: {response.status_code}")
return False
except Exception as e:
print(f"β Connection error: {e}")
return False
# Create a test project
print("\nποΈ Creating test project...")
try:
project_data = {
"collection_id": collection_id,
"label": "ScribeMD Test Project",
"metadata": {
"app": "ScribeMD",
"version": "1.0",
"description": "Medical billing automation with AI Second Brain"
},
"artifacts": [{
"type": "setup",
"title": "Initial Setup",
"data": {
"setup_date": "2024-01-01",
"features": [
"AI-powered transcript processing",
"Medical code generation",
"Context-aware learning",
"Patient-specific AI agents"
]
}
}]
}
response = requests.post("https://www.contextus.space/v1/projects", json=project_data)
if response.status_code == 200:
result = response.json()
project_id = result.get("project_id")
print(f"β
Test project created: {project_id}")
# Save project ID to .env
with open(".env", "a") as f:
f.write(f"\nCONTEXTUS_TEST_PROJECT_ID={project_id}\n")
print(f"β
Project ID saved to .env file")
return True
else:
print(f"β Failed to create project: {response.status_code}")
print(f"Response: {response.text}")
return False
except Exception as e:
print(f"β Error creating project: {e}")
return False
def test_ai_agent():
"""
Test the AI agent functionality.
"""
print("\nπ§ Testing AI Agent...")
load_dotenv()
project_id = os.getenv("CONTEXTUS_TEST_PROJECT_ID")
collection_id = os.getenv("CONTEXTUS_COLLECTION_ID")
if not project_id or not collection_id:
print("β Missing project or collection ID")
return False
try:
# Test query
response = requests.post(
f"https://www.contextus.space/v1/projects/{project_id}/query",
json={"q": "What is this project about?"}
)
if response.status_code == 200:
result = response.json()
print(f"β
AI Agent Response: {result.get('response', 'No response')}")
return True
else:
print(f"β AI Agent test failed: {response.status_code}")
return False
except Exception as e:
print(f"β AI Agent test error: {e}")
return False
def show_integration_guide():
"""
Show integration guide for using Contextus with ScribeMD.
"""
print("\nπ Integration Guide")
print("=" * 60)
print("1. Enhanced API Endpoints:")
print(" POST /api/enhanced-generate-claim")
print(" GET /api/patient-context/<patient_id>")
print(" POST /api/ai-agent-query")
print(" GET /api/ai-insights/<patient_id>")
print("\n2. Key Features:")
print(" β
AI Second Brain for each patient")
print(" β
Context-aware medical coding")
print(" β
Learning from historical data")
print(" β
AI agent queries")
print(" β
Intelligent insights")
print("\n3. Usage Example:")
print("""
# Enhanced claim generation
curl -X POST http://localhost:5000/api/enhanced-generate-claim \\
-H "Content-Type: application/json" \\
-d '{
"transcript": "Doctor: Good morning, John. What brings you in today?",
"form_type": "cms1500",
"patient_id": "patient_123",
"patient_name": "John Doe",
"doctor_id": "doctor_456"
}'
# Query AI agent
curl -X POST http://localhost:5000/api/ai-agent-query \\
-H "Content-Type: application/json" \\
-d '{
"query": "What are the most common diagnoses for this patient?",
"patient_id": "patient_123"
}'
""")
print("\n4. Next Steps:")
print(" - Run: python src/contextus_enhanced_app.py")
print(" - Test the enhanced endpoints")
print(" - Integrate with your frontend")
print(" - Customize AI agents for your needs")
def main():
"""
Main setup function.
"""
print("π Starting Contextus setup...")
# Setup Contextus
if setup_contextus():
print("\nβ
Contextus setup completed successfully!")
# Test AI agent
if test_ai_agent():
print("β
AI Agent test passed!")
else:
print("β οΈ AI Agent test failed, but setup is complete")
# Show integration guide
show_integration_guide()
print("\nπ You're ready to use Contextus with ScribeMD!")
print("Run: python src/contextus_enhanced_app.py")
else:
print("\nβ Setup failed. Please check the error messages above.")
print("Make sure you have a valid Contextus Collection ID.")
if __name__ == "__main__":
main()