This bot is an AI-powered assistant that uses Google's Gemini AI to process user queries and provide responses based on uploaded documents. It integrates with Telegram for user interaction.
- Responds to user queries about specific documents or topics.
- Utilizes Google Gemini AI for natural language understanding and document-based querying.
- Handles Telegram messages and commands.
- Supports MarkdownV2 formatting for responses.
- Supports dynamic loading of documents from a specified GitHub repository.
- Supports rate limit handling for Gemini API models when using free-tier accounts (only if
GOOGLE_API_MODELis set toauto).
Warning
If the GOOGLE_API_MODEL environment variable is set to a specific model name (e.g., gemini-2.0-flash), the bot will not monitor rate limits automatically. This may lead to unexpected costs or rate limiting issues.
Warning
The list of supported free-tier Gemini models may change over time. Please refer to the official documentation for the most up-to-date information. If a model expires, it can no longer be used by the bot until the code in modules/state.py is updated.
- Python 3.8 or higher.
- Required Python packages (install using
pip install -r requirements.txt)
- Generate a Gemini API key from Google AI Studio
- Use @BotFather to generate a bot
- Get the API key from the generate bot
- Clone the Repository
git clone <repository-url>
cd <repository-folder>- Create a
.envFile
Create a .env file in the project root directory with the following variables:
TELEGRAM_API_KEY=your-telegram-bot-token
TELEGRAM_BOT_NAME=@your-bot-username
GOOGLE_API_KEY=your-google-api-key
GOOGLE_API_MODEL=gemini-2.0-flash
GOOGLE_API_MAX_ATTEMPTS=2
REPO_URL=https://github.com/octocat/hello-world
TELEGRAM_RESTART_DELAY_SECONDS=15Please note: creating the .env file is optional, if the variables are set in the current environment, the bot will retrieve them from there (or from the Docker environment variables)
- Prepare the sources
The bot pulls documents from the repository defined by REPO_URL and stores them in ./sources. You can also place your documents directly inside the sources folder if you want to manage them locally.
- Install Dependencies
pip install -r requirements.txt- Start the Bot using:
python main.py/start: Initiates interaction with the bot and provides an introductory message.
- Send a text message with your query to the bot, and it will respond based on the information in the uploaded documents.
The bot logs all activity to the console. Logs are categorized into:
- INFO: General information about the bot's operation.
- DEBUG: Detailed logs for troubleshooting.
- WARNING: Potential issues that do not stop the bot.
- ERROR: Issues that prevent successful operation.
You can adjust the log level in the configure_logging() function.
- Missing API keys: Ensure the
.envfile is correctly configured. - Google Gemini AI errors: Check your API key and ensure the uploaded files meet the requirements.
- Telegram bot issues: Verify the bot token and bot username.
For detailed error messages, check the logs.
- Clone the repo
- Build the container with
docker build -t notebook-lm-bot:latest . - Create the
docker-compose.ymlfile containing the text below - Start the container with
docker compose up
services:
bot:
container_name: notebook-lm-bot
environment:
- TELEGRAM_API_KEY=your-telegram-bot-token
- TELEGRAM_BOT_NAME=@your-bot-username
- GOOGLE_API_KEY=your-google-api-key
- GOOGLE_API_MODEL=gemini-2.0-flash
- GOOGLE_API_MAX_ATTEMPTS=2
- REPO_URL=https://github.com/octocat/hello-world
- TELEGRAM_RESTART_DELAY_SECONDS=15
restart: unless-stopped
image: notebook-lm-bot:latest
deploy:
resources:
limits:
cpus: '1'
memory: 256M