[3] Tmall elf open experimental platform experiment - switching intention, parameter transfer

Keywords: AI Alibaba Cloud

Tmall elf open experimental platform experiment - switching intention, parameter transfer

Reference link: AliGenie - skill application platform

1, Create two intentions

Then, in the first two experiments, we continue to create new two intentions to realize the speech skills associated with multiple intentions.

Through learning, you will master:

  • How to associate two intentions

  • How to implement the backend code

  • Online test implementation function

1. Configure weather quality query intent

(1) Create intent

Open the previously created voice skills and enter the voice interaction model module.

(2) Click "create intention" to create weather query intention.

(3) Fill in the Chinese name and intention logo.

(4) Configure single round dialogue corpus

(5) Configure pre intent

When switching from "weather query" intention to "air quality query" intention:

  • Weather query intention is the pre intention of air quality query intention, which needs to be configured in the air quality query intention;
  • Configure parameter transfer rule: pre intention ID. parameter name in pre intention, for example: {weather.city}.

(6) The intent is to create a complete commit save.

2. Deploy back-end services.

(1) Go to development.

(2) Modify the previous code.

After entering the CloudIDE platform, the code edited in the previous lesson will be displayed. This time, you can edit the new skill code on the basis of the original one.

package com.alibaba.ailabs;

import com.alibaba.ailabs.common.AbstractEntry;
import com.alibaba.da.coin.ide.spi.meta.AskedInfoMsg;
import com.alibaba.da.coin.ide.spi.meta.ExecuteCode;
import com.alibaba.da.coin.ide.spi.meta.ResultType;
import com.alibaba.da.coin.ide.spi.standard.ResultModel;
import com.alibaba.da.coin.ide.spi.standard.TaskQuery;
import com.alibaba.da.coin.ide.spi.standard.TaskResult;
import com.alibaba.fastjson.JSON;
import com.aliyun.fc.runtime.Context;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description Tmall elf skill function entry, FC
 *              handler: com.alibaba.ailabs.GenieEntry::handleRequest
 * @Version 1.0
 **/
public class GenieEntry extends AbstractEntry {

  @Override
    public ResultModel<TaskResult> execute(TaskQuery taskQuery, Context context) {
        context.getLogger().info("taskQuery: " + JSON.toJSONString(taskQuery));
        // ResultModel<TaskResult> res = new ResultModel<>();
        TaskResult taskResult = new TaskResult();
        // Get the intention parameter and parameter value from the request
        Map<String, String> paramMap = taskQuery.getSlotEntities().stream().collect(Collectors.toMap(slotItem -> slotItem.getIntentParameterName(), slotItem -> slotItem.getOriginalValue()));
         //The intention of dealing with the name welcome
        if ("welcome".equals(taskQuery.getIntentName())) {
             taskResult.setReply("Welcome to the weather Xiaomi. You can check the weather with Xiaomi");
            //Handle the intent with the name weather
        } else if ("weather".equals(taskQuery.getIntentName())) {
            //The date parameter in the weather intention is checked as required. The request data must carry the date parameter. You only need to judge whether the city parameter exists.
            if (paramMap.get("city") == null) {
                taskResult.setReply("Which city do you want to inquire about the weather?");
                return askReply(taskResult, "city", taskQuery.getIntentId());
            }
            //TODO obtains weather information according to parameters. Here, false data is used instead
           taskResult.setReply(paramMap.get("city") + paramMap.get("sys.date(public entity)") + "The weather is fine");

            //The process name is ari_quality intent
        }else if ("ari_quality".equals(taskQuery.getIntentName())) {

            //air_ If the date parameter in the quality intention is checked as required, the date parameter must be carried in the request data. You only need to judge whether the city parameter exists.
            if (paramMap.get("city") == null) {
               taskResult.setReply("Which city do you want to inquire about air quality?");
                return askReply(taskResult, "city", taskQuery.getIntentId());
            }

            //TODO obtains the air quality information according to the parameters. Here, false data is used instead
            taskResult.setReply(paramMap.get("city") + paramMap.get("sys.date(public entity)") + "Excellent air quality");
            //Other intentions
        }else {
            taskResult.setReply("Please check whether the intention name is correct, or the new intention does not add the corresponding processing branch in the code.");
        }
        return reply(taskResult);
      }

    /**
     * End the conversation and close the speaker after replying
     */
      private ResultModel<TaskResult> reply(TaskResult taskResult) {
        ResultModel<TaskResult> res = new ResultModel<>();
        taskResult.setExecuteCode(ExecuteCode.SUCCESS);
        taskResult.setResultType(ResultType.RESULT);
        res.setReturnCode("0");
        res.setReturnValue(taskResult);
        return res;
    }
    /**
     * Specify the questioning parameters, the speaker will open the microphone automatically, and the user's answer will first match the questioning parameters
     */
      private ResultModel<TaskResult> askReply(TaskResult taskResult, String parameterName, Long intentId) {
        ResultModel<TaskResult> res = new ResultModel<>();
        taskResult.setExecuteCode(ExecuteCode.SUCCESS);
        taskResult.setResultType(ResultType.ASK_INF);
        AskedInfoMsg askedInfoMsg = new AskedInfoMsg();
        askedInfoMsg.setIntentId(intentId);
        askedInfoMsg.setParameterName(parameterName);
        List<AskedInfoMsg> askedInfos = new ArrayList<>();
        askedInfos.add(askedInfoMsg);
        taskResult.setAskedInfos(askedInfos);
        res.setReturnValue(taskResult);
        return res;
    }
}

(3) Submit code.

After completing the code writing, submit the code to the warehouse, otherwise there will be no more. Submission steps: click source code management, and then click the submit button.

#Prevent code loss and upload to remote branch.
[admin@980ebc02-4e66-493b-9bfe-f64a4455309d-677dd68b4b-794h4 /home/admin/workspace/codeup.aliyun.com/618249ae404574409feabd87/workbench/repo_2021-11-03_2021110301471207]
$git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

[admin@980ebc02-4e66-493b-9bfe-f64a4455309d-677dd68b4b-794h4 /home/admin/workspace/codeup.aliyun.com/618249ae404574409feabd87/workbench/repo_2021-11-03_2021110301471207]
$fit add src
sh: fit: command not found

[admin@980ebc02-4e66-493b-9bfe-f64a4455309d-677dd68b4b-794h4 /home/admin/workspace/codeup.aliyun.com/618249ae404574409feabd87/workbench/repo_2021-11-03_2021110301471207]
$git commit -m "ari_quality"
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

[admin@980ebc02-4e66-493b-9bfe-f64a4455309d-677dd68b4b-794h4 /home/admin/workspace/codeup.aliyun.com/618249ae404574409feabd87/workbench/repo_2021-11-03_2021110301471207]
$git push
Counting objects: 18, done.
Delta compression using up to 5 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (18/18), 1.88 KiB | 71.00 KiB/s, done.
Total 18 (delta 5), reused 0 (delta 0)
To https://codeup.aliyun.com/618249ae404574409feabd87/workbench/repo_2021-11-03_2021110301471207.git
   356d325..a79d046  master -> master

[admin@980ebc02-4e66-493b-9bfe-f64a4455309d-677dd68b4b-794h4 /home/admin/workspace/codeup.aliyun.com/618249ae404574409feabd87/workbench/repo_2021-11-03_2021110301471207]
$^C

(4) Deployment services.


Click continue deployment.

(5) Deployment succeeded.

3. Voice skills online test.

Posted by wrongmove18 on Thu, 04 Nov 2021 06:00:22 -0700