LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

[JAWS-UG CLI] Amazon Lex 入門 (5) ボットのテスト

Last updated at Posted at 2017-10-22

この記事について

JAWS-UG CLI専門支部 #95 Lex入門 (秋のVUIキャンペーン第1弾)で実施するハンズオン用の手順書です。

前提条件

必要な権限

作業にあたっては、以下の権限を有したIAMユーザもしくはIAMロールを利用してください。

  • 以下のサービスの対するフルコントロール権限
    • IAM
    • Lex

0. 準備

0.1. リージョンを指定

バージニアリージョンを利用します。(リンク先にサービスが提供されているリージョンの一覧が記載されています)

API Reference

コマンド
export AWS_DEFAULT_REGION="us-east-1"

0.2. 資格情報を確認

コマンド
aws configure list

インスタンスプロファイルを設定したEC2インスタンスでアクセスキーを設定せずに実行した場合、以下のようになります。

結果
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************QSAA         iam-role
secret_key     ****************c1xY         iam-role
    region                us-west-2              env    AWS_DEFAULT_REGION

0.3. バージョン確認

コマンド
aws --version
結果
(可能な限り最新版を利用しましょう)

0.4. バージョンアップ(必要に応じて)

コマンド
sudo pip install -U awscli

0.5 変数の確認

コマンド
cat << ETX

    BOT_NAME: ${BOT_NAME}
    ALIAS: ${ALIAS}

ETX

1. テスト

作成したボットを実際に利用します。

ホットを利用する際には、lex-runtime APIを利用します。

1.1. テスト

ユーザーIDを指定します。

コマンド
USER_ID="user01"

Utteranceを指定し、ボットにテキストを投稿します。

コマンド
UTTERANCE="I would like to pick up flowers"
コマンド
aws lex-runtime post-text \
    --bot-name ${BOT_NAME} \
    --bot-alias ${ALIAS} \
    --user-id ${USER_ID} \
    --input-text "${UTTERANCE}"
結果
{
    "slotToElicit": "FlowerType",
    "slots": {
        "PickupDate": null,
        "PickupTime": null,
        "FlowerType": null
    },
    "dialogState": "ElicitSlot",
    "message": "What type of flowers would you like to order?",
    "intentName": "OrderFlowers"
}

注文したい花を指定します。

コマンド
SLOT01="rose"
コマンド
aws lex-runtime post-text \
    --bot-name ${BOT_NAME} \
    --bot-alias ${ALIAS} \
    --user-id ${USER_ID} \
    --input-text "${SLOT01}"
結果
{
    "slotToElicit": "PickupDate",
    "slots": {
        "PickupDate": null,
        "PickupTime": null,
        "FlowerType": "rose"
    },
    "dialogState": "ElicitSlot",
    "message": "What day do you want the rose to be picked up?",
    "intentName": "OrderFlowers"
}

何日に花を注文するかを指定します。

コマンド
SLOT02="one week later"
コマンド
aws lex-runtime post-text \
    --bot-name ${BOT_NAME} \
    --bot-alias ${ALIAS} \
    --user-id ${USER_ID} \
    --input-text "${SLOT02}"
結果
{
    "slotToElicit": "PickupTime",
    "slots": {
        "PickupDate": "2017-10-29",
        "PickupTime": null,
        "FlowerType": "rose"
    },
    "dialogState": "ElicitSlot",
    "message": "Pick up the rose at what time on 2017-10-29?",
    "intentName": "OrderFlowers"
}

花を何時に取りに行くかを指定します。

コマンド
SLOT03="5pm"
コマンド
aws lex-runtime post-text \
    --bot-name ${BOT_NAME} \
    --bot-alias ${ALIAS} \
    --user-id ${USER_ID} \
    --input-text "${SLOT03}"
結果
{
    "slots": {
        "PickupDate": "2017-10-29",
        "PickupTime": "17:00",
        "FlowerType": "rose"
    },
    "dialogState": "ConfirmIntent",
    "message": "Okay, your rose will be ready for pickup by 17:00 on 2017-10-29.  Does this sound okay?",
    "intentName": "OrderFlowers"
}

注文の内容に問題がないかを確認します。

コマンド
CONFIRMATION="ok"
コマンド
aws lex-runtime post-text \
    --bot-name ${BOT_NAME} \
    --bot-alias ${ALIAS} \
    --user-id ${USER_ID} \
    --input-text "${CONFIRMATION}"
結果
{
    "slots": {
        "PickupDate": "2017-10-29",
        "PickupTime": "17:00",
        "FlowerType": "rose"
    },
    "dialogState": "ReadyForFulfillment",
    "intentName": "OrderFlowers"
}

2. Utterancesの認識結果を確認

正常に認識した投稿を表示します。

【未確認】過去に同じ名前でbotを作った場合、その時の履歴が表示されるようです。

コマンド
aws lex-models get-utterances-view \
    --bot-name ${BOT_NAME} \
    --bot-versions ${BOT_VERSION} \
    --status-type Detected
結果(例)
{
    "utterances": [
        {
            "utterances": [
                {
                    "count": 2,
                    "utteranceString": "3pm",
                    "lastUtteredDate": 1508607248.116,
                    "distinctUsers": 2,
                    "firstUtteredDate": 1507450545.754
                },
                {
                    "count": 2,
                    "utteranceString": "rose",
                    "lastUtteredDate": 1508607227.027,
                    "distinctUsers": 2,
                    "firstUtteredDate": 1507450530.562
                },
                {
                    "count": 1,
                    "utteranceString": "I would like to pick up flowers",
                    "lastUtteredDate": 1508607220.256,
                    "distinctUsers": 1,
                    "firstUtteredDate": 1508607220.256
                },
                {
                    "count": 1,
                    "utteranceString": "next wednesday",
                    "lastUtteredDate": 1507450540.062,
                    "distinctUsers": 1,
                    "firstUtteredDate": 1507450540.062
                },
                {
                    "count": 1,
                    "utteranceString": "ok",
                    "lastUtteredDate": 1508607251.416,
                    "distinctUsers": 1,
                    "firstUtteredDate": 1508607251.416
                },
                {
                    "count": 1,
                    "utteranceString": "Okay",
                    "lastUtteredDate": 1507450549.931,
                    "distinctUsers": 1,
                    "firstUtteredDate": 1507450549.931
                },
                {
                    "count": 1,
                    "utteranceString": "yesterday",
                    "lastUtteredDate": 1508607235.466,
                    "distinctUsers": 1,
                    "firstUtteredDate": 1508607235.466
                },
                {
                    "count": 1,
                    "utteranceString": "pm3",
                    "lastUtteredDate": 1508607243.175,
                    "distinctUsers": 1,
                    "firstUtteredDate": 1508607243.175
                },
                {
                    "count": 1,
                    "utteranceString": "I want to order flower",
                    "lastUtteredDate": 1507450526.418,
                    "distinctUsers": 1,
                    "firstUtteredDate": 1507450526.418
                }
            ],
            "botVersion": "$LATEST"
        }
    ],
    "botName": "OrderFlowersBot"
}

正常に認識できなかった投稿を表示します。

コマンド
aws lex-models get-utterances-view \
    --bot-name ${BOT_NAME} \
    --bot-versions ${BOT_VERSION} \
    --status-type Missed
結果(例)
{
    "utterances": [
        {
            "utterances": [
                {
                    "count": 1,
                    "utteranceString": "I want flower",
                    "lastUtteredDate": 1507450511.201,
                    "distinctUsers": 1,
                    "firstUtteredDate": 1507450511.201
                }
            ],
            "botVersion": "$LATEST"
        }
    ],
    "botName": "OrderFlowersBot"
}

以上です。

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up