AI large language model can help us solve various problems, such as translation, copywriting, poetry creation, mathematical problem solving, emotional companionship, etc. Today, I will teach you how to use the NS1 serial port server module to connect to Zhipu Qingyan AI large language model and realize the dialogue with the large language model.
The NS1 module has many functions. This article will introduce how to use the Http function of the NS1 module to connect to the API of Zhipu Qingyan free large language model (glm-4-flash-250414).
The following is the functional block diagram of NS1:
The HTTP function block diagram of NS1 is as follows
Ⅰ.Zhipu Qingyan AI large language model docking process:
1. Log in to Zhipu open platform to obtain the large model API-KEY. As shown in the figure below, this is the key I obtained by logging in to Zhipu Qingyan.
Ⅱ. View the http interface document of the large language model. The following figure is introduced in the Zhipu Qingyan API docking document. We can refer to this for the configuration in the NS1 module based on the example later.
Ⅲ. Enter the NS1 WEB management page and configure the Http parameters according to the reference request example in step 2, as shown in the figure below. Several important points need to be noted in the figure:
1. The IP mode is set to dynamic because the module needs to be able to connect to the external network. If it is set to static mode, the network segment needs to be set correctly to ensure that the module can access the external network.
2. The working mode needs to be selected: HTTP client
3. Destination IP/domain name: Refer to the picture in step 2 and fill in the domain name address of the interface.
4. The port is set to 80
5. Refer to the picture in step 2. The interface uses the Post method, and the URL path is the path after removing the domain name address.
- Host in the HTTP header is the domain name address.
- Authorization is the user authentication value. Bearer <API KEY> is required. API KEY is obtained in step 1.
- Content-Type is the data transmission format used when HTTP transmission is specified. It can be seen from step 2 that it is required to be configured in application/json mode.
6. Short links need to be enabled to set the range (2-255) or as shown in the figure.
7. After setting the above parameters, submit and save the configuration!
Ⅳ. According to the http request reference example in step 2, use the serial port debugging assistant to send data in a certain data format to test the return result:
The request data marked with 1 in the figure is the format of the request body, refer to the picture settings in step 2.
- model is the requested model
- messages are the conversation information during the request.
- role is the conversation role
- content is the content of the specific conversation.
The data marked with 2 in the figure is the data returned by the big model. You can see in the figure
The content we sent to the big model is: hello, speak english
The content returned by the big model is: Hello! Yes, I can speak English. How can I help you
Friends who want to know more can check the official website HTTP request parameters for detailed information. In addition, the English used in the question in the figure is because the serial port debugging assistant will garble Chinese, and this is to demonstrate the test in English! In addition, I want to make the answer as short as possible and it is best to output the answer directly. If there is too much answer data, it may cause time to wait, so pay attention to this!
Test more effects:
Ask the big model: Tell me a story (Tell me a 100-word story in English)
The big model returns the following content:
Ask the large model: The circumference of a circle is 10. Calculate the area of this circle. Please answer directly in English.
The large model returns the following content:
That’s all for today’s sharing. EBYTE is committed to better supporting the development of IoT, intelligence, and automation, improving resource utilization, and providing more information on wireless data transmission module products such as serial port servers, data transmission radios, lora modules, etc. Interested friends can log in to our EBYTE official website to learn more, or call 400 directly to consult a technical specialist!