MedPrompt: AI-Powered Medical Triage Assistant

MedPrompt is a sophisticated medical triage assistant powered by Large Language Models (LLMs) that analyzes patient-reported symptoms and provides evidence-based care recommendations. By combining advanced NLP capabilities with medical knowledge retrieval, MedPrompt helps users understand the potential severity of their symptoms and directs them to appropriate care pathways.
๐ Key Features
- Intelligent Symptom Analysis: Leverages MedLLaMA 2, a specialized medical LLM, to analyze and interpret complex symptom descriptions
- Evidence-Based Responses: Integrates with PubMed through a Retrieval-Augmented Generation (RAG) pipeline to provide medically accurate information
- Multi-Level Triage System: Classifies symptoms into five severity levels and recommends appropriate care pathways
- Responsive Web Interface: Clean, intuitive UI with real-time feedback and accessibility features
- Robust Error Handling: Gracefully manages connection issues, timeouts, and resource limitations
- Pediatric Symptom Recognition: Specialized patterns for recognizing and appropriately triaging children's symptoms
- Chronic Condition Management: Intelligent assessment of worsening chronic conditions like asthma, diabetes, and chronic pain
๐ฌ Technical Architecture
1. RAG (Retrieval-Augmented Generation) Pipeline
- Real-time PubMed Integration: Searches and retrieves relevant medical literature based on symptom descriptions
- Vector Embedding: Uses sentence-transformers to create semantic embeddings of medical texts
- FAISS Vector Store: Efficiently indexes and retrieves relevant medical information
- Context Enhancement: Augments LLM prompts with evidence-based medical information
- Fallback Mechanisms: Provides graceful degradation when external services are unavailable
2. Advanced Triage System
- Pattern-Based Classification: Uses sophisticated regex patterns to identify symptom severity
- Multi-Symptom Analysis: Intelligently parses and evaluates multiple symptoms simultaneously
- Severity Hierarchy: Implements a priority-based classification system that highlights the most urgent concerns
- Specialized Pattern Recognition: Contains over 100 medical patterns for accurate symptom classification
- Care Pathway Mapping: Maps severity levels to appropriate healthcare settings (Emergency Room, Urgent Care, etc.)
- Age-Appropriate Recommendations: Provides different guidance for pediatric vs. adult cases
3. LLM Integration
- Local Inference: Uses Ollama to run MedLLaMA 2 locally, ensuring privacy and reducing latency
- Optimized Prompting: Carefully crafted prompts that combine symptom information, triage results, and medical context
- Resource Management: Intelligent handling of memory constraints and timeout scenarios
- Response Formatting: Structured outputs with explanations, self-care advice, and warning signs
4. FastAPI Backend
- Asynchronous Processing: Handles multiple requests efficiently
- Robust Error Handling: Gracefully manages exceptions and provides helpful error messages
- Health Monitoring: Includes health check endpoints for system monitoring
- Static File Serving: Efficiently serves the frontend application
๐ Triage Classification System
MedPrompt classifies symptoms into five severity levels:
Severity Level | Description | Care Pathway | Example Symptoms |
---|
Emergency | Life-threatening conditions requiring immediate medical attention | Emergency Room | Severe chest pain, difficulty breathing, stroke symptoms |
Urgent | Serious conditions requiring prompt care within 24 hours | Urgent Care | High fever, persistent vomiting, moderate injuries |
Semi-Urgent | Conditions requiring care within 72 hours | Primary Care | Ear infections, mild sprains, worsening chronic conditions |
Routine | Non-urgent conditions requiring medical attention | Telehealth | Medication refills, mild symptoms, follow-up care |
Self-Care | Minor conditions that can be managed at home | Self-Management | Common cold, minor headaches, mild allergies |
๐ Installation & Setup
click to view
Prerequisites
- Python 3.8+
- Ollama (for local LLM inference)
- 8GB+ RAM recommended for optimal performance
Step 1: Clone the repository
git clone https://github.com/yourusername/medical_ai_symptom_checker.git
cd medical_ai_symptom_checker
Step 2: Install dependencies
pip install -r requirements.txt
Step 3: Set up Ollama with MedLLaMA 2
# Install Ollama from https://ollama.ai/
ollama pull medllama2
Step 4: Start the application
# For development with auto-reload
uvicorn app:app --host 0.0.0.0 --port 8000 --reload
# For production
python app.py
Step 5: Access the web interface
Open your browser and navigate to:
http://localhost:8000
๐งช Testing & Validation
Example Test Cases
Test the application with these symptom scenarios to evaluate its performance:
1. Mild Symptoms
- "I've had a mild cough for 2 days"
- "I have a slight headache and feel tired"
- "My skin is itchy but there's no rash"
2. Moderate Symptoms
- "I've had a fever of 101ยฐF for the past day with body aches"
- "My ankle is swollen after falling yesterday"
- "I've had diarrhea for 3 days but am still drinking fluids"
3. Severe Symptoms
- "I have a severe headache with fever and stiff neck"
- "I'm experiencing chest pain that radiates to my left arm"
- "I can't catch my breath and my lips look bluish"
4. Chronic Conditions
- "My asthma symptoms have been worse than usual for a week"
- "I've had persistent lower back pain for 3 months"
- "My blood sugar readings have been higher than normal for several days"
5. Pediatric Symptoms
- "My 2-year-old has had a fever of 102ยฐF for 24 hours"
- "My child has a rash that doesn't blanch when pressed"
- "My baby seems lethargic and isn't feeding normally"
๐ Project Structure
click to view
medical_ai_symptom_checker/
โโโ app.py # FastAPI application with main routes and LLM integration
โโโ pubmed_rag.py # RAG pipeline for PubMed data retrieval and processing
โโโ triage_agent.py # Decision tree-based triage classification system
โโโ requirements.txt # Project dependencies
โโโ static/ # Frontend files
โ โโโ index.html # Main HTML page with embedded CSS and JavaScript
โ โโโ style.css # CSS styles (placeholder)
โ โโโ script.js # JavaScript functionality (placeholder)
โโโ pubmed_cache/ # Cache directory for PubMed data
๐ง Advanced Configuration
click to view
Memory Optimization
For systems with limited RAM, you can adjust these parameters in app.py:
# Reduce token generation to prevent timeouts
"num_predict": 256,
# Reduce context size to help with memory issues
"num_ctx": 2048,
# Use GPU if available
"num_gpu": 1
Timeout Settings
Adjust the timeout value based on your system's performance:
# Reduce timeout for faster feedback on slow systems
timeout=15 # seconds
PubMed API Configuration
Set your email for the PubMed API in pubmed_rag.py:
# Set your email for Entrez (required by NCBI)
Entrez.email = "your-email@example.com"
โ ๏ธ Medical Disclaimer
IMPORTANT: MedPrompt is designed for informational purposes only and does not provide medical diagnosis, advice, or treatment. The triage recommendations are based on pattern matching and AI analysis, which may not capture all medical nuances or individual circumstances.
Always consult with a qualified healthcare provider for medical concerns. In case of emergency, call emergency services (911 in the US) or go to your nearest emergency room immediately.
๐ฅ Contributors
- Utsav Mishra - Initial development and design
๐ Acknowledgments

