-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from flynnoct/dev
v1.1.0
- Loading branch information
Showing
11 changed files
with
329 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,87 @@ | ||
# chatgpt-telegram-bot | ||
# ChatGPT Bot for Telegram | ||
|
||
Telegram bot implemented by OpenAI ChatGPT API (gpt-3.5-turbo-0301) released on March 1, 2023. | ||
![](/docs/dialog.png) | ||
|
||
## News | ||
|
||
- **DALL·E, the OpenAI Image Generation Model**, is now supported! Send a short prompt to the Bot and get your own painting! | ||
- **Whisper, the OpenAI Intelligent Speech Recognizer**, is now supported! Now chat with the Bot with audio messages! | ||
|
||
## Introduction | ||
|
||
This is a Telegram bot implemented by OpenAI ChatGPT API (gpt-3.5-turbo-0301). It is based on [OpenAI ChatGPT API](https://platform.openai.com/docs/guides/chat) and [python-telegram-bot](https://python-telegram-bot.org) | ||
ChatGPT Bot for Telegram is implemented with [OpenAI ChatGPT API](https://platform.openai.com/docs/guides/chat) released on March 1, 2023. The Telegram integration framework is based on [python-telegram-bot](https://python-telegram-bot.org). | ||
|
||
ChatGPT Bot can act as your Telegram contact. You can chat with it either personally or in a group chat. Just like the popular AI on the OpenAI official site, the Bot shares knowledge and inspires exciting new ideas. Many interesting features, such as **DALL·E** and **Whisper** are integrated together to make our Bot smarter and more usable. | ||
|
||
## Usage | ||
We hope you enjoy it! | ||
|
||
### Private Chat | ||
## Features | ||
|
||
You can just send a message to the bot in private chat. The bot will reply to you. | ||
The Telegram Bot features the following functions: | ||
|
||
### Group Chat | ||
- An AI consultant, based on OpenAI ChatGPT, interacts in a conversational way. | ||
- A flexible speech recognizer which supports audio interaction. | ||
- A AI painter reponses to user's requirement prompt. | ||
|
||
You can add the bot to a group chat. However it will only reply the messages with `@<bot_name>` mentioned. | ||
Additonal functions are also implemented: | ||
|
||
### Commands | ||
- Set the daily limitation of requirements to **DALL·E**. | ||
- Grant more resources to _Super Users_. | ||
|
||
## Commands | ||
|
||
- `/start`: Start the bot. | ||
- `/clear`: Clear the conversation context. | ||
- `/getid`: Get your Telegram user ID. | ||
- `/dalle <prompt>`: Ask DALL·E for a painting based on your prompt. | ||
|
||
## Sample Usage | ||
|
||
## Installation | ||
The Bot works in both personal and group chat of Telegram. | ||
In a personal chat, simply send a message to the Bot and it will reply to you. | ||
In a group chat, you need to tag the message with `@<bot_name>` to invoke the Bot. | ||
|
||
### Prepare | ||
### Preparation | ||
|
||
1. Create a Telegram bot by [@BotFather](https://t.me/BotFather) and get the token. | ||
2. Create an OpenAI account and get the API key. | ||
3. A VM or a server with Python 3 is needed to run the bot. | ||
3. A Linux VM or a server with Python 3 is needed to run the bot. | ||
4. A practical Internet environment is required. | ||
5. (Optional) [FFmpeg](https://ffmpeg.org) is required for the Bot to handle voice messages with Whisper. If you are not interested in using voice messages, you don't need to install it and **must set `enable_voice` in the config file to False**. | ||
|
||
> **Note**: You should disable the privacy mode of the bot. Otherwise the bot will not receive the messages from the group chat. You can do this by sending `/setprivacy` to [@BotFather](https://t.me/BotFather). | ||
### Deploy | ||
|
||
Clone this repository. | ||
|
||
```bash | ||
git clone [email protected]:flynnoct/chatgpt-telegram-bot.git | ||
``` | ||
### Deployment | ||
|
||
Install the dependencies. | ||
Download the latest release version and install the dependencies. | ||
|
||
```bash | ||
wget https://github.com/flynnoct/chatgpt-telegram-bot/releases/latest | ||
pip install -r requirements.txt | ||
``` | ||
|
||
Create config file. | ||
Then, you need to create a config file to manage the Bot. The config file includes sensitive information, such as telegram_token and openai_api_key, and we only release the corresponding template `config.json.template`. Therefore, you need to create a new `config.json` file and replace the relative fields with your own. | ||
|
||
```bash | ||
cp config.json.template config.json | ||
``` | ||
|
||
Modify config file. First, | ||
Follow below procedures to fill you `config.json`: | ||
|
||
```bash | ||
vim config.json | ||
``` | ||
1. Replace the `telegram_token` and `openai_api_key` with your own. | ||
2. Add allowed users to the `allowed_users` list. You can get your user id by sending `/start` to [@userinfobot](https://t.me/userinfobot) or send `/getid` to the Bot (after you start it). | ||
|
||
then, replace the `telegram_token` and `openai_api_key` with your own. | ||
> Note: the user ID is a series of numbers, you should add it to the `allowed_users` list as a string (add quotation marks around it). | ||
Add allowed users to the `allowed_users` list. You can get your user id by sending `/start` to [@userinfobot](https://t.me/userinfobot) or send `/getid` to this bot (after you start it). | ||
Now, you can run the Bot with `start_bot.sh` and try talk to it. Also, you can invite it to group chats and share with your friends! | ||
|
||
> Note: the user ID is a series of numbers, you should add it to the `allowed_users` list as a string (add quotation marks around it). | ||
To clear ChatGPT conversation context and restart the Bot, run shell script `restart_bot.sh`. To shut down the Bot, run `stop_bot.sh`. | ||
|
||
Run the bot. | ||
## Release version and notes | ||
|
||
```bash | ||
nohup python3 telegram_message_parser.py & | ||
``` | ||
or | ||
```bash | ||
pm2 start telegram_message_parser.py | ||
``` | ||
> Note: A launch script will be added later. | ||
The latest released version can be found [here](https://github.com/flynnoct/chatgpt-telegram-bot/releases/latest). More interesting new features are comming soon! | ||
|
||
Now you can start a private chat to the bot or add the bot to your group chat. Enjoy. | ||
The release notes are [here](/docs/release_notes.md). | ||
|
||
## License | ||
|
||
|
@@ -85,4 +91,4 @@ Now you can start a private chat to the bot or add the bot to your group chat. E | |
|
||
If you like this project, you can buy me a coffee ❤️ or give this repository a free star ⭐️. | ||
|
||
Click [Alipay](donate_code/alipay.jpg) to open QR code. | ||
Click [Alipay](donate_code/alipay.jpg) to open QR code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
{ | ||
{ | ||
"openai_api_key": "<YOUR_OPENAI_API_KEY_HERE>", | ||
"telegram_bot_token": "<YOUR_TELEGRAM_BOT_TOKEN_HERE>", | ||
"allowed_users": [ | ||
"<USER_ID_1>", | ||
"<USER_ID_2>" | ||
], | ||
"wait_time": 300 | ||
"enable_voice": true, // When enabled, Bot will accept audio messages with Whisper and reply. | ||
"allowed_users": [ | ||
"<USER_ID_1>", | ||
"<USER_ID_2>", | ||
], | ||
"wait_time": 600, // The time limit in seconds that the Bot will clear the conversation context. | ||
"enable_dalle": true, // When enabled, Bot will involve DALL·E to handle requests for painting. | ||
"super_users": [ | ||
"<SUPER_USER_ID_1>", // Super users are granted unlimited usage on DALL·E per day. | ||
"<SUPER_USER_ID_2>" | ||
], | ||
"image_generation_limit_per_day": 5 // The upper limit that a normal user is allowed to invoke DALL·E per day. | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# This script restarts a Python program named telegram_message_parser.py | ||
|
||
echo "Restarting bot..." | ||
|
||
pid=`ps -ef | grep telegram_message_parser.py | grep -v grep | awk '{print $2}'` | ||
|
||
if [ -z $pid ]; then | ||
echo "Bot is not running" | ||
else | ||
echo "Bot has been terminated" | ||
kill -9 $pid | ||
fi | ||
|
||
echo "Starting bot..." | ||
nohup python3 telegram_message_parser.py >/dev/null 2>&1 & | ||
echo "Bot has been restarted successfully" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/bin/bash | ||
# This script start a Python program named telegram_message_parser.py and run it in the background | ||
|
||
nohup python3 telegram_message_parser.py & | ||
nohup python3 telegram_message_parser.py >/dev/null 2>&1 & | ||
echo "Bot has been started successfully" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
# This script stops a Python program named telegram_message_parser.py | ||
|
||
# Find the PID of the process | ||
pid=$(ps -ef | grep "telegram_message_parser.py" | grep -v grep | awk '{print $2}') | ||
|
||
if [ -z "$pid" ]; then | ||
echo "Bot is not running" | ||
else | ||
# Terminate the process | ||
kill $pid | ||
echo "Bot has been terminated" | ||
fi |
Oops, something went wrong.