File size: 4,644 Bytes
6dc9d46
 
 
 
 
 
 
 
aefac4f
6dc9d46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aefac4f
6dc9d46
aefac4f
 
 
 
6dc9d46
 
 
 
 
aefac4f
6dc9d46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aefac4f
6dc9d46
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
# RagBot API - Quick Reference

## πŸš€ Quick Start Commands

### Start API (Local)
```powershell
# From api/ directory
cd C:\Users\admin\OneDrive\Documents\GitHub\RagBot\api
..\.\.venv\Scripts\python.exe -m uvicorn app.main:app --reload --port 8000
```

### Start API (Docker)
```powershell
# From api/ directory
docker-compose up --build
```

### Test API
```powershell
# Run test suite
.\test_api.ps1

# Or manual test
curl http://localhost:8000/api/v1/health
```

---

## πŸ“‘ Endpoints Cheat Sheet

| Method | Endpoint | Purpose |
|--------|----------|---------|
| GET | `/api/v1/health` | Check API status |
| GET | `/api/v1/biomarkers` | List all 24 biomarkers |
| POST | `/api/v1/analyze/natural` | Natural language analysis |
| POST | `/api/v1/analyze/structured` | Structured JSON analysis |
| GET | `/api/v1/example` | Pre-run diabetes example |
| GET | `/docs` | Swagger UI documentation |

---

## πŸ’» Integration Snippets

### JavaScript/Fetch
```javascript
const response = await fetch('http://localhost:8000/api/v1/analyze/natural', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    message: "My glucose is 185 and HbA1c is 8.2",
    patient_context: {age: 52, gender: "male"}
  })
});
const result = await response.json();
console.log(result.prediction.disease); // "Diabetes"
```

### PowerShell
```powershell
$body = @{
    biomarkers = @{Glucose = 185; HbA1c = 8.2}
    patient_context = @{age = 52; gender = "male"}
} | ConvertTo-Json

$result = Invoke-RestMethod -Uri "http://localhost:8000/api/v1/analyze/structured" `
    -Method Post -Body $body -ContentType "application/json"

Write-Host $result.prediction.disease
```

### Python
```python
import requests

response = requests.post('http://localhost:8000/api/v1/analyze/structured', json={
    'biomarkers': {'Glucose': 185.0, 'HbA1c': 8.2},
    'patient_context': {'age': 52, 'gender': 'male'}
})
result = response.json()
print(result['prediction']['disease'])  # Diabetes
```

---

## πŸ”§ Troubleshooting Quick Fixes

### API won't start
```powershell
# Check if port 8000 is in use
netstat -ano | findstr :8000

# Kill process if needed
taskkill /PID <PID> /F
```

### LLM provider errors
```powershell
# Check your .env has the right keys
# Default provider is Groq (GROQ_API_KEY required)
# Alternative: Google Gemini (GOOGLE_API_KEY)
# Optional: Ollama (local, no key needed)
```

### Vector store not loading
```powershell
# From RagBot root
.\.venv\Scripts\python.exe scripts/setup_embeddings.py
```

---

## πŸ“Š Response Fields Overview

**Key Fields You'll Use:**
- `prediction.disease` - Predicted disease name
- `prediction.confidence` - Confidence score (0-1)
- `analysis.safety_alerts` - Critical warnings
- `analysis.biomarker_flags` - All biomarker statuses
- `analysis.recommendations.immediate_actions` - What to do
- `conversational_summary` - Human-friendly text for display

**Full Data Access:**
- `agent_outputs` - Raw agent execution data
- `analysis.disease_explanation.citations` - Medical literature sources
- `workflow_metadata` - Execution details

---

## 🎯 Common Use Cases

### 1. Chatbot Integration
```javascript
// User types: "my glucose is 140"
const response = await analyzeNatural(userMessage);
displayResult(response.conversational_summary);
```

### 2. Form-Based Input
```javascript
// User fills form with biomarker values
const response = await analyzeStructured({
  biomarkers: formData,
  patient_context: patientInfo
});
showAnalysis(response.analysis);
```

### 3. Dashboard Display
```javascript
// Fetch and display example
const example = await fetch('/api/v1/example').then(r => r.json());
renderDashboard(example);
```

---

## πŸ” Production Checklist

Before deploying to production:

- [ ] Update CORS in `.env` (restrict to your domain)
- [ ] Add API key authentication
- [ ] Enable HTTPS
- [ ] Set up rate limiting
- [ ] Configure logging (rotate logs)
- [ ] Add monitoring/alerts
- [ ] Test error handling
- [ ] Document API for your team

---

## πŸ“ž Support

- **API Docs:** http://localhost:8000/docs
- **Main README:** [api/README.md](README.md)
- **RagBot Docs:** [../docs/](../docs/)

---

## πŸŽ“ Example Requests

### Simple Test
```bash
curl http://localhost:8000/api/v1/health
```

### Full Analysis
```bash
curl -X POST http://localhost:8000/api/v1/analyze/natural \
  -H "Content-Type: application/json" \
  -d '{"message": "glucose 185, HbA1c 8.2", "patient_context": {"age": 52, "gender": "male"}}'
```

### Get Example
```bash
curl http://localhost:8000/api/v1/example
```

---

**Last Updated:** February 2026  
**API Version:** 1.0.0