Super detailed API plug-in usage tutorial to teach you how to develop AI garbage classification robots

This article is shared from Huawei Cloud Community [Case Teaching] The Charm of Huawei Cloud API Dialogue Robot—Experience the AI ​​Garbage Classification Robot , author: Huawei Cloud PaaS Service Xiaozhi.

Experience using Huawei Cloud API to develop an AI garbage classification robot, and learn AI natural language capabilities such as sentiment analysis, text segmentation, and text translation.

1 Introduction to the API plug-in of IntelliJ IDEA

The API plug-in supports VS Code IDE, IntelliJ IDEA and other platforms, as well as Huawei Cloud's self-developed CodeArts IDE. Based on the capabilities provided by Huawei Cloud services, it helps developers build applications more efficiently and conveniently. The API plug-in is associated with API Explorer, DevStar, CodeLabs, SDK Center, and CLI Center products under Huawei Cloud Services, and is committed to providing developers with a more stable, faster, and safer programming experience.

In this plug-in, we provide but are not limited to the following functions:

Connected to the Huawei Cloud API open platform, it supports users to retrieve APIs, view API documents, debug APIs, and provide SDK sample codes for users to learn how to use APIs.

Provides Huawei Cloud SDK code snippet completion function, and SDK dependency packages are automatically introduced to accelerate users' integration of Huawei Cloud APIs.

Connected to Huawei Cloud Development Experience Center Codelabs, it provides 500+ cloud service code examples and guided tutorials to help users learn quickly.

illustrate:

On a series of platforms such as IntelliJ IDEA and VS Code IDE, the name of the Huawei Cloud API plug-in is Huawei Cloud API. In CodeArts IDE, the API plug-in is natively built into the IDE, and its name is Huawei Cloud API Development Kit.

The use of API plug-ins on series platforms such as IntelliJ IDEA and VS Code IDE depends on the base plug-in. Please install the base plug-in in advance.

2 API plug-in installation--IntelliJ IDEA

2.1 IntelliJ IDEA and other platforms

Installation preparation: Download and install JDK1.8 or higher. Download and install IntelliJ IDEA 2020.2 or higher.

Note: The IntellIj platform also supports IDEs including Goland, Pycharm, etc. If you develop on other related IDEs, please download and configure the compiler or interpreter of the corresponding language. Here we take IDEA as an example to introduce the installation process of the IntelliJ platform plug-in. For other IntelliJ series IDEs, please refer to IDEA.

Start the installation: https://developer.huaweicloud.com/develop/toolkit.html

You can download and install the offline package directly from the IDE plug-in market or directly from the JetBrains plug-in market.

IDE installation

  1. Select File > Settings in the top menu bar of IntelliJ IDEA, and click Plugins in the left navigation bar of the Settings dialog box.
  2. Click Marketplace in the Plugins area and enter Huawei Cloud API in the search bar.
  3. Huawei Cloud API will appear in the Search Results area, click Install, and restart the IDE after completion.

10001.png

Offline package installation:

  1. Enter the plug-in market and search for Huawei Cloud API, enter the plug-in details page, select the desired version of the API plug-in under the Versions tab, and click Download to download the offline plug-in compressed package and save it locally. .
  2. Select File > Settings in the top menu bar of IntelliJ IDEA, and click Plugins in the left navigation bar of the Settings dialog box.
  3. Click in the Plugins area, and then click Install Plugin from Disk....
  4. Select the offline installation package (no need to decompress it) in the Choose Plugin File dialog box, and follow the prompts on the IntelliJ IDEA installation page to complete the subsequent installation steps.

10002.png

Note: If the IntelliJ IDE you want to install the plug-in for is already open on the desktop, enter the plug-in market and search for Huawei Cloud API. Enter the plug-in details page. In the upper right corner, the locally opened IDE will be identified. Click the corresponding button. In the pop-up Click OK in the IDE window, and the IDE background will start to install the corresponding version of the API plug-in.

Installation verification: After successfully installing the plug-in on the IntelliJ series platform, you can see the Huawei Cloud Toolkit icon in the left navigation bar. Click on the back panel and the words Huawei Cloud API will appear, indicating that the installation is successful.

3 Use dialogue processes to build complex logic AI dialogue scenarios

3.1 Huawei Cloud API

10003.png

The API list is displayed on the left, and all APIs can be queried. Currently, there are 206 cloud services and APIs 9213.

https://developer.huaweicloud.com/develop/toolkit.html

b0dfa7cf-ff72-4076-a7d0-7320a0fe0593.png

3.2 Use dialogue flow to configure multiple rounds of dialogue in complex scenarios

What is a conversational bot service?

Conversational Bot Service is a cloud service based on artificial intelligence technology developed for enterprise application scenarios. It mainly includes functions such as intelligent question and answer, intelligent quality inspection, customized conversation bots, and task-based dialogue.

Skills management in conversational robot services is a tool platform for building task-based conversational skills. By creating and managing different skills and dictionaries, we can meet different user needs and achieve multi-round dialogue capabilities in different scenarios.

In this case, you will use CBS's skill management to quickly configure skills for the robot, and implement the robot's garbage classification skills through multiple rounds of dialogue.

Case goal: Master how to use CBS skills. Master how to use CBS to create garbage classification process configuration.

To experience the configuration of the garbage classification robot, you need to complete the following preparations:

Create a Huawei Cloud account and perform real-name authentication.

Register a Huawei Cloud account. To complete real-name authentication, it is recommended to use QR code authentication. https://support.huaweicloud.com/usermanual-account/zh-cn_topic_0133456714.html

Download data:

.
├── DB_query_rubbish_type.py
└── rubbish_dict.txt

Create a trial version of the intelligent Q&A robot: Since skill management is a function under the professional version of the intelligent Q&A robot, first we need to purchase a trial version of the professional version of the Q&A robot. Click this link to enter the dialogue robot service intelligent question and answer robot page. Click Purchase Question and Answer Robot in the upper right corner to enter the question and answer robot purchase page. https://console.huaweicloud.com/cbs/?region=cn-north-4#/home/qa-robot

1694583836383733980.png

Enter the name of the Q&A robot respectively, select the trial billing mode, and click Buy Now to complete the payment. This completes the creation of the trial professional version robot.

After the Q&A robot is successfully created, return to the main page of the conversation robot service. After waiting for the robot to be successfully created, click "Robot Name" to enter the robot. There will be a skill management in the tab bar on the left.

10006.png

Create a dictionary:

To add a garbage type dictionary, enter the conversation robot service, click to enter the corresponding robot, click "Skills Platform", then click the "Entity Management" button, and follow the guidance below to add a garbage type dictionary: https://console.huaweicloud.com/cbs /?region=cn-north-4#/home/qa-robot

10007.png

Dictionary identifier : rubbish

Dictionary name : Junk items

Click the "Confirm" button to create the dictionary and enter the "Edit" page.

Import terms

Click the "Import" button on the page, then click the "Add File" button, upload the rubbish_dict.txt file in the local folder, select "Append" for the import mode, and finally click the "OK" button to complete the garbage dictionary entry Import. As shown below:

10008.png

Skill configuration:

In this section, we will add corpus and annotation, and configure the robot's "garbage classification" skills.

Click this link, https://console.huaweicloud.com/cbs/?region=cn-north-4#/home/qa-robot . Enter the "Skills Management" of the conversational robot service, create a new garbage classification skill and configure the skill.

Create skills

Click the "Add Skill" button, select "Multiple Rounds of Dialogue Skills", click Next, enter the skill name: Garbage Classification, as shown in the figure below:

10009.png

Create an intent:

After the skill is created, click to enter the "Garbage Classification" skill, click the "Create" button in the intention list, and fill in the instructions as shown below:

1694583989606562219.png

Intent identifier: query_rubbish_type

Intent name: Determine the type of garbage

Then click the "Confirm and continue setup" button to continue configuring the intent.

Add user question materials

Enter the "User Questioning Method" of the "Determine the Type of Garbage" purpose, click the blue font "Batch Add User Questioning Material" below the "User Questioning Material" input box, copy the corpus below to the pop-up dialog box, and click "Confirm" Complete the expected import of user questions.

What to do with books

What kind of garbage are books?

Does other trash include toothpicks?

There is hand cream in other garbage

How to recycle toilet paper

What kind of garbage does toilet paper belong to?

Does food waste include apple peels?

Are there potato peels in kitchen waste?

How to dispose of Coke bottles

Does recyclable waste include iron sheets?

After adding the corpus, slide the page to the bottom and click "Save". The following results can be obtained:

10011.png

Add slot

Scroll down the page, find the "Slot Management" page, create the slot: rubbish (junk category), then click the "Add Slot" button, and follow the following guidance to add the rubbish_goods slot:

10012.png

Associated slot: Not associated

Slot ID: rubbish_goods

Slot name: Junk items

Is it necessary: ​​Yes

Number of questioning rounds: 1

Input box: Can you be more specific?

Dictionary selection: rubbish

Answer candidates: Unchecked

Then click the "OK" button. After the slot is added, slide the page to the bottom and click "Save".

Corpus annotation:

Swipe up the page, return to "User Questions", and annotate the corpus in the "User Questions Materials" list.

Select the keyword, and then use the slot to mark the keyword.

After the annotation is completed, it will appear as shown below:

10013.png

Add user question template

Click the "User Question Template" page in "User Question" to add a template.

Click the "Add Template" button. The template content is as shown in the figure below. Click the slot name below at the corresponding position to insert the corresponding slot. After completing the configuration, users can use the template's questions to talk to the robot.

Add template:

10014.png

After adding the question template, slide the page to the bottom and click "Save".

Configure conversation flow

Click "Configure Dialog Process" to complete complex dialog logic configuration.

Drag a "Conditional Judgment" node from the left node bar to below the "Dialogue Start" node, and connect the two points.

10015.png

Click "Conditional Judgment" to complete the settings as shown below:

10016.png

Then drag an "Information Collection" node from the left node bar to below the "Conditional Judgment" node, and connect the two nodes, as shown in the following figure:

10017.png

10018.png

10019.png

10020.png

For function configuration, please refer to Chapter 6 in this link:

https://codelabs.developer.huaweicloud.com/codelabs/samples/039d02c2d9af4d3eba24b652675976f9

The function reference code is as follows:

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Version : Python 3.6
import json
import requests
# Define a garbage type processing suggestion dictionary
rubbish_info = {
    0: "When sorting recyclables, they should be kept clean and dry to avoid contamination, and should be handled with care; waste paper should be kept as flat as possible; three-dimensional packaging should be emptied of its contents and flattened after cleaning; items with sharp edges and corners should be wrapped Posted later.",
    1: "Rechargeable batteries, button batteries, and accumulators should be handled with care when disposing them; if there are any residues in paint buckets and pesticides, please seal them tightly before disposing them; fluorescent lamps and energy-saving lamps are easily damaged and must be packaged or wrapped before disposing them; waste drugs and their packaging should be disposed of Put them in the trash together.",
    2: "Food waste with packaging should be taken out and sorted and put away; large bones, coconut shells, durian shells, etc. are not easy to biochemically degrade and should be put out as dry garbage; pure liquid (such as milk, etc.) food waste can be poured directly into the drain; the rest should be drained before putting it into the food waste bin.",
    3: "Dry garbage should be drained as much as possible and put into dry garbage containers.",
}

# Call the garbage classification API
def get_response(word, mode=1):
    """
    Call Tianxing API interface to obtain garbage classification information
    :param word: The junk items to be queried
    :return: Return the classification information of junk items
    """
    key = "replace with apikey" # You can visit https://www.tianapi.com/ to register and obtain apikey
    url = "http://api.tianapi.com/lajifenlei/index"
    data = {
        "key": key,
        "word": word,
        "mode": mode,
    }
    headers = {'Content-type': 'application/x-www-form-urlencoded'}
    res = requests.post(url, data=data, headers=headers, verify=False)
    return res.json()
# Function entry
def handler(event, context):
    """
    """
    slot_temp = json.dumps(event, ensure_ascii=False)
    slot_info = json.loads(slot_temp)
    log = context.getLogger()
    log.info(slot_temp)
# Get slot information, that is, the value obtained by the slot
    word = slot_info.get("goods", None)
    result = {
        "content": "I don't know what this is, let's change it to a junk item~"
    }
    if word:
        res = get_response(word)
# Determine API response code
        if res['code'] != 200:
            result["content"] = "Insufficient data source resources!"
            return json.dumps(result, ensure_ascii=False)
        all_data_list = res.get("newslist", [{}])
        filter_data_list = list(filter(lambda x: x.get("name", "") == word, all_data_list))
        if filter_data_list:
            _type = filter_data_list[0].get("type", 4)
            rubbish_result = ""
            log.info (word)
# Splice the return value according to the garbage type
            if _type == 0:
                rubbish_result = "{} is recyclable garbage. Suggestion for placement: {}".format(word, rubbish_info[_type])
            elif _type == 1:
                rubbish_result = "{} is hazardous waste. Suggestions for placing it: {}".format(word, rubbish_info[_type])
            elif _type == 2:
                rubbish_result = "{} is kitchen waste (i.e. wet waste). Suggestions for placing: {}".format(word, rubbish_info[_type])
            elif _type == 3:
                rubbish_result = "{} is other garbage (that is, dry garbage). Suggestions for placing: {}".format(word, rubbish_info[_type])
            else:
                pass
            if rubbish_result:
                result["content"] = rubbish_result
    logg.info(json.dumps(result, ensure_ascii=False))
return json.dumps(result, ensure_ascii=False)

 

Model training release

On the "Garbage Classification Skills" page, enter the "Publish Test" page, click the "Training Model" button, check "User Frequently Asked Questions", and the skill threshold is the default. Click "OK" to start model training, which takes about 3 minutes.

10021.png

After the model training is completed, click the "Online Publish" button to publish the model.

10022.png

Skill experience:

After the model is released, return to the "Skill Management" page and click the "Conversation Experience" button in the upper right corner

The picture below is a sample conversation:

10023.png

4 References

https://support.huaweicloud.com/usermanual-cbs/cbs_01_0029.html

https://console.huaweicloud.com/cbs/?region=cn-north-4#/cbs/management/skills

5 Experience the charm of plug-ins

Huawei Cloud devkit is online

https://developer.huaweicloud.com/develop/toolkit.html

Click to follow and learn about Huawei Cloud’s new technologies as soon as possible~

 

JetBrains releases Rust IDE: RustRover Java 21 / JDK 21 (LTS) GA With so many Java developers in China, an ecological-level application development framework .NET 8 should be born. The performance is greatly improved, and it is far ahead of .NET 7. PostgreSQL 16 is released by a former member of the Rust team I deeply regret and asked to cancel my name. I completed the removal of Nue JS on the front end yesterday. The author said that I will create a new Web ecosystem. NetEase Fuxi responded to the death of an employee who was "threatened by HR due to BUG". Ren Zhengfei: We are about to enter the fourth industrial revolution, Apple Is Huawei's teacher Vercel's new product "v0": Generate UI interface code based on text
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4526289/blog/10112268