Unit 1: QQ Chatbot Deployment Based on GPT3.0 Model + mirai QQ#
date: January 7, 2023
slug: 13
status: Published
tags: Technology
type: Post
1. Register OpenAI Account#
Registration method: 1. If you have a US phone number (Google Voice is not available), you can register directly. 2. If you don't have a US phone number, you can use an SMS verification platform. 3. Lazy people like me choose to register through pdd directly. The specific registration process is not described here. After successful registration, go to the personal center to view the API key, which will come with 18 USD of free API call quota.
2. Automated Deployment Method#
Use Docker for Linux and Installer for Windows.
Deployment on Linux#
(Using CentOS as an example)
There are two possibilities for someone who doesn't use Docker. One is that they don't have the ability to use Docker. Because they can't afford a server and can't understand the documentation, their life is a failure. The second possibility is that they have the ability but choose not to use Docker. When they have the ability but don't have the idea of using Docker, their ideological level is so low that it is appalling. A capable person who does not take action to prove himself can only prove the low quality of his behavior. It is dark and not truly recognized by society.
Project Address: QChatGPT-Docker-Installer
1. Install Docker and Docker Compose#
- Install Docker:
sudo curl -sSL https://get.daocloud.io/docker|sh
- Start Docker:
systemctlstart docker
- Guard Docker:
sudo systemctl daemon-reload
- Install Docker-compose:
sudo pip3 install docker-compose
For those without pip, execute the following command:
sudo yum install python3-pip
2. Download the Required Files#
i. Clone the Repository#
git clone https://github.com/mikumifa/QChatGPT-Docker-Installer
cd QChatGPT-Docker-Installer
ii. Deploy#
chmod +x loadFile.sh && ./loadFile.sh
After deployment, the file directory will be as follows:
.
├── bot
│ ├── config-template.py
│ ├── LICENSE
│ ├── main.py
│ ├── pkg
│ ├── README.md
│ ├── requirements.txt
│ ├── res
│ ├── sensitive.json
│ └── tests
├── docker-compose.yaml
├── loadFile.sh
├── mirai
│ ├── LICENSE
│ ├── mcl
│ ├── mcl.cmd
│ ├── mcl.jar
│ └── README.md
├── _mirai.Dockerfile
└── _setup.Dockerfile
3. Configure and Start mirai#
i. Initialize mirai#
docker compose run --rm mirai
ii. Log in to QQ on mirai#
login <Bot QQ Number> <Bot QQ Password>
Note: It is recommended not to set a device lock for the QQ account used as the bot. When logging in, you may need to slide the verification code. At this time, you need to use
iii. Configure Auto Login#
After successfully logging in to the bot account, execute the following command:
autologinadd <Bot QQ Number> <Bot QQ Password>
autologin setConfig <Bot QQ Number> protocol ANDROID_PAD
After completing the configuration, press Ctrl+C
to exit.
iv. Write the Configuration File#
- Create
config.py
in thebot
folder and copy the contents ofconfig-template.py
into it. Editconfig.py
and modify the required items. - In the
mirai/config/net.mamoe.mirai-api-http
folder, findsetting.yml
, which is the configuration file formirai-api-http
. Modify the content of this file to:
adapters:
- ws
debug: true
enableVerify: true
verifyKey: yirimirai
singleMode: false
cacheSize: 4096
adapterSettings:
ws:
host: localhost
port: 8080
reservedSyncId: -1
The value of verifyKey
should be the same as the verifyKey
in config.py
of the bot
.
4. Start#
i. Start the mirai Container#
docker compose run -itd mirai
This command will start the mirai container in the background.
ii. Start the Main Program Container#
docker compose run -itd setup
This command will start the main program container in the background and complete the configuration.
When I reached this step, I couldn't recognize the
-itd
command, and in the end, I didn't use-itd
and just used-d
, which seems to work too. Let's make do with it, as it didn't give any errors.
Installer Version#
(Supports Windows, CentOS, Ubuntu, and Raspbian arm64)
Project Address: qcg-installer This project is a one-click deployment script written in Go language for the QChatGPT project, automating the deployment of dependencies.
- Note: The downloaded Python and mirai are both portable versions and do not affect other system environments.
1. Download the Installer#
- Download the executable file from the Release page. If you cannot access it, please go to Gitee.
- Save it to an empty directory on your computer, run it directly, and wait for the environment configuration.
- After completion, enter the
API key
andQQ number
as prompted. - Installation is complete at this point.
2. Run the Program#
After each restart, follow these steps to start the program:
i. Start mirai#
- Run
run-mirai.bat
(Windows) or./run-mirai.sh
(Linux) to start mirai. - Enter
login <QQ number> <QQ password>
to log in to the account as prompted (see the above Linux deployment for Tencent authentication tutorial).
ii. Run the Main Program#
- After logging in, run
run-bot.bat
(Windows) or./run-bot.sh
(Linux) to start the main program.
iii. Common Issues#
- If mirai prompts "QQ version is too low", see this issue.
- If
run-bot.bat
crashes, see this solution. - If prompted to install
uvicorn
orhypercorn
after starting, do not install them as they may cause unknown bugs.