Recently, OpenAI released a cross-historyGPT-4oThe matter of models should be known to everyone in the streets and alleys.
At the beginning, I wanted to let everyone quickly experience the GPT-4o model, and encapsulated the model interface intoWeChat Official Accountmiddle.
It seems that everyone has a strong demand for "how to connect the GPT-4o model to the WeChat public account in detail and how to write specific codes", so roll up your sleeves and do it.In order not to let everyone down, I stayed up all night and finally recorded every step in detail.
The goal is to enable model access even with zero foundation!
1.1 Introduction and use of Coze platform
CozeIt is an AI chatbot and application development platform launched overseas by ByteDance, designed specifically for the development of the next generation of AI chatbots.
The reason we use it in this feature is precisely because of its ability to quickly build AI chatbots!
Website: https://www.1ai.net/2490.html
- For an introduction to the functions of the Coze platform, I recommend reading my previous article: 5 Minutes! Develop and Launch an Ai Robot, No More~
1.2 Introduction and use of API transfer station
Since we want to experience the model capabilities of GPT4o, we naturally have to call the model API provided on the OpenAI server.
However, we all know that due to network problems, we cannot access OpenAI's server smoothly.
So,The functions provided by a series of request relay proxy platforms allow us to perfectly solve this network problem. We only need to apply for the API of the corresponding model on these relay platforms, and then send a request to the API address specified by this relay platform to achieve smooth access to OpenAI's server.
As for how the network is implemented, we don’t need to pay attention to this. We only need to pay attention to whether the risk of this platform running away is high.
Here I would like to recommend an API transfer platform that I am currently using: https://aihubmix.com
- (1) After registering an account, you can start the service by recharging one dollar. Don't worry, the service is pay-as-you-go.
Create the corresponding Token, and pay special attention to checking the GPT-4o model, otherwise your Token cannot be used!
Copy your token and write down the transfer service URL: https://aihubmix.com/v1 (All your requests are forwarded to OpenAI's server through this URL)
1.3 WeChat Official Account
There is nothing much to say about the WeChat platform. Just log in and register your official account. Both individuals and companies can access it smoothly!
https://mp.weixin.qq.com
After the above platforms are ready, we can start the next formal development!
2.1 GPT4o_API plugin development
Why develop plugins?
I remember that after I used the COZE platform for a while, I was shocked by the rich bots and functional plug-ins in the platform! I couldn't help but wonder, can we only use these ready-made plug-in capabilities to build our robot services?
Does the platform provide a mechanism or function that allows us to freely access external API capabilities?
The answer to this question is:We encapsulate our API through plug-ins to enable access to external capabilities.
- (1) Start creating your own plug-in: Since we need to access external APIs, we choose to use the "IDE environment" here, that is, we write our own code to call external interfaces.
- (2) Write the service call code and remember to import the corresponding service dependencies and the API Key obtained from the API transfer platform.
The complete handler function body is provided here, you can copy it directly.
def handler(args: Args[Input])->Output: client = OpenAI( api_key = 'Fill in your API Key', base_url='https://aihubmix.com/v1') completion = client.chat.completions.create( model="gpt-4o", messages=[ { "role": "user", "content": [ {"type": "text", "text": "Please describe the content of this picture. The description should be interesting and humorous, and ask me questions based on the content of the picture."}, { "type": "image_url", "image_url": { "url": args.input.image, }, }, ], } ], max_tokens=300, ) return {"message": completion.choices[0].message.content}
Here is an additional plug-in for calling the DeepSeek V2 model that I developed personally. You are welcome to call it: [DeepSeek V2 plug-in] https://www.coze.cn/store/plugin/7367376039481344012?from=explore_card
2.2 Processing User Message Prompt Construction
On the COZE platform, services are provided to the outside world in the form of Bot robots.Therefore, here we need to encapsulate the plug-in in the previous step into the robot, and let the robot understand that the GPT-4o plug-in needs to be called to process specific user requests!
That is, we need to write a well-functioning Prompt instruction so that the Bot can perform logical control correctly.
## Role You are an AI chat assistant. Please use the corresponding skills to reply according to my questions and the "skill usage rules" I provided. ##Skill usage rules According to the user's function input, start the corresponding plug-in call. The function mapping relationship is as follows: 1. User sends: "DeepSeek", start calling "Conversational chat" 2. User sends: "AI song writing", start calling "Song creation" 3. User sends: "GPT-4o", start calling "Image recognition" ##Skill "Conversational chat": For any content X entered by the user, you need to call the "call_deepseek_api" API in the DeepSee_V2 plug-in, and pass the content X as the "question" parameter, and directly return the plug-in call result. "Song creation": For the song creation requirement X sent by the user, you need to call the "lyrics_to_song" API in the AI band plug-in, and extract the content X into a text array as the "lyrics" parameter and pass it in, and directly return the plug-in call result. 「Identify images」: For the image link sent by the user, you need to call the "call_gpt_4o_function" API in the ChatGPT_4o plug-in, use the image link as the image parameter, and directly return the plug-in call result.
2.3 Configure the official account
After the plug-in and Bot are developed, we only need to configure the WeChat public account (both corporate and personal accounts can be connected!)!The significance of this configuration step is to allow the messages of the WeChat public account to smoothly enter the Bot we developed, so as to realize the conversation!
- (1) First, go to the "Development Configuration" option in the WeChat public account backend to obtain the AppID of the application.
- (2) Fill in the APPID you just obtained in the WeChat public account configuration window on the COZE platform!
Congratulations, this is the last step:
3. Service Release
This is the last step of development and also the easiest step. After the previous work is completed, just click the "Publish" button and you can have fun in the official account!
If you think the tutorial is good, please like, read, bookmark, and forward it (this is really important to me! Thank you for your support)!