File size: 2,854 Bytes
83c84e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# API Reference — DDI Checker

REST API served by `app.py` on port 7860.

---

## Endpoints

| Method | Path | Description |
|---|---|---|
| GET | `/` | Landing page |
| GET | `/checker` | DDI Checker UI |
| GET | `/chat` | Chat interface |
| GET | `/results` | Model performance page |
| GET | `/responsible` | Responsible ML page (RM1–RM4) |
| GET | `/dashboard` | Live dashboard |
| GET | `/about` | About page |
| GET | `/health` | Liveness / readiness check |
| GET | `/api/stats` | Live stats (queries, hit rate, top pairs) |
| POST | `/api/check` | Check a single drug pair |
| POST | `/api/check/batch` | Check up to 50 pairs |
| POST | `/api/check/compare` | Side-by-side dict vs GNN comparison |
| POST | `/api/chat` | Chat endpoint (NER → lookup → explanation) |
| GET | `/api/drug/search?q=<query>&limit=<n>` | Drug name autocomplete |

---

## `POST /api/check`

**Request:**
```json
{ "drug_a": "Warfarin", "drug_b": "Aspirin" }
```
Accepts drug names **or** DrugBank IDs (`DB00682`). Case-insensitive.

**Response:**
```json
{
  "drug_a": { "query": "Warfarin", "resolved": "Warfarin", "id": "DB00682" },
  "drug_b": { "query": "Aspirin",  "resolved": "Acetylsalicylic acid", "id": "DB00945" },
  "source":  "documented",
  "found":   true,
  "interaction_description": "Acetylsalicylic acid may increase the anticoagulant activities...",
  "gnn":     null,
  "error":   null
}
```

**`source` values:**
| Value | Meaning |
|---|---|
| `"documented"` | Pair found in DrugBank (O(1) dict lookup) |
| `"gnn_predicted"` | Novel pair — GNN link prediction above threshold |
| `"not_found"` | Not in DrugBank; GNN score below threshold |
| `"drug_not_found"` | Drug name could not be resolved |

---

## `POST /api/check/batch`

**Request:**
```json
{
  "pairs": [
    { "drug_a": "Warfarin", "drug_b": "Aspirin" },
    { "drug_a": "Metformin", "drug_b": "Lisinopril" }
  ]
}
```
Max 50 pairs per request.

**Response:**
```json
{ "results": [ { /* same structure as /api/check */ }, ... ] }
```

---

## `GET /api/drug/search`

```
GET /api/drug/search?q=war&limit=5
```

Returns a list of drug name suggestions for autocomplete:
```json
[
  { "name": "Warfarin", "id": "DB00682" },
  ...
]
```

---

## `GET /health`

```json
{ "status": "ok", "model_loaded": true, "drugs_loaded": 4795 }
```

---

## `GET /api/stats`

Live dashboard metrics:
```json
{
  "total_queries": 142,
  "documented_hits": 89,
  "gnn_predictions": 31,
  "not_found": 22,
  "avg_latency_ms": 14.2,
  "top_pairs": [ ... ]
}
```

---

## Authentication

No authentication required. The API is public and read-only.
`GROQ_API_KEY` is required server-side for `/api/chat` (NER + explanation); all other endpoints work without it.

---

*For pipeline details see [pipeline.md](pipeline.md). For model details see [model_architecture.md](model_architecture.md).*