A web application for testing and comparing biases across different language models. This tool helps students and researchers explore how various LLMs respond to bias-sensitive prompts, aligned with the "Biases in AI" lecture materials.
- Multi-Model Comparison: Query multiple LLMs simultaneously and compare responses side-by-side
- Flexible LLM Support: Works with both API-based models (OpenAI, Anthropic) and local models (LM Studio, Ollama)
- Pre-Built Bias Tests: Curated prompts covering gender bias, professional bias, cultural bias, and more
- Visual Analysis: Automatic highlighting of gendered pronouns and bias indicators
- Export Capabilities: Save results as CSV or JSON for further analysis in Pandas/Jupyter
- No Authentication Required: Simple setup for educational environments
app/
├── backend/ # FastAPI backend
│ ├── main.py # Application entry point
│ ├── config.py # Configuration management
│ ├── models/ # Pydantic schemas
│ ├── services/ # LLM adapters and orchestrator
│ ├── api/ # API endpoints
│ └── utils/ # Utility functions
├── frontend/ # Vanilla JavaScript frontend
│ ├── index.html # Main UI
│ └── js/ # JavaScript modules
├── config/ # Configuration files
│ ├── default_models.json # Model definitions
│ └── bias_test_prompts.json # Pre-built test prompts
└── requirements.txt # Python dependencies
- Python 3.9 or higher
- (Optional) API keys for cloud-based models
- (Optional) Local LLM server (LM Studio or Ollama)
cd /Users/baptistegregorutti/Documents/Repositories/gitlab/introduction-to-ai/appcd backend
uv sync
source .venv/bin/activateCopy the example environment file:
cp .env.example .envEdit .env and add your API keys (if using cloud models):
# Optional: Add API keys if using cloud-based models
OPENAI_API_KEY=sk-your-openai-api-key-here
ANTHROPIC_API_KEY=sk-ant-your-anthropic-api-key-here
# Optional: Configure local model endpoints
LM_STUDIO_ENDPOINT=http://localhost:1234/v1
OLLAMA_ENDPOINT=http://localhost:11434/v1Start the FastAPI backend server:
cd backend
python main.pyOr using uvicorn directly:
uvicorn backend.main:app --reload --port 8000The application will be available at:
- Frontend: http://localhost:8000/
- API Documentation: http://localhost:8000/docs
- API Endpoints: http://localhost:8000/api/
-
Add your API keys to
.env:OPENAI_API_KEY=sk-... ANTHROPIC_API_KEY=sk-ant-...
-
Start the backend (API keys will be auto-detected)
-
Select cloud models in the web interface
-
Download and install LM Studio
-
Load a model in LM Studio (e.g., Llama 2, Mistral, etc.)
-
Start the local server in LM Studio:
- Go to "Local Server" tab
- Click "Start Server"
- Note the endpoint (default: http://localhost:1234/v1)
-
Update
.envif using a different endpoint:LM_STUDIO_ENDPOINT=http://localhost:1234/v1
-
Start the backend and select "LM Studio (Local)" in the interface
-
Install Ollama
-
Pull a model:
ollama pull llama2 ollama pull mistral
-
Ollama runs on http://localhost:11434 by default
-
Start the backend and select Ollama models in the interface
-
Open the Application: Navigate to http://localhost:8000/
-
Select Models: Check the boxes for models you want to compare
- Green checkboxes = Available models
- Red "(Unavailable)" = Missing API key or endpoint not configured
-
Choose a Test:
- Click a pre-built bias test button, OR
- Enter your own custom prompt
-
Adjust Temperature (optional):
- 0.0 = More deterministic
- 2.0 = More creative/random
-
Click "Compare Models": Wait for results to load
-
Analyze Results:
- View responses side-by-side
- Gendered pronouns are highlighted in yellow
- Gender-specific terms are highlighted in pink
-
Export Data (optional):
- Click "Export CSV" for Pandas analysis
- Click "Export JSON" for programmatic use
- Select multiple models (e.g., GPT-4, Claude, local Llama)
- Click "Professional Association: Doctor" quick test
- Compare how models complete: "The doctor walked into the room. He..."
- Note differences in pronoun usage and assumptions
- Use the "Cultural Assumptions: Names" test
- Compare responses to prompts about different names
- Identify stereotype patterns across models
- Enter your own prompt testing a specific bias dimension
- Select models to compare
- Analyze and export results for research
Add or modify LLM models:
{
"models": [
{
"id": "custom-model",
"name": "My Custom Model",
"provider": "lm-studio",
"api_type": "openai",
"endpoint_env": "LM_STUDIO_ENDPOINT",
"model_name": "custom-model-name",
"requires_api_key": false
}
]
}Add custom bias tests:
{
"prompts": [
{
"id": "custom-test-1",
"category": "gender_bias",
"title": "My Custom Test",
"prompt": "Your test prompt here",
"description": "What this test evaluates",
"source": "custom"
}
]
}List all available models with availability status.
Response:
{
"models": [
{
"id": "gpt-4",
"name": "GPT-4",
"provider": "openai",
"available": true
}
]
}Query multiple models with a prompt.
Request:
{
"prompt": "Complete: The doctor is...",
"models": ["gpt-4", "claude-sonnet-4"],
"temperature": 0.7
}Response:
{
"prompt": "Complete: The doctor is...",
"timestamp": "2026-01-27T15:30:00Z",
"responses": [
{
"model_id": "gpt-4",
"model_name": "GPT-4",
"response": "...a highly trained professional...",
"latency_ms": 1234,
"error": null
}
]
}Get pre-built bias test prompts.
Response:
{
"prompts": [
{
"id": "gender-profession-doctor",
"category": "gender_bias",
"title": "Professional Association: Doctor",
"prompt": "Complete this sentence...",
"description": "Tests gender stereotypes..."
}
]
}Health check endpoint.
Response:
{
"status": "healthy",
"timestamp": "2026-01-27T15:30:00Z",
"available_models": 3
}Error: "Models config file not found"
- Ensure
config/default_models.jsonexists - Check file path is correct relative to backend directory
Error: "No module named 'fastapi'"
- Run
pip install -r requirements.txt - Ensure you're using Python 3.9+
Cloud models (OpenAI, Anthropic)
- Check API keys are correctly set in
.env - Verify API key format (starts with
sk-for OpenAI,sk-ant-for Anthropic) - Test API key with:
curl https://api.openai.com/v1/models -H "Authorization: Bearer YOUR_KEY"
Local models (LM Studio, Ollama)
- Ensure LM Studio or Ollama is running
- Check endpoint URL in
.envmatches the server - Verify firewall isn't blocking localhost connections
"Connection refused" error
- Local model server not running - start LM Studio or Ollama
- Check endpoint URL is correct
"Request timeout" error
- Increase timeout in
.env:QUERY_TIMEOUT_SECONDS=60 - Local model may be too slow - try a smaller model
- Reduce max concurrent queries:
MAX_CONCURRENT_QUERIES=3
"Rate limit exceeded" error
- You've hit API rate limits
- Wait a few minutes before retrying
- Consider using local models instead
Models or prompts not loading
- Check browser console for errors (F12 → Console tab)
- Verify backend is running and accessible
- Check CORS settings in
backend/config.py
Results not displaying
- Check browser console for JavaScript errors
- Ensure all JS files loaded correctly
- Clear browser cache and refresh
This tool complements the "Biases in AI" lecture by providing:
- Live Demonstrations: Show real-time bias patterns during lectures
- Hands-on Practice: Students can explore biases independently
- Data Collection: Export results for quantitative analysis
- Discussion Starters: Compare responses to spark classroom discussion
Use this tool to:
- Explore Bias Dimensions: Test gender, racial, professional, and cultural biases
- Compare Models: Understand how different architectures handle bias
- Collect Data: Export results for research projects or reports
- Analyze Patterns: Use CSV exports with Pandas for deeper analysis
- Bias Audit: Test 10 prompts across 3 models, analyze patterns
- Prompt Engineering: Create prompts that reveal specific biases
- Comparative Study: Compare cloud vs. local model bias patterns
- Mitigation Analysis: Test debiased vs. standard models
- Create a new adapter in
backend/services/:
from backend.services.llm_adapter import LLMAdapter
from backend.models.schemas import ModelResponse
class CustomAdapter(LLMAdapter):
async def query(self, prompt: str, temperature: float) -> ModelResponse:
# Your implementation
pass-
Register in
backend/services/llm_orchestrator.py -
Add model configuration to
config/default_models.json
Modify frontend/js/comparison-view.js to add custom highlighting:
highlightBiasIndicators(text) {
// Add your custom detection logic
// Example: highlight specific keywords, sentiment, etc.
}- Parallel Queries: Queries to different models run simultaneously
- Timeouts: Default 30s per model (configurable)
- Rate Limiting: Respect API provider rate limits
- Local Models: Generally slower but no rate limits
- API Keys: Never commit
.envfile to version control - Local Only: Default configuration only allows localhost access
- No Authentication: Suitable for local/educational use only
- Production: Add authentication and rate limiting for public deployment
To extend this tool:
- Add new bias test prompts to
config/bias_test_prompts.json - Create new LLM adapters for additional providers
- Enhance bias detection algorithms in frontend
- Add new export formats (PDF, Excel, etc.)
Educational use only. Part of the "Introduction to AI" course materials.
For issues or questions:
- Check the Troubleshooting section
- Review API documentation at http://localhost:8000/docs
- Contact course instructors
- Based on "Biases in Language Models" lecture (biases.tex)
- Built with FastAPI, Tailwind CSS, and vanilla JavaScript
- Supports OpenAI, Anthropic, LM Studio, and Ollama