Spaces:
Running
Running
File size: 4,893 Bytes
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 | # Test RagBot API Endpoints
# Run this while the API server is running
$baseUrl = "http://localhost:8000"
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "RagBot API Test Suite" -ForegroundColor Cyan
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host ""
# Test 1: Root endpoint
Write-Host "Test 1: Root endpoint" -ForegroundColor Yellow
try {
$response = Invoke-RestMethod -Uri "$baseUrl/" -Method GET
Write-Host "β Root endpoint OK" -ForegroundColor Green
Write-Host " Version: $($response.version)" -ForegroundColor Gray
} catch {
Write-Host "β Failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 2: Health check
Write-Host "Test 2: Health check" -ForegroundColor Yellow
try {
$response = Invoke-RestMethod -Uri "$baseUrl/api/v1/health" -Method GET
Write-Host "β Health check OK" -ForegroundColor Green
Write-Host " Status: $($response.status)" -ForegroundColor Gray
Write-Host " RagBot: $($response.ragbot_initialized)" -ForegroundColor Gray
} catch {
Write-Host "β Failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 3: Biomarkers list
Write-Host "Test 3: Biomarkers list" -ForegroundColor Yellow
try {
$response = Invoke-RestMethod -Uri "$baseUrl/api/v1/biomarkers" -Method GET
Write-Host "β Biomarkers endpoint OK" -ForegroundColor Green
Write-Host " Total biomarkers: $($response.biomarkers.Count)" -ForegroundColor Gray
} catch {
Write-Host "β Failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 4: Example analysis
Write-Host "Test 4: Example analysis (diabetes case)" -ForegroundColor Yellow
try {
$response = Invoke-RestMethod -Uri "$baseUrl/api/v1/example" -Method GET
Write-Host "β Example endpoint OK" -ForegroundColor Green
Write-Host " Request ID: $($response.request_id)" -ForegroundColor Gray
Write-Host " Predicted disease: $($response.analysis.prediction.predicted_disease)" -ForegroundColor Gray
Write-Host " Confidence: $($response.analysis.prediction.confidence)" -ForegroundColor Gray
Write-Host " Processing time: $($response.processing_time_ms)ms" -ForegroundColor Gray
} catch {
Write-Host "β Failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 5: Structured analysis
Write-Host "Test 5: Structured analysis (POST)" -ForegroundColor Yellow
try {
$body = @{
biomarkers = @{
glucose = 180
hba1c = 8.2
ldl = 145
hdl = 35
triglycerides = 220
}
patient_context = @{
age = 55
gender = "male"
bmi = 28.5
}
} | ConvertTo-Json
$response = Invoke-RestMethod -Uri "$baseUrl/api/v1/analyze/structured" `
-Method Post `
-Body $body `
-ContentType "application/json"
Write-Host "β Structured analysis OK" -ForegroundColor Green
Write-Host " Request ID: $($response.request_id)" -ForegroundColor Gray
Write-Host " Predicted disease: $($response.analysis.prediction.predicted_disease)" -ForegroundColor Gray
Write-Host " Confidence: $($response.analysis.prediction.confidence)" -ForegroundColor Gray
Write-Host " Biomarker flags: $($response.analysis.biomarker_flags.Count)" -ForegroundColor Gray
Write-Host " Safety alerts: $($response.analysis.safety_alerts.Count)" -ForegroundColor Gray
} catch {
Write-Host "β Failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "Testing complete!" -ForegroundColor Cyan
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "For JavaScript/Fetch usage in your website:" -ForegroundColor Yellow
Write-Host ""
Write-Host @"
// Example: Fetch from your website
fetch('http://localhost:8000/api/v1/example')
.then(response => response.json())
.then(data => {
console.log('Predicted disease:', data.analysis.prediction.predicted_disease);
console.log('Confidence:', data.analysis.prediction.confidence);
console.log('Full response:', data);
})
.catch(error => console.error('Error:', error));
// Example: POST structured analysis
fetch('http://localhost:8000/api/v1/analyze/structured', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
biomarkers: {
glucose: 180,
hba1c: 8.2,
ldl: 145
},
patient_context: {
age: 55,
gender: 'male'
}
})
})
.then(response => response.json())
.then(data => console.log('Analysis:', data))
.catch(error => console.error('Error:', error));
"@ -ForegroundColor Gray
|