Not difficult, the code is only 25 lines in total, the general logic is as follows.
In total, there are two steps
Deploying Custom Message Processing Services on Cloud Servers
Here we need to customize the way we handle the messages sent by the user
First of all, import werobot, this is the official WeChat public let us customize the message processing module
pip install werobot
And then there's a sample.The details are annotated
Note that you can only start it on port 80, if you have https you can start it on port 443, as to why? Will know later.
import werobot # token is a credential used by WeChat to specify access to the current cloud server's services, representing that it's accessed by one of its own, and wait a minute to see what it's used for robot = (token='123456') @ def hello (messages): # is the content sent by the user print() return "hello!" ['HOST'] = '0.0.0.0' ['PORT'] = 80 ()
Then integrate into the chatgpt service
There are two prerequisites for integrating the chatgpt service here
- To register for an openai account, generate an api_key under the account for the program to use
- The server is able to access the extranet so that the call is successful
import werobot robot = (token='123456') import openai # This api_key needs to have an openai account in the first place, and then it is generated under the personal account. # Specific reference: /ysvae/article/details/128203722 openai.api_key="*****************************************" def generate_response(prompt): response = ( model="text-davinci-003", prompt=prompt, temperature=0, max_tokens=100, top_p=1, frequency_penalty=0.0, presence_penalty=0.0, ) message = [0].text return () @ def hello (messages): print() return generate_response() ['HOST'] = '0.0.0.0' ['PORT'] = 80 ()
Eventually it needs to be booted up in python
WeChat Configure Your Own Message Processing Server
You need to make sure that the previous services have been started!
Then we need microsoft public public to access the services of our own cloud service. Exactly which cloud server, you need to go to the background of our public management platform to configure.
Step 1: Modify the messaging server settings to allow us to customize how we handle messages sent by users
Setup and Development → Basic Configuration → Server Configuration → Modify Configuration
Step two:
url43.153.123.200 is the ip of the server, you can't add the port number after it, you can only use port 80 by default, https is port 443 by default. /chatgpt can be written casually
token: it's your own credentials as mentioned earlier
EncodingAESKeyJust randomize it.
Step Three:
If you are sure that there are no problems with the service on the cloud server, just click submit.
To this article on WeChat public number how to access the ChatGPT robot article is introduced to this, more related WeChat public number to access the ChatGPT robot content, please search for my previous articles or continue to browse the following related articles I hope you will support me more in the future!