File size: 5,066 Bytes
2532605 | 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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | # Complete Step-by-Step Testing Guide
## Part 1: Check Available Models
### Step 1: List all MLflow runs
Open a terminal and run:
```bash
python -c "
import mlflow
runs = mlflow.search_runs()
if runs:
for i, run in enumerate(runs):
print(f'{i+1}. Run ID: {run.info.run_id}')
print(f' Status: {run.info.status}')
artifacts = mlflow.artifacts.list_artifacts(run_id=run.info.run_id)
print(f' Has artifacts: {len(artifacts) > 0}')
print()
else:
print('No runs found!')
"
```
**What to look for:**
- Copy a run ID that has `status: FINISHED`
- Check if it has artifacts (models)
**If you see run IDs:** Go to Step 3
**If you see "No runs found!":** Go to Step 2
---
## Part 2: Train a New Model (If Needed)
### Step 2: Train the model
```bash
python ml/train.py
```
**What to expect:**
- Takes 2-5 minutes
- Prints: `Training complete! Run ID: ...`
- Copy that Run ID
---
## Part 3: Update Configuration
### Step 3: Update .env with the correct Run ID
Edit `.env` and replace the run ID:
```bash
KRONECTOR_MODEL_RUN_ID=<paste-the-run-id-here>
```
Example:
```
KRONECTOR_MODEL_RUN_ID=563634279953604033
```
**Save the file!**
### Step 4: Restart the API
If the API is running, stop it (Ctrl+C in the terminal).
Then restart:
```bash
python -m uvicorn api.main:app --reload
```
Wait for: `Uvicorn running on http://127.0.0.1:8000`
---
## Part 4: Test the API
### Step 5: Check Health Status
Open a new terminal and run:
```bash
curl http://localhost:8000/health
```
**Expected output:**
```json
{
"status": "healthy",
"model_loaded": true,
"data_available": true,
"version": "1.0.0"
}
```
**If `model_loaded` is still `false`:** The run ID is wrong. Go back to Step 1 and copy the correct ID.
### Step 6: List Available Drivers
```bash
curl "http://localhost:8000/drivers?season=2023"
```
**Expected output:**
```json
[
{"driver_id": "VER", "driver_name": "Max Verstappen", "team": "Red Bull"},
{"driver_id": "SAI", "driver_name": "Carlos Sainz", "team": "Ferrari"},
...
]
```
### Step 7: List Races
```bash
curl http://localhost:8000/races/2023
```
**Expected output:**
```json
[
{"season": 2023, "round": 1, "name": "Bahrain Grand Prix"},
{"season": 2023, "round": 2, "name": "Saudi Arabian Grand Prix"},
...
]
```
---
## Part 5: Test the Main Prediction
### Step 8: Natural Language Query (THE MAIN TEST)
```bash
curl -X POST http://localhost:8000/predict/f1 `
-H "Content-Type: application/json" `
-d '{"query": "What is Verstappens win probability at Monaco 2023?"}'
```
**Expected output:**
```json
{
"win_probability": 0.87,
"metadata": {
"season": 2023,
"round": 6,
"driver_id": "VER",
"driver_name": "Max Verstappen",
"team": "Red Bull",
"grid_position": 1
},
"shap_values": {
"grid_position": 0.45,
"previous_race_points": 0.23,
...
}
}
```
**If it works:** β
SUCCESS! The system is working!
---
## Part 6: Visual Testing (Easiest!)
### Step 9: Use the Interactive API Docs
Open your browser and visit:
```
http://localhost:8000/docs
```
**You'll see all 5 endpoints with:**
- Try it out buttons
- Example inputs
- Full responses
**Test order:**
1. Click `/health` β Execute (check model_loaded)
2. Click `/drivers` β Execute (see drivers)
3. Click `/races/{season}` β Enter "2023" β Execute
4. Click `/predict/f1` β Enter `{"query": "Verstappen Monaco 2023"}` β Execute
---
## Troubleshooting
### Problem: `model_loaded: false`
**Solution:**
1. Check you have the right run ID in `.env`
2. Verify the run exists: `python ml/train.py` to create a new one
3. Restart the API
### Problem: Query returns error 503
**Solution:**
- Model not loaded yet (see above)
- Check the API logs in the terminal for details
### Problem: `"query": "must be at least 3 characters"`
**Solution:**
- Make sure your query is longer than 3 characters
- Example: `"What is VER's win probability at Monaco?"` β
### Problem: `Race not found`
**Solution:**
- Check valid seasons: 2023 races are available
- Try: `"Verstappen Bahrain 2023"` instead
---
## Quick Test Commands (Copy & Paste)
```bash
# 1. Check health
curl http://localhost:8000/health
# 2. List drivers
curl "http://localhost:8000/drivers?season=2023"
# 3. List races
curl http://localhost:8000/races/2023
# 4. Make prediction
curl -X POST http://localhost:8000/predict/f1 `
-H "Content-Type: application/json" `
-d '{"query": "Verstappen Monaco 2023 win probability?"}'
# 5. Open interactive docs
start http://localhost:8000/docs
```
---
## Expected Results
| Test | Status | Output |
|------|--------|--------|
| Health check | β
| `model_loaded: true` |
| List drivers | β
| Array of drivers |
| List races | β
| Array of races |
| Prediction | β
| Win probability (0-1) + SHAP values |
---
## Success!
If all 4 tests pass, your system is fully functional! π
The API is ready to:
- Accept natural language F1 queries
- Return accurate win probabilities
- Explain predictions with SHAP values
|