ChatGPT accesses WeChat to act as a robot

Start the Nuggets Growth Journey! This is the 5th day of my participation in the "Nuggets Daily New Plan·December Update Challenge", click to view the event details

1 Introduction

ChatGPT is very popular recently, students who don’t know about it may have a question, what is ChatGPT? In official terms, it is a language model that optimizes dialogue. It interacts in a conversational manner. The conversational format allows ChatGPT to answer follow-up questions, admit mistakes, challenge incorrect premises, and deny inappropriate requests. ChatGPT is a sibling model of InstructGPT that is trained to follow instructions in prompts and provide detailed responses. official address

In the words of Baidu Encyclopedia, ChatGPT is an artificial intelligence technology-driven natural language processing tool newly launched by the artificial intelligence research laboratory OpenAI. It uses the Transformer neural network architecture, which is also the GPT-3.5 architecture. The model for processing sequence data has language understanding and text generation capabilities. In particular, it will train the model by connecting a large number of corpora, which contain dialogues in the real world, making ChatGPT capable of knowing astronomy and geography. The ability to interact in the context of the chat, to communicate in a chat scene that is almost the same as a real human being. ChatGPT is not only a chat robot, but also can perform tasks such as writing emails, video scripts, copywriting, translation, and code.

2. Introduce ChatGPT

As the saying goes, if you want to do a good job, you must first sharpen your tools. If you want to introduce ChatGPT, you need to apply for a ChatGPT account first. Since this is a project created by foreign friends, it is not very friendly to domestic students. If you have the conditions, you can prepare scientific Internet tools and a mobile phone number that can receive foreign verification codes (if you don’t have a mobile phone number, this sms-activate website can help you).

2.1 Apply for a ChatGPT account

Click on the above registration address, select signup, after the registration is completed, you will be prompted to verify your mobile phone number. (If you encounter a prompt during the application process that the OpenAI service is not available in your country/region, please switch to the region of the Science Internet agent)image.png

2.2 Apply to receive the verification code online

After opening the above URL and registering, you can see the interface below. Enter OpenAI in the search bar, and there will be many countries below. India is recommended here. Don’t ask why. It’s cheaper. You need to recharge a certain amount in your account before purchasing. This The more user-friendly point of the website is that it can support Alipay payment. Just recharge the corresponding RMB amount according to the above tips. If you don’t know the exchange rate, you can directly search for the corresponding amount on Baidu and you can see the corresponding RMB amount. After the purchase, a virtual mobile phone number will appear, fill in the mobile phone in the corresponding region on ChatGPT, and then wait for the verification code in sms-activate.image.png

2.3 Test ChatGPT

The current window can only be used online

image.png

2.4 Apply for API keys

Application address: beta.openai.com/account/api...Click Create new secret key to create it, pay attention to save after generation, if you forget to regenerate one

image.png

3. Start deployment

There are already many open source projects on Github that introduce ChatGPT into WeChat, such as:

image.pngHowever, many of the above are verified through tokens. Here I want to use Api Keys to achieve it, so I found a mirror using Api Keys on dockerhub, and the mirror address . This only needs to be configured with the Api key.

3.1 Pull the image

docker pull cynen/wechat:latest

[root@centos /]# docker pull cynen/wechat:latest
​
[root@centos wechat]# docker images
REPOSITORY     TAG       IMAGE ID       CREATED        SIZE
cynen/wechat   latest    758738a0d88f   10 days ago    13.8MB
复制代码

3.2 config.json configuration

The config.json file is placed under /home/wechat

[root@centos wechat]# ls
config.json
复制代码
{
  "api_key": "sk-****",
  "auto_pass": false, 
  "model": "text-davinci-003",
  "session_timeout": 60
}
复制代码

api_key: the Api keys you applied for above

auto_pass: Whether to automatically pass the friend verification, here is set to false

model: model [you can refer to the official document to select the appropriate model, the address is at the bottom]

session_timeout: session saving time seconds is actually the context retention time, beyond this time, the context will be cleared automatically

3.3 Start the container

[root@centos wechat]# docker run -dti --name wechat -v /home/wechat:/app/ cynen/wechat
ca4b9e9c3cab2a196e2a50d0ac90c34183265f69f8b8f56b5513755ef5d8480f
[root@centos wechat]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                                                      NAMES
ca4b9e9c3cab   cynen/wechat   "wechatbot-amd64-lin…"   5 seconds ago   Up 4 seconds 
复制代码

3.4 Login

Use the docker logs -f wechat command to view logs

image.pngAfter scanning and logging in, there will be the following log outputimage.png

3.5 Test use

image.png

4. Reference

Official development documentation: beta.openai.com/docs/introd…

Retrieve the model address: beta.openai.com/docs/api-re…

Guess you like

Origin juejin.im/post/7181392275925106745