This project is a Telegram bot designed to help users solve school curriculum tasks using the AI21 model. The bot provides answers in three styles: short, medium, and detailed. It is implemented using aiogram
for message and command handling and langchain_ai21
for interaction with the language model.
- Python: Version 3.9 or higher
- Dependencies:
aiogram
langchain_ai21
langchain_core
datetime
random
-
Clone the repository or download the files:
git clone <repository_url> cd <repository_directory>
-
Create a virtual environment:
python3.9 -m venv venv source venv/bin/activate # For Linux/MacOS venv\Scripts\activate # For Windows
-
Upgrade
pip
and install dependencies:pip install --upgrade pip pip install -r requirements.txt
-
Configure environment variables: Create a file named
app/config.py
and add your bot token:TOKEN = "Your_Bot_Token"
-
Run the bot:
python bot.py
bot.py
: The main file containing the bot's logic.app/config.py
: Configuration file for storing the bot's token.texts.py
: Contains text data, such as sticker sets.app/kb.py
: Keyboard layouts for user interactions.
- Command
/start
: Initiates interaction with the bot. The user receives a welcome message and options to proceed. - Question Handling: Users can ask a question, select the type of answer (
short
,medium
,long
), and the bot will generate a response using AI21. - Sticker Interaction: The bot sends random stickers to create a friendly atmosphere.
- State Management: FSM (
aiogram.fsm
) is used to track the current dialogue state.
- Register at AI21 Studio and obtain an API key.
- Add the API key to the code:
API_KEY = 'Your_API_Key'
Example requirements.txt
file content:
aiogram==3.x
langchain-ai21
langchain-core
python-dotenv
- Payment Timeout: The code includes a placeholder for handling payment timeout, which is set to
10
seconds (adjustable in thePAYMENT_TIMEOUT
variable). - Error Handling: Ensure proper error handling for API calls and user interactions to maintain a smooth experience.