A multi-provider, multi-user AI chatbot built with Streamlit, featuring conversation memory, token tracking, and admin analytics.
- Multi-Provider Support: OpenAI, Anthropic (Claude), and Google Gemini
- User Authentication: Secure login/registration with bcrypt password hashing
- Conversation Memory: Vector-based memory storage using pgvector for context-aware responses
- Token Tracking: Real-time token usage monitoring and cost estimation
- Export Functionality: Download conversations in JSON or Markdown format
- Auto-Summarization: Automatic conversation summarization after 20 messages
- Admin Dashboard: Comprehensive analytics and user management
- Cloud Storage: All data stored in Supabase (PostgreSQL + pgvector)
chatbot/
├── app.py # Main Streamlit application
├── pages/
│ ├── chat.py # Chat interface
│ ├── login.py # Login page
│ ├── register.py # Registration page
│ └── admin.py # Admin dashboard
├── core/
│ ├── providers.py # LLM provider integrations
│ ├── memory.py # Vector memory management
│ ├── auth.py # Authentication functions
│ ├── counters.py # Token counting utilities
│ └── utils.py # Helper functions
├── assets/
│ └── style.css # Custom CSS styling
├── requirements.txt # Python dependencies
├── schema.sql # Database schema
└── .env.sample # Environment variables template
- Python 3.8 or higher
- A Supabase account and project
- API keys for the AI providers you want to use:
- OpenAI API key
- Anthropic API key
- Google AI Studio API key
git clone <repository-url>
cd chatbot-shiro
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt- Create a new project in Supabase
- Go to the SQL Editor in your Supabase dashboard
- Run the SQL commands from
schema.sqlto create tables and functions - Note down your Supabase URL and service role key
- Copy
.env.sampleto.env - Fill in your Supabase credentials:
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
SUPABASE_ANON_KEY=your-anon-key
EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
SESSION_TIMEOUT_MINUTES=30streamlit run app.pyThe application will be available at http://localhost:8501
- Register a new account or use the default admin account:
- Username:
admin - Password:
admin123(change this immediately!)
- Username:
- Login to your account
- Select an AI provider (OpenAI, Anthropic, or Gemini)
- Choose a model from the available options
- Enter your API key for the selected provider
- Adjust temperature and max tokens as needed
- Enable conversation memory for context-aware responses
- Start chatting!
Admins can access the admin dashboard to view:
- User activity statistics
- Token usage analytics
- Cost estimates
- Provider and model usage distribution
- User management
Each user must provide their own API keys for the AI providers they want to use. Keys are not stored permanently and must be entered each session for security.
| Provider | Models |
|---|---|
| OpenAI | o3, gpt-4.1, gpt-4o, o4-mini-deep-research |
| Anthropic | claude-sonnet-4-20250514, claude-3-7-sonnet-20250219, claude-opus-4-20250514 |
| Gemini | gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, gemini-pro-vision |
- Default Models:
- OpenAI:
o3 - Anthropic:
claude-sonnet-4-20250514 - Gemini:
gemini-2.5-pro
- OpenAI:
See core/providers.py for the latest model list and integration details.
The application uses a sophisticated memory system:
- Vector Storage: Messages are embedded using sentence-transformers and stored in pgvector
- Similarity Search: Relevant past conversations are retrieved for context
- Auto-Summarization: After 20 messages, older conversations are summarized and pruned
- Per-User Memory: Each user has isolated conversation memory
- Real-time token counting for all providers
- Cost estimation based on current pricing
- Session-level usage tracking
- Historical analytics in admin dashboard
Users can export their conversations in two formats:
- JSON: Machine-readable format for archival
- Markdown: Human-readable format for documentation
- Set up a VPS with Python 3.8+
- Clone the repository and install dependencies
- Set up environment variables
- Use a process manager like PM2 or systemd
- Set up a reverse proxy (Caddy, Nginx) for HTTPS
Example with Caddy:
# Install Caddy
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo tee /etc/apt/trusted.gpg.d/caddy-stable.asc
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update && sudo apt install caddy
# Create Caddyfile
echo "yourdomain.com {
reverse_proxy localhost:8501
}" | sudo tee /etc/caddy/Caddyfile
# Start services
sudo systemctl enable caddy
sudo systemctl start caddyRun the Streamlit app:
streamlit run app.py --server.port 8501 --server.address 0.0.0.0- All passwords are hashed using bcrypt
- Row Level Security (RLS) is enabled in Supabase
- API keys are not persisted (entered per session)
- Session timeout prevents unauthorized access
- Admin privileges are properly controlled
- Import Errors: Ensure all dependencies are installed:
pip install -r requirements.txt - Database Errors: Verify Supabase credentials and run schema.sql
- API Errors: Check API key validity and format
- Memory Issues: Ensure pgvector extension is enabled in Supabase
Make sure all required environment variables are set:
SUPABASE_URLSUPABASE_SERVICE_ROLE_KEYSUPABASE_ANON_KEY
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License. See LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review Supabase logs for database issues
- Check Streamlit logs for application issues
- Open an issue on GitHub
- Initial MVP release
- Multi-provider LLM support
- Vector memory system
- User authentication
- Admin dashboard
- Export functionality
- Auto-summarization