Welcome to the Multi-LLM Telegram Bot project! This versatile bot brings the power of GPT and Claude AI models directly to your Telegram chats, allowing to prompt both GPT and Claude through Telegram to easily compare the responses from both models. There are also image generation capabilities and special chat modes.
I currently run this bot on a self-hosted Raspberry Pi running Raspbian. Most of the workload is on the LLM hosting side (e.g. OPenAI or Anthropic) and the resource useage on the bot side itself is quite low so far - of course, this may vary significantly depending on how many users run your bot. The bot is currently built with the assumption that useage will be limited with a low number of users (yourself, maybe friends and family).
Clone the repository
git clone https://github.com/derdide/telegram_multi_llm_bot/
cd telegram_multi_llm_bot
Set up a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
Install dependencies
pip install -r requirements.txt
Set up environment variables
Create a .env
file in the project root and add the following:
# Telegram settings
TELEGRAM_TOKEN=your_telegram_token_here
AUTHORIZED_USERS=your_telegram_user1,your_telegram_user1
AUTHORIZED_GROUPS=your_telegram_group1,your_telegram_group2
# Open AI settings
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-40-mini
OPENAI_TOKENS=max_number_of_tokens_for_openai
IMAGE_GEN_MODEL=dall-e-3
# Anthropic settings
ANTHROPIC_API_KEY=your_anthropic_api_key_here
ANTHROPIC_MODEL=claude-3-opus-20240229
ANTHROPIC_TOKENS=max_number_of_tokens_for_anthropic_
Set up the database The bot will automatically create the necessary SQLite database when it first runs.
Create a chat-modes.json
file
This file should contain your custom chat modes. For example:
{
"pro": "You are in a professional environment. I expect you to to be formal and straight to the point. No blah-blah",
"creative": "You are expected to be creative and provide unconventional responses.",
"french": "You are expected to always reply in French, even if the prompt is in English"
}
To setup the bot as a service on a Linux server (e.g. Raspberry Pi), please follow instructions here: https://github.com/derdide/telegram_multi_llm_bot/issues/11#issuecomment-2295244069
Start the bot
python telegram-bit-main-bot.py
Interact with the bot on Telegram
/start
: Get a welcome message and basic info/help
: View available commands/gpt <message>
: Interact with GPT/claude <message>
: Interact with Claude/compare <message>
: Compare responses from both Claude and GPT/image <prompt>
: Generate an image based on the prompt/mode <mode_name>
: Switch to a special chat mode. Use '/mode reset' to return back to standard chat mode/balance
: Check current API usage and costsSend images
You can send images to the bot, and it will include them in the AI analysis
The bot tracks API usage for each interaction. Use the /balance
command to view a summary of your usage.
Keep your .env
file secure and never share your API keys. The bot stores conversation history and API usage in a local SQLite database. Ensure you comply with data protection regulations if deploying this bot in a production environment.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Happy chatting with your AI-powered Telegram bot! If you have any questions or run into issues, please open an issue on GitHub. Enjoy exploring the capabilities of GPT and Claude through your Telegram chats! ππ€