Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

A while ago, I shared how to connect a large model toWeChatThe robot tutorial is based on the chatgpt-on-wechat project, which uses the models of LinkAI and Zhipu AI. In subsequent tests, some problems were found, such as problems with the call of Zhipu AI knowledge base, and sometimes the hit rate was very low.

So I stopped using the robot and looked for new solutions until I found Coze (an AI robot and agent creation platform launched by ByteDance). It turned out that Coze was very easy to use and also fit my usage scenario.

Therefore, I wrote this article to record the deployment process of building my own WeChat group chat AI robot from scratch, including server purchase and configuration, project deployment, access to coze, modification of coze configuration, access to the knowledge base, plug-in installation, etc.

I originally planned to divide this article into two parts, but in the end I decided to complete the entire article directly. Although it is long, the operation is relatively simple and there is basically no problem following the instructions.

This article is generally divided into two parts:

  • Deployment of chatgpt-on-wechat project
  • CozeRobot configuration

There are two ways to deploy the chatgpt-on-wechat project:

  1. Source code deployment.
  2. I have created a docker image that can be deployed with one click.

Get the Docker image:

Reply to the public account (note capitalization)ChatOnWeChat

What is Coze?

Coze is a next-generation AI application and chatbot development platform for everyone. It allows users to easily create a variety of chatbots, regardless of whether the user has programming experience. Users can deploy and publish their own chatbots to different social platforms, such as Doubao, Feishu, WeChat, etc. Coze provides a wealth of features, including roles and prompts, plug-ins, knowledge base, opening dialogues, preview and debugging, workflows, etc. Users can also create their own plug-ins. In addition, Coze has a Bot Store that displays open source robots with various functions for users to browse and learn.

Register coze

Enter the official website

Come to coze official website

  • China: https://www.coze.cn/
  • Overseas: https://www.coze.com/

Here I use domestic coze.

If your business is overseas, it is recommended to use the foreign Coze, which I will not go into detail about here.

register

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Get API key

We need to obtain the APIKey to call the coze large model interface.

After registration, click the button API at the bottom of the homepage

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Click on the API Token option

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Adding a New Token

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Configure a personal token.

  • Name: You can choose any name you want, I will keep the default name.
  • Expiration time: Permanently valid.
  • Select a specific team space: Personal
  • Permissions: Check all.

Finally click Confirm.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

The creation is successful. The token generated here needs to be saved! It will be used later. Click the Copy button to copy the token.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Creating a Bot

Go back to the home page and click Create Bot on the left

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants
  • Select the default Personal workspace
  • Fill in your own Bot name
  • Bot function introduction fill in

After filling in the form, click Confirm

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

The creation is successful and the configuration interface is entered.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Get BotID

Without doing any detailed configuration, just click Publish.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Let's skip the opening scene, we don't need it.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

You can fill in the release record here at will. I filled in the version number.

Select the publishing platform: Check the button Bot Store and Bot as API. (If you did not get the API key, you will not see the Bot as API option here)

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Then click Publish and you can see that it is published successfully.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Click to copy the Bot link

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

The link is as follows: https://www.coze.cn/store/bot/7388292182391930906?bot_id=true

Among them, 7388292182391930906 is the BotID. Save the BotID as we will use it later.

One thing to note here:

Every time you modify the Bot, the BotID will change after it is released!

Register a cloud server

There are many cloud server providers. Here I choose Alibaba Cloud for deployment. The price may not be the cheapest, so you need to compare it yourself.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Configuration reference

Here I will briefly explain the configuration of the purchase interface for your convenience.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Select CentOS 7.9 64-bit as the image

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Cloud disk 40G

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Check the public IP and the service will be charged based on fixed bandwidth, with a minimum bandwidth of 1Mbps.

Open IPV4 port/protocol and check it here

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Select a custom password for the login credentials and save it for later use in connecting to the server.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Cloud Server Configuration

Install the pagoda panel

First you need to install the server management interface, here choose to install Baota

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

When connecting, you will be prompted to log in to the instance and enter the password (the password set when creating the instance)

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Baota installation command

  1. -&&-.:
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

After the installation is complete, save the link in the red box and the account password.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Pay attention! Here it is prompted that the corresponding port number needs to be opened. We need to configure the corresponding port number in the Alibaba Cloud security group.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Configure security group rules

Click Manage Rules

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Click Add Manually (There are many port numbers in the inbound direction because I bought this server before and it was idle. The port numbers in the inbound direction were added before, so you don’t need to add them here like I did)

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Add ports 8080 and 13695 here. Port 8080 is the port number we will use to deploy the project later, which is fixed. Port 13695 is the port number that needs to be opened for accessing the Baota panel. The port number generated by each person here is different. Pay attention to your port number!

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Saved successfully

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Pagoda Configuration

Entering the Pagoda

After the security group is set up, go to the pagoda link you just saved, select the external network panel address, copy it to the browser and open it.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

After entering, you need to log in and fill in the username and password just generated

Installation Kit

After entering for the first time, an installation kit will be recommended. Select LNMP here.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Then wait patiently for the installation to complete

Install Python

Click on the website--python project--python version management

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Select Python version 3.9.7 (it is best to use Python 3.10 or below. The chatgpt-on-wechat project may have some problems with Python 3.10 or above)

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Wait for the installation to complete

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Project deployment

Source code deployment

Download the project source code from github https://github.com/zhayujie/chatgpt-on-wechat As of the time of writing this article, the version is 1.6.8

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Go to the Pagoda panel--file--path/www/wwwroot

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Upload the downloaded compressed package

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Right click to unzip

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Then go to the website--python project--add python project

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Project path: Select the folder path you just unzipped.

Project Name: Keep the default.

Run file: Select the app.py script in the project folder

Project port: 8080 (check the release port at the back)

Python version: 3.9.7 just installed

Framework: Choose Python

Run mode: python

Install dependency packages: The requirements.txt file in the project folder will be automatically selected here

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Click Submit.

Wait patiently and you will see the creation completed.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Remember to modify the security group in the Alibaba Cloud instance

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Management Rules

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

In the input direction, select Manual Add

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Set the port range to 8080 and the source to 0.0.0.0 and click Save

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Open the terminal. If prompted to enter the ssh key, enter the password you created when you created the server.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Terminal interface input

  1. -.
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Installation complete

Then install the optional components

  1. --.
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Installation complete

Docker Image Deployment

Come to the Docker interface of Baota. If it is a newly built server, the Docker service is not installed.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Click Install.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

After the installation is complete, come to the /www/wwwroot root directory of the pagoda.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Upload the image

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Import the image and select the path /www/wwwroot that you just uploaded.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Import Success

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Come to the container--add container

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Container name: optional

Image: Select the image you just imported

Port: 8080 (remember to check the server's security group rules)

Simply select Create.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Create Success

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Click Log

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

You can see that the project has run normally and generated a WeChat login QR code. Don't rush to scan it at this time, you also need to modify the project configuration.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

So far, the deployment of the project using the docker image has been completed. Next, you can modify the COW configuration. The red box area here simply selects the areas that need to be modified. The specific meaning of the modification will be explained below.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Restart the project after modification.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Scan the QR code again to log in.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Modify COW

Here, if you are deploying with docker image, you can skip the step of modifying to support COZE. Go directly to the step of modifying configuration to modify config.json

Modify to support COZE

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

In the /www/wwwroot/chatgpt-on-wechat-1.6.8 folder, add the following line after line 177 in the config.py file

  1. : , : , : , : ,

as follows:

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

config.py complete code

Create a new folder under /www/wwwroot/chatgpt-on-wechat-1.6.8/bot and name it "bytedance".

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Then upload the bytedance_coze_bot.py file in /www/wwwroot/chatgpt-on-wechat-1.6.8/bot/bytedance

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

bytedance_coze_bot.py is as follows

3. In the /www/wwwroot/chatgpt-on-wechat-1.6.8/bot folder, modify the bot_factory.py file.

  1. == .: .. ()
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Complete code

  1. (): == .:

In the /www/wwwroot/chatgpt-on-wechat-1.6.8/common folder, modify the Const.py file

  1. =
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Complete code

Under /www/wwwroot/chatgpt-on-wechat-1.6.8/bridge, modify the bridge.py file

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Complete code

  1. .. . .... (): (): .= { : ., :().(, ), :().(, ), :().(, ), }

Modify the configuration

Go to the project root directory and find the config-template.json file, which is the configuration file for startup.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

The main changes are the following four lines. You can directly clear the original file configuration and paste the following configuration into your config.json file.

  1. : , : , : , : ,
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Complete code

  1. { : , : , : , : , : , : , : , : , : , : , : [ , ], : , : [ ], : [ , ], : [ ], : , : , : , : 2500, : 3600, : , : 0.7, : , : , : , : }

Run the project

Start a project

Come to the python project management interface.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Stop the project and start it through the terminal, because you need to get the 0 QR code to log in when starting

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Open Terminal

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Enter the following command

Create a log

  1. .

Run app.py

  1. .&-.

If the operation is successful, a QR code will be generated in the terminal. Just scan the code with the WeChat account you need to log in.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Test results

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

You can see that the project is running normally and the robot is responding normally.

The reply here is related to the function introduction I set when I created the robot. Just delete it.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Restart Project

If you need to close or restart the project during debugging

Enter the query command

  1. -|.|-

Turn off the corresponding PID program

  1. -9 15230

For example, the pid of the program here is 20945, enter kill -9 20945 to shut down the program.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

About the Knowledge Base

Go to coze homepage to create knowledge base

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Configuring Knowledge Base Options

There are three types of knowledge bases: text format, table format, and photo type.

Different types of uploads are handled differently.

Here we only talk about the processing of text format.

Select the import type according to your needs.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

This is the knowledge base TXT I prepared, in the form of a question and answer.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Upload the prepared TXT file

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Select automatic segmentation and cleaning

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Click Confirm and wait for the process to complete.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

You can see that the generated segmentation fragments divide this text into 2 paragraphs, but this is not what I want. I want one question and one answer to be one paragraph.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Click Resegment

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

For segmentation settings, choose Custom, and for the identifier, I used the symbol ###.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

And the knowledge base TXT was modified, adding the identifier ### in front of each question

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Divide it into 8 sections again, which is what I want.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Go to Robot Orchestration, click the + sign in the Knowledge Options

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Select the newly created knowledge base

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

The default setting in the knowledge base is no recall response.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

You can customize a response. For example, if the question a user asks is not in the knowledge base, the response will be the statement you set.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Test the effect

Ask about the knowledge base

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

You can see that the response will be based on the content in our knowledge base.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Test results in WeChat.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

About Group Chat

Set up group chat

If you want the robot to reply in a group chat, you need to modify config.json. Modify the group_name_white_list group chat whitelist. Fill in the group name you want to reply to here. (The WeChat account logged in by the robot must be in this group chat)

  1. : [ , ],

Set the welcome message

When a new person joins the group chat, you can set a welcome message. Add the following to the config.json file:

  1. : ,

Remember to restart the project after setting config.json.

Effect test

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

About logs

The output log is in the run.log file in the project root directory

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Character Adjustment

If you think the robot's reply is too monotonous, we can add some human characters. This is a prompt from Liu Yulong.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Paste the character into the settings.

Need to wait for review

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Once the review is passed, we will test it directly to see the effect.

Test Results

Very individual!

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Plugin Installation

Plugin Introduction

The COW project provides plug-in functions, and we can install corresponding plug-ins according to our needs.

The source.json file in the project plugins directory shows the repositories of some plugins.

  1. { : { : { : , : }, : { : , : }, : { : , : }, : { : , : }, : { : , : }, : { : , : }, : { : , : }, : { : , : }, : { : , : }, : { : , : } } }

Here I need to post some content in the group at a fixed time, so I need to install the timetask timing plug-in.

Start Installation

First, make sure the robot is logged in.

Chat privately with the robot in the WeChat chat window.

Enter the administrator login command.

123456 is a custom password. You can set the password in the config.json file in the /www/wwwroot/chatgpt-on-wechat-1.6.8/plugins/godcmd directory.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Change password to your custom password and restart the service.

  1. { : , : [] }

Authentication successful.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Install the timetask plugin command

There may be a prompt here that the installation failed due to network reasons.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Workaround

Enter in the Baota terminal and turn off SSL verification.

  1. --.

Then re-execute the installation command.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

After successful installation, execute the scan command.

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Scheduled tasks

Tips: Talk to the robot and send the following scheduled task instructions

Add a scheduled task

【Instruction format】:**$time cycle time event**

  1. **: Command prefix. When the chat content starts with time, it will be regarded as a timed command.
  2. cycle: Today, tomorrow, the day after tomorrow, every day, working day, every week X (such as every Wednesday), YYYY-MM-DD date, cron expression
  3. time: Time at X o'clock and X minutes (e.g. 10:10), HH:mm:ss
  4. event: Things you want to do (supports general reminders and extension plug-ins in the project, details are as follows)
  5. Group title (optional): Optional. If not, the task will be executed normally. If this option is passed, a private message can be sent to the group with the target group title to set the task (the format is: group [group title], note that the robot must be in the target group)
  1. - : ,, . - :10:30 - :10:30 - :10:30 - :10:30 -:[0 * * * *] -:10:30- :10:30- :10:30 [] : ,- ,,. : (:) : -. -,/..
Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

Cancel scheduled tasks

First query the task number list, then select the task number to be canceled, and cancel the scheduled task

Nanny-level WeChat AI chatbot tutorial, using COZE to create private and group chat assistants

About Risk

After the last article was published, a fan left a message asking me whether this deployment mechanism has the risk of being blocked. To be honest, I only received a risk warning once on the WeChat account I used for testing, and there was no risk after it was unblocked and continued to be used. So far, it has been running stably for about a month. It is recommended that you use a small account to operate during the testing phase to reduce the risk of warnings.

at last

Congratulations! If you have read this far, you should be able to deploy the project successfully and run it on WeChat! If you encounter any problems in the middle, please leave a message below to communicate with me.

 

statement:The content of the source of public various media platforms, if the inclusion of the content violates your rights and interests, please contact the mailbox, this site will be the first time to deal with.
Encyclopedia

AI writing articles have too much AI flavor, here comes the universal prompt word template you want to remove the AI flavor

2024-7-22 9:55:09

Encyclopedia

How to use ChatGPT? How to write like a copywriter using ChatGPT

2024-7-24 9:06:13

Search