Spaces:
Running
Running
RagBot API - Getting Started (5 Minutes)
Follow these steps to get your API running in 5 minutes:
Prerequisites
Before starting, ensure you have:
Python 3.11+ installed
python --versionA free API key from one of:
- Groq β Recommended (fast, free LLaMA 3.3-70B)
- Google Gemini β Alternative
RagBot dependencies installed
# From RagBot root directory pip install -r requirements.txt.envconfigured in project root with your API key:GROQ_API_KEY=gsk_... LLM_PROVIDER=groq
π Step 1: Install API Dependencies (30 seconds)
# Navigate to api directory
cd C:\Users\admin\OneDrive\Documents\GitHub\RagBot\api
# Install FastAPI and dependencies
pip install -r requirements.txt
Expected output:
Successfully installed fastapi-0.109.0 uvicorn-0.27.0 ...
π Step 2: Start the API (10 seconds)
# Make sure you're in the api/ directory
python -m uvicorn app.main:app --reload --port 8000
Expected output:
INFO: Started server process
INFO: Waiting for application startup.
π Starting RagBot API Server
β
RagBot service initialized successfully
β
API server ready to accept requests
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000
β οΈ Wait 10-30 seconds for initialization (loading vector store)
β Step 3: Verify It's Working (30 seconds)
Option A: Use the Test Script
# In a NEW PowerShell window (keep API running)
cd C:\Users\admin\OneDrive\Documents\GitHub\RagBot\api
.\test_api.ps1
Option B: Manual Test
# Health check
curl http://localhost:8000/api/v1/health
# Get example analysis
curl http://localhost:8000/api/v1/example
Option C: Browser
Open: http://localhost:8000/docs
π Step 4: Test Your First Request (1 minute)
Test Natural Language Analysis
# PowerShell
$body = @{
message = "My glucose is 185 and HbA1c is 8.2"
patient_context = @{
age = 52
gender = "male"
}
} | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:8000/api/v1/analyze/natural" `
-Method Post -Body $body -ContentType "application/json"
Expected: JSON response with disease prediction, safety alerts, recommendations
π Step 5: Integrate with Your Backend (2 minutes)
Your Backend Code (Node.js/Express Example)
// backend/routes/analysis.js
const axios = require('axios');
app.post('/api/analyze', async (req, res) => {
try {
// Get user input from your frontend
const { biomarkerText, patientInfo } = req.body;
// Call RagBot API on localhost
const response = await axios.post('http://localhost:8000/api/v1/analyze/natural', {
message: biomarkerText,
patient_context: patientInfo
});
// Send results to your frontend
res.json(response.data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
Your Frontend Code (React Example)
// frontend/components/BiomarkerAnalysis.jsx
async function analyzeBiomarkers(userInput) {
// Call YOUR backend (which calls RagBot API)
const response = await fetch('/api/analyze', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
biomarkerText: userInput,
patientInfo: { age: 52, gender: 'male' }
})
});
const result = await response.json();
// Display results
console.log('Disease:', result.prediction.disease);
console.log('Confidence:', result.prediction.confidence);
console.log('Summary:', result.conversational_summary);
return result;
}
π Quick Reference
API Endpoints You'll Use Most:
Natural Language (Recommended)
POST /api/v1/analyze/natural Body: {"message": "glucose 185, HbA1c 8.2"}Structured (If you have exact values)
POST /api/v1/analyze/structured Body: {"biomarkers": {"Glucose": 185, "HbA1c": 8.2}}Health Check
GET /api/v1/health
π Troubleshooting
Issue: "Connection refused"
Problem: Ollama not running
Fix:
ollama serve
Issue: "Vector store not loaded"
Problem: Missing vector database
Fix:
cd C:\Users\admin\OneDrive\Documents\GitHub\RagBot
python scripts/setup_embeddings.py
Issue: "Port 8000 in use"
Problem: Another app using port 8000
Fix:
# Use different port
python -m uvicorn app.main:app --reload --port 8001
π Next Steps
- Read the docs: http://localhost:8000/docs
- Try all endpoints: See README.md
- Integrate: Connect your frontend to your backend
- Deploy: Use Docker when ready (docker-compose.yml)
π You're Done!
Your RagBot is now accessible via REST API at http://localhost:8000
Test it right now:
curl http://localhost:8000/api/v1/health
Need Help?
- Full docs: README.md
- Quick reference: QUICK_REFERENCE.md
- Implementation details: IMPLEMENTATION_COMPLETE.md
Have fun! π