Latihan 2: Tambahkan Ucapan Baru ()AWS CLI - Amazon Lex V1

Pemberitahuan akhir dukungan: Pada 15 September 2025, AWS akan menghentikan dukungan untuk Amazon Lex V1. Setelah 15 September 2025, Anda tidak lagi dapat mengakses konsol Amazon Lex V1 atau sumber daya Amazon Lex V1. Jika Anda menggunakan Amazon Lex V2, lihat panduan Amazon Lex V2 sebagai gantinya.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Latihan 2: Tambahkan Ucapan Baru ()AWS CLI

Untuk meningkatkan model pembelajaran mesin yang digunakan Amazon Lex untuk mengenali permintaan dari pengguna Anda, tambahkan contoh ucapan lain ke bot.

Menambahkan ucapan baru adalah proses empat langkah.

  1. Gunakan GetIntent operasi untuk mendapatkan maksud dari Amazon Lex.

  2. Perbarui maksudnya.

  3. Gunakan PutIntent operasi untuk mengirim intent yang diperbarui kembali ke Amazon Lex.

  4. Gunakan GetBot dan PutBot operasi untuk membangun kembali bot apa pun yang menggunakan intent.

Untuk menjalankan perintah dalam latihan ini, Anda perlu mengetahui wilayah di mana perintah akan dijalankan. Untuk daftar wilayah, lihat Kuota Bangunan Model .

Respons dari GetIntent operasi berisi bidang yang disebut checksum yang mengidentifikasi revisi spesifik dari maksud. Anda harus memberikan nilai checksum saat Anda menggunakan PutIntent operasi untuk memperbarui maksud. Jika tidak, Anda akan mendapatkan pesan galat berikut:

            An error occurred (PreconditionFailedException) when calling 
            the PutIntent operation: Intent intent name already exists. 
            If you are trying to update intent name you must specify the 
            checksum.
        
catatan

AWS CLI Contoh berikut diformat untuk Unix, Linux, dan macOS. Untuk Windows, ubah "\$LATEST" ke $LATEST dan ganti karakter kelanjutan garis miring terbalik (\) di akhir setiap baris dengan tanda sisipan (^).

Untuk memperbarui OrderFlowers intent ()AWS CLI
  1. Di AWS CLI, dapatkan niat dari Amazon Lex. Amazon Lex mengirimkan output ke file bernama OrderFlowers-V2.json.

    aws lex-models get-intent \ --region region \ --name OrderFlowers \ --intent-version "\$LATEST" > OrderFlowers-V2.json
  2. Buka OrderFlowers-V2.json di editor teks.

    1. Temukan dan hapuscreatedDate,lastUpdatedDate, dan version bidang.

    2. Tambahkan yang berikut ini ke sampleUtterances bidang:

      I want to order flowers
    3. Simpan file tersebut.

  3. Kirim intent yang diperbarui ke Amazon Lex dengan perintah berikut:

    aws lex-models put-intent \ --region region \ --name OrderFlowers \ --cli-input-json file://OrderFlowers-V2.json

    Amazon Lex mengirimkan tanggapan berikut:

    {
        "confirmationPrompt": {
            "maxAttempts": 2, 
            "messages": [
                {
                    "content": "Okay, your {FlowerType} will be ready for pickup by {PickupTime} on {PickupDate}.  Does this sound okay?", 
                    "contentType": "PlainText"
                }
            ]
        }, 
        "name": "OrderFlowers", 
        "checksum": "checksum", 
        "version": "$LATEST", 
        "rejectionStatement": {
            "messages": [
                {
                    "content": "Okay, I will not place your order.", 
                    "contentType": "PlainText"
                }
            ]
        }, 
        "createdDate": timestamp, 
        "lastUpdatedDate": timestamp, 
        "sampleUtterances": [
            "I would like to pick up flowers", 
            "I would like to order some flowers", 
            "I want to order flowers"
        ], 
        "slots": [
            {
                "slotType": "AMAZON.TIME", 
                "name": "PickupTime", 
                "slotConstraint": "Required", 
                "valueElicitationPrompt": {
                    "maxAttempts": 2, 
                    "messages": [
                        {
                            "content": "Pick up the {FlowerType} at what time on {PickupDate}?", 
                            "contentType": "PlainText"
                        }
                    ]
                }, 
                "priority": 3, 
                "description": "The time to pick up the flowers"
            }, 
            {
                "slotType": "FlowerTypes", 
                "name": "FlowerType", 
                "slotConstraint": "Required", 
                "valueElicitationPrompt": {
                    "maxAttempts": 2, 
                    "messages": [
                        {
                            "content": "What type of flowers would you like to order?", 
                            "contentType": "PlainText"
                        }
                    ]
                }, 
                "priority": 1, 
                "slotTypeVersion": "$LATEST", 
                "sampleUtterances": [
                    "I would like to order {FlowerType}"
                ], 
                "description": "The type of flowers to pick up"
            }, 
            {
                "slotType": "AMAZON.DATE", 
                "name": "PickupDate", 
                "slotConstraint": "Required", 
                "valueElicitationPrompt": {
                    "maxAttempts": 2, 
                    "messages": [
                        {
                            "content": "What day do you want the {FlowerType} to be picked up?", 
                            "contentType": "PlainText"
                        }
                    ]
                }, 
                "priority": 2, 
                "description": "The date to pick up the flowers"
            }
        ], 
        "fulfillmentActivity": {
            "type": "ReturnIntent"
        }, 
        "description": "Intent to order a bouquet of flowers for pick up"
    }

Sekarang setelah Anda memperbarui intent, buat kembali bot apa pun yang menggunakannya.

Untuk membangun kembali OrderFlowersBot bot ()AWS CLI
  1. Di AWS CLI, dapatkan definisi OrderFlowersBot bot dan simpan ke file dengan perintah berikut:

    aws lex-models get-bot \ --region region \ --name OrderFlowersBot \ --version-or-alias "\$LATEST" > OrderFlowersBot-V2.json
  2. Dalam editor teks, bukaOrderFlowersBot-V2.json. HapuscreatedDate,lastUpdatedDate, status dan version bidang.

  3. Dalam editor teks, tambahkan baris berikut ke definisi bot:

    "processBehavior": "BUILD",
  4. Di AWS CLI, buat revisi baru bot dengan menjalankan perintah berikut untuk:

    aws lex-models put-bot \ --region region \ --name OrderFlowersBot \ --cli-input-json file://OrderFlowersBot-V2.json

    Tanggapan dari server adalah:

    {
        "status": "BUILDING", 
        "intents": [
            {
                "intentVersion": "$LATEST", 
                "intentName": "OrderFlowers"
            }
        ], 
        "name": "OrderFlowersBot", 
        "locale": "en-US", 
        "checksum": "checksum", 
        "abortStatement": {
            "messages": [
                {
                    "content": "Sorry, I'm not able to assist at this time", 
                    "contentType": "PlainText"
                }
            ]
        }, 
        "version": "$LATEST", 
        "lastUpdatedDate": timestamp, 
        "createdDate": timestamp 
        "clarificationPrompt": {
            "maxAttempts": 2, 
            "messages": [
                {
                    "content": "I didn't understand you, what would you like to do?", 
                    "contentType": "PlainText"
                }
            ]
        }, 
        "voiceId": "Salli", 
        "childDirected": false, 
        "idleSessionTTLInSeconds": 600, 
        "description": "Bot to order flowers on the behalf of a user"
    }
    

Langkah Selanjutnya

Latihan 3: Tambahkan Fungsi Lambda ()AWS CLI