This is a project for the course, which aims to create a Telegram bot that utilizes the power of OpenAI's GPT language model to assist users with text and visual-related tasks.
The ChatGPT Image Bot is designed to respond to user messages with text and, when needed, generate images based on the user's image description. It leverages the OpenAI Chat API and Image API to achieve these functionalities.
To run this project, you need to have the following components set up:
- Python 3.7 or higher
- aiogram library
- pandas library
- re (regular expression) library
- OpenAI Python library (
openai
)
Additionally, you need an OpenAI API key (YOUR_TOKEN
) to access the OpenAI Chat API for language model responses and the Image API for generating images.
- Clone the project repository and navigate to the project directory.
- Install the required dependencies using
pip install aiogram pandas openai
. - Set your OpenAI API key by replacing
"YOUR_TOKEN"
with your actual API key in the code.
-
The bot responds to the
/start
command, which registers the user if they are new or welcomes them back if they are already registered. -
The
/get_tokens
command increases the token capacity of the user if a cooldown period has passed since the last increase. -
The
/get_pic
command allows the user to provide a description of the image they want to generate. -
To generate an image, use the
[IMAGE]{description of the image}
tool in the message. The bot will then attempt to generate the image based on the provided description.
-
Since the GPT language model cannot directly generate images, it uses a special tool format (
[IMAGE]{description of the image}
) to indicate the appearance of the picture in the response. -
Make sure to use a detailed image description in the tool format to get more accurate and relevant image generation results.
main.py
: The main script containing the bot's functionality, message handlers, and API integration.users.csv
: A CSV file to store user data, including token capacity and context for conversation history.
-
After setting up the prerequisites and updating the API key, run the
main.py
script. -
The bot will start listening for incoming messages and respond accordingly.
-
User data (including token capacity) will be saved to
users.csv
after each execution.
This project is built using the aiogram
library for Telegram bot interactions and the pandas
library for managing user data. The powerful language model is provided by OpenAI's GPT.
Note: Make sure to adhere to OpenAI's guidelines and terms of use when using the GPT language model and API.
Enjoy exploring the capabilities of the ChatGPT Image Bot! If you have any questions or feedback, feel free to reach out.
Happy coding!