|
|
--- |
|
|
title: LLM Council |
|
|
emoji: π’ |
|
|
colorFrom: pink |
|
|
colorTo: green |
|
|
sdk: gradio |
|
|
sdk_version: 6.0.0 |
|
|
app_file: app.py |
|
|
pinned: false |
|
|
--- |
|
|
|
|
|
# π’ LLM Council - Multi-Model AI Deliberation System |
|
|
|
|
|
A sophisticated system where multiple LLMs collaboratively answer questions through a 3-stage deliberation process. |
|
|
|
|
|
## π― How It Works |
|
|
|
|
|
1. **Stage 1 - Individual Responses**: 5 different AI models independently answer your question |
|
|
2. **Stage 2 - Peer Review**: Each model ranks the anonymized responses from others |
|
|
3. **Stage 3 - Synthesis**: A chairman model synthesizes the final answer based on all inputs |
|
|
|
|
|
## π° Cost: Mostly FREE! |
|
|
|
|
|
This version uses **FREE HuggingFace Inference API** models: |
|
|
- β
Meta Llama 3.3 70B (FREE) |
|
|
- β
Qwen 2.5 72B (FREE) |
|
|
- β
Mixtral 8x7B (FREE) |
|
|
- π΅ OpenAI GPT-4o-mini (low cost) |
|
|
- π΅ OpenAI GPT-3.5-turbo (low cost) |
|
|
|
|
|
**Cost per query**: ~$0.01-0.03 (mostly OpenAI, HF is free!) |
|
|
|
|
|
## β‘ Quick Start |
|
|
|
|
|
### π Deploy to Hugging Face (Recommended) |
|
|
|
|
|
1. **Fork/Duplicate this Space** |
|
|
2. **Add your API keys** in Settings β Repository secrets: |
|
|
- `OPENAI_API_KEY` - Get from [OpenAI](https://platform.openai.com/api-keys) |
|
|
- `HUGGINGFACE_API_KEY` - Get from [HuggingFace](https://huggingface.co/settings/tokens) |
|
|
3. **Done!** Your space will auto-deploy |
|
|
|
|
|
### π» Run Locally |
|
|
|
|
|
```bash |
|
|
# Clone repository |
|
|
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME |
|
|
cd YOUR_SPACE_NAME |
|
|
|
|
|
# Install dependencies |
|
|
pip install -r requirements.txt |
|
|
|
|
|
# Create .env file with your API keys |
|
|
cp .env.example .env |
|
|
# Edit .env and add: |
|
|
# OPENAI_API_KEY=your_openai_key |
|
|
# HUGGINGFACE_API_KEY=your_hf_token |
|
|
|
|
|
# Run the app |
|
|
python app.py |
|
|
``` |
|
|
|
|
|
Visit `http://localhost:7860` |
|
|
|
|
|
## π Getting API Keys |
|
|
|
|
|
### OpenAI API Key (Required) |
|
|
1. Go to https://platform.openai.com/api-keys |
|
|
2. Create new secret key |
|
|
3. Copy and save it (costs ~$0.01-0.03 per query) |
|
|
|
|
|
### HuggingFace Token (Required for FREE models) |
|
|
1. Go to https://huggingface.co/settings/tokens |
|
|
2. Create new token (read access is enough) |
|
|
3. Copy and save it (100% FREE to use!) |
|
|
|
|
|
## π€ Council Models |
|
|
|
|
|
### Current Configuration |
|
|
- **Meta Llama 3.3 70B** - Excellent reasoning, FREE |
|
|
- **Qwen 2.5 72B** - Strong performance, FREE |
|
|
- **Mixtral 8x7B** - Mixture of experts, FREE |
|
|
- **OpenAI GPT-4o-mini** - Fast & capable, low cost |
|
|
- **OpenAI GPT-3.5-turbo** - Reliable, low cost |
|
|
|
|
|
### Chairman |
|
|
- **OpenAI GPT-4o-mini** - Excellent synthesis capabilities |
|
|
|
|
|
Want to customize? Edit `backend/config_free.py`! |
|
|
|
|
|
## π Performance |
|
|
|
|
|
- **Response Time**: 60-120 seconds (3 stages, parallel processing) |
|
|
- **Quality**: Better than single-model responses |
|
|
- **Cost**: ~$0.01-0.03 per query (mostly FREE!) |
|
|
- **Reliability**: Automatic retries & error handling |
|
|
|
|
|
## π οΈ Tech Stack |
|
|
|
|
|
- **Frontend**: Gradio 6.0+ (with MCP server support) |
|
|
- **Backend**: Python async/await |
|
|
- **APIs**: |
|
|
- HuggingFace Inference API (FREE models) |
|
|
- OpenAI API (paid models) |
|
|
- **Storage**: JSON-based conversation persistence |
|
|
|
|
|
## π Project Structure |
|
|
|
|
|
``` |
|
|
llm_council/ |
|
|
βββ app.py # Main Gradio interface |
|
|
βββ requirements.txt # Python dependencies |
|
|
βββ .env.example # Environment template |
|
|
βββ backend/ |
|
|
β βββ config_free.py # FREE model configuration |
|
|
β βββ api_client.py # HF + OpenAI API client |
|
|
β βββ council_free.py # 3-stage orchestration |
|
|
β βββ storage.py # Conversation storage |
|
|
β βββ main.py # FastAPI backend (optional) |
|
|
βββ docs/ |
|
|
βββ QUICKSTART.md |
|
|
βββ DEPLOYMENT_GUIDE.md |
|
|
βββ CODE_ANALYSIS.md |
|
|
``` |
|
|
|
|
|
## π§ Configuration |
|
|
|
|
|
Want different models? Edit `backend/config_free.py`: |
|
|
|
|
|
```python |
|
|
# Use ALL FREE models (no OpenAI cost): |
|
|
COUNCIL_MODELS = [ |
|
|
{"id": "meta-llama/Llama-3.3-70B-Instruct", "provider": "huggingface"}, |
|
|
{"id": "Qwen/Qwen2.5-72B-Instruct", "provider": "huggingface"}, |
|
|
{"id": "mistralai/Mixtral-8x7B-Instruct-v0.1", "provider": "huggingface"}, |
|
|
{"id": "google/gemma-2-27b-it", "provider": "huggingface"}, |
|
|
] |
|
|
``` |
|
|
|
|
|
## π€ Contributing |
|
|
|
|
|
Improvements welcome! See `CODE_ANALYSIS.md` for refactoring suggestions. |
|
|
|
|
|
## π Credits |
|
|
|
|
|
- Implementation: Community contributions |
|
|
- FREE models: Meta, Qwen, Mistral via HuggingFace |
|
|
|
|
|
## π License |
|
|
|
|
|
See original repository for license information. |
|
|
|
|
|
--- |
|
|
|
|
|
**Need Help?** Check the docs folder for detailed guides! |
|
|
|