Zhishu Cloud connects to WeChat group robots

GPT access to WeChat

Tools to prepare

server

Alibaba Cloud and Pagoda, follow up as an example

WeChat (small)

It is recommended to use a WeChat account, there is a risk of being banned

Github code

A third-party code is required, which connects ChatGPT to various messaging applications, and developers can easily establish a connection between ChatGPT and various messaging applications.

API

console access

deployment server

Installation package

The code supports Linux, MacOS, and Windows systems (it is recommended to run on a Linux server), and it needs to be installed

Python, it is recommended that the Python version be between 3.7.1 and 3.10.

Upload and decompress the code directly through the pagoda or git (contact wei for help: mytimerun) download

Install dependencies

pip3 install itchat-uos==1.5.0.dev0
pip3 install --upgrade openai

Note: itchat-uosUse the specified version 1.5.0.dev0, and openaiuse the latest version, which must be higher than 0.27.0.

Note: The openai version requires 0.27.0the above. If the installation fails, you can upgrade pip first,pip3 install --upgrade pip

fix itchat bug

If after scanning the code, the mobile phone prompts that the login verification needs to wait for 5 seconds, but the QR code of the terminal keeps refreshing and prompts Log in time out, reloading QR code, you can execute the following script to quickly fix it:

bash fix-itchat.sh

If the automatic repair is invalid, refer to chatgpt-on-wechat/#8 for manual repair.

Configuration instructions

The core configuration file is config.jsona template file provided in the project config-template.json, which can be copied from the template to generate the final effective config.jsonfile:

cp config-template.json config.json

config.json example

{
    
    
  "model": {
    
    
    "type" : "zhishuyun",
    "openai": {
    
    
      "token": "你的国内key",
      "conversation_max_tokens": 1000,
      "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。"
    }
  },
"channel": {
    
    
    "type": "wechat",

    "single_chat_prefix": ["bot", "@bot"],
    "single_chat_reply_prefix": "[bot] ",
    "group_chat_prefix": ["@bot"],
    "group_name_white_list": ["ChatGPT测试群"],
    "image_create_prefix": ["画", "看", "找一张"],

    "wechat": {
    
    
    }
}
}

start up

After the configuration modification is completed and the dependencies are installed, we can run the program.

Use the nohup command to run a program in the background:

touch nohup.out                                   # 首次运行需要新建日志文件  
nohup python3 app.py & tail -f nohup.out          # 在后台运行程序并通过日志输出二维码

Supplementary Notes - Error Resolution

Personal WeChat
is used in a similar way to the project chatgpt-on-wechat.

Installation dependencies:

pip3 install itchat-uos==1.5.0.dev0
pip3 install --upgrade openai


Possible errors
pip3: command not found

You can install pip3 by the following steps:

Confirm if Python3 is installed on your system. You can enter "python3" in the terminal to check whether it is installed.

If you don't have Python3 in your system, you can install it with: sudo yum install python3

Install the development package of Python3: sudo yum install python3-devel

Install pip3: sudo yum install python3-pip

To verify whether pip3 is successfully installed, you can enter "pip3" in the terminal. If the relevant information of pip3 is output, it means that the installation is successful.


When this prompt appears, solve
WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --userinstead.


If you want to avoid installing Python packages with root privileges, follow the steps below to install pip in a non-root environment:

1. If you do not have Python 3 on your CentOS operating system, install it with the following command:

$ sudo yum update -y
$ sudo yum install -y python3
2. Then, you need to install pip in Python 3 to easily install and manage other Python packages. You can use the following command to do this:

into a virtual environment to ensure success

$ python3 -m venv myenv
$ source myenv/bin/activate
$ python3 -m pip install --upgrade pip
falls back to root:
deactivate

maybe: pip install --upgrade pip

The first line of command creates a virtual environment named "myenv" and contains the file containing the activate script in the "bin" folder.

Next, the commands required to activate the virtual environment are executed with "." in the second line. If the virtual environment is activated successfully, "(myenv)" will be displayed on the left side of the command prompt. Now you can install pip. The third line of command installs the latest version of pip.

3. The next step is to install the package using pip, for example, run the following command to install numpy:

$ pip install numpy
can also be installed with similar commands for other packages.

4. Finally, when you are done installing packages or completing tasks, you can exit the virtual environment:

$ deactivate
This command will leave the virtual environment and restore the original bash shell.

With these steps, installing and using Python packages in a non-root environment should not be a problem.


Note: itchat-uos uses the specified version 1.5.0.dev0, and openai uses the latest version, which must be higher than 0.27.0.

fix itchat bug

If after scanning the code, the mobile phone prompts that the login verification needs to wait for 5 seconds, but the QR code of the terminal keeps refreshing and prompts Log in time out, reloading QR code, you can execute the following script to quickly fix it:

bash fix-itchat.sh
If the automatic repair is invalid, refer to chatgpt-on-wechat/#8 for manual repair.

Description of configuration items:

“channel”: {
“type”: “wechat”,

"single_chat_prefix": ["bot", "@bot"],
"single_chat_reply_prefix": "[bot] ",
"group_chat_prefix": ["@bot"],
"group_name_white_list": ["ChatGPT测试群"],
"image_create_prefix": ["画", "看", "找一张"],

"wechat": {
}

}
Personal WeChat configuration items are placed at the same level as type, indicating that these are public configurations and will be reused in other applications. When the configuration is loaded, the configuration in the module will be used first, and if it is not found, the public configuration will be used.

Execute python3 app.py in the project root directory to start the program, scan the QR code with your mobile phone to complete the login, and refer to chatgpt-on-wechat for details.

20230513
Complete installation process of WeChat robot

First switch root to the myenv environment

Installation dependencies:

pip3 install itchat-uos==1.5.0.dev0
pip3 install --upgrade openai


$ python3 -m venv myenv
$ source myenv/bin/activate
$ python3 -m pip install --upgrade pip

pip install pillow


You are using pip version 8.1.2, however version 23.1.2 is available.
You should consider upgrading via the ‘pip install --upgrade pip’ command.

maybe:
pip install --upgrade pip



ModuleNotFoundError: No module named ‘qrcode’
to do :
pip install qrcode
maybe:
sudo yum install python-pip

ModuleNotFoundError: No module named ‘PIL’
to do :
pip install pillow


View running programs
ps -ef | grep app.py | grep -v grep

kill process (number)

Startup
After the configuration modification is completed and the dependencies are installed, we can run the program.

Use the nohup command to run a program in the background:

touch nohup.out # The first run needs to create a new log file
nohup python3 app.py & tail -f nohup.out # Run the program in the background and output the QR code through the log

Guess you like

Origin blog.csdn.net/hbqjzx/article/details/130656170