Here’s the translated version of the README:
This project is a Telegram bot integrated with the OpenAI API. It provides answers to questions based on documentation (Word documents) and the user's previous interactions. The bot uses machine learning to find the most relevant answers and can query OpenAI if the required information is not found in the local database.
The project is built using the following technologies and libraries:
Python 3.8+
python-telegram-bot
for interacting with the Telegram APIopenai
for integration with OpenAI GPT-3.5colorama
for colorful loggingscikit-learn
for text vectorization and nearest neighbors searchpython-docx
for working with Word documents
/project-root
│
├── bot.py # Main file to launch the bot
├── requirements.txt # Project dependencies
│
├── classes/ # Classes for handling various tasks
│ ├── bot_class.py # ChatBot class for command and message handling
│ └── question_answer_base.py # Class for searching answers in documentation
│
├── handlers/ # Handlers for commands and APIs
│ ├── handler.py # Handlers for bot commands and messages
│ ├── api_handler.py # Functions for interacting with the OpenAI API
│ ├── file_handler.py # Functions for file handling (uploading, searching, context saving)
│ └── logger.py # Logging setup with color customization
│
└── contexts/ # Stores files with user context
└── context_user_chat_id.txt # Context files for each user
Assuming Python 3.8+, IDE (e.g., VSCode), pip, and git are already installed:
-
Clone the repository:
git clone <git@github.com:ebataeva/lena_info_bot.git>
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install required dependencies:
pip3 install -r requirements.txt
-
Set up environment variables:
- Add environment variables for your Telegram Bot Token and OpenAI API Key:
TELEGRAM_BOT_TOKEN=your_bot_token_here OPENAI_API_KEY=your_openai_api_key_here
- Add environment variables for your Telegram Bot Token and OpenAI API Key:
-
Launch the bot using the following command:
python bot.py
-
The bot will start interacting with users on Telegram, processing commands and responding to messages.
- The main file for launching the bot. It loads environment variables, initializes the
ChatBot
instance, and calls itsstart()
method. Handles bot initialization and error management.
- The
ChatBot
class manages the bot's core functionality, including processing/start
and/clear
commands as well as text messages from users. It uses theQuestionAnswerBase
class to search for answers in documentation.
- Contains handlers for commands and messages. Handles user context saving and loading, and interacts with OpenAI for generating answers.
- Configures colorful logging for different project components using
colorama
.
- Utility functions for file operations such as loading text from Word documents, saving/loading user context, and searching for answers in the local database.
- Responsible for interacting with the OpenAI API. Contains functions for sending requests to OpenAI and processing responses.
- The
QuestionAnswerBase
class handles answer searching within Word documentation. Uses a nearest neighbors method fromscikit-learn
to find the most relevant paragraphs.
- Lists all necessary libraries and dependencies used in the project.
- After launching the bot, send the
/start
command in the Telegram chat to initialize the dialogue. - Send the bot a question, and it will try to find an answer in the uploaded documentation or query OpenAI for additional information.
- Python 3.8+
- Installed and configured
pip
- Accounts and tokens for Telegram and OpenAI
- The bot supports storing context from previous interactions for more personalized answers.
- Colorful logging is implemented for better traceability of bot performance and error handling.