연습 2: 새 표현 추가(AWS CLI) - Amazon Lex V1

Amazon Lex V2를 사용하는 경우 Amazon Lex V2 가이드를 대신 참조하십시오.

 

Amazon Lex V1을 사용하는 경우 봇을 Amazon Lex V2로 업그레이드하는하는 것이 좋습니다. 더 이상 V1에 새로운 기능을 추가하지 않으므로 모든 새 봇에 V2를 사용할 것을 강력히 권장합니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

연습 2: 새 표현 추가(AWS CLI)

Amazon Lex가 사용자의 요청을 인식하는 데 사용하는 기계 학습 모델을 개선하려면 봇에 다른 샘플 표현를 추가합니다.

새 표현 추가는 4단계 프로세스입니다.

  1. GetIntent 작업을 사용하여 Amazon Lex 에서 의도를 가져옵니다.

  2. 의도를 업데이트합니다.

  3. PutIntent 작업을 사용하여 업데이트된 의도를 다시 Amazon Lex로 보냅니다.

  4. GetBotPutBot 작업을 사용하여 해당 의도를 사용하는 봇을 다시 구축합니다.

이 연습에서 명령을 실행하려면 명령이 실행될 리전을 알아야 합니다. 리전 목록은 모델 구축 할당량 을 참조하십시오.

GetIntent 작업의 응답에는 의도의 특정 개정을 식별하는 checksum이라는 필드가 포함되어 있습니다. PutIntent 작업을 사용하여 의도를 업데이트하는 경우 체크섬 값을 제공해야 합니다. 체크섬 값을 제공하지 않으면 다음 오류 메시지가 표시됩니다.

            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.
        
참고

다음은 Unix, Linux, macOS용 형식으로 지정된 AWS CLI 예제입니다. Windows의 경우 "\$LATEST"$LATEST로 바꾸고, 각 줄의 끝에 있는 백슬래시(\) 연속 문자를 캐럿(^)으로 변경합니다.

OrderFlowers 의도를 업데이트하려면(AWS CLI)
  1. AWS CLI에서 Amazon Lex 의 의도를 얻으십시오. Amazon Lex는 출력을 OrderFlowers-V2.json.라는 파일로 보냅니다.

    aws lex-models get-intent \ --region region \ --name OrderFlowers \ --intent-version "\$LATEST" > OrderFlowers-V2.json
  2. 텍스트 편집기에서 OrderFlowers-V2.json을 엽니다.

    1. createdDate, lastUpdatedDateversion 필드를 찾아 삭제합니다.

    2. sampleUtterances 필드에 다음을 추가합니다.

      I want to order flowers
    3. 파일을 저장합니다.

  3. 다음 명령을 사용하여 Amazon Lex에 업데이트된 의도를 보냅니다.

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

    Amazon Lex가 다음 응답을 보냅니다.

    {
        "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"
    }

이제 의도를 업데이트했으므로 해당 의도를 사용하는 봇을 다시 구축합니다.

OrderFlowersBot 봇을 다시 구축하려면(AWS CLI)
  1. AWS CLI에서 다음 명령을 사용하여 OrderFlowersBot 봇의 정의를 가져와 파일에 저장합니다.

    aws lex-models get-bot \ --region region \ --name OrderFlowersBot \ --version-or-alias "\$LATEST" > OrderFlowersBot-V2.json
  2. 텍스트 편집기에서 OrderFlowersBot-V2.json 파일을 엽니다. createdDate, lastUpdatedDate, statusversion 필드를 제거합니다.

  3. 텍스트 편집기에서 봇 정의에 다음 줄을 추가합니다.

    "processBehavior": "BUILD",
  4. AWS CLI에서 다음 명령을 실행하여 봇의 새 개정을 구축합니다.

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

    서버에서 다음과 같이 응답합니다.

    {
        "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"
    }
    

다음 단계

연습 3: Lambda 함수 추가(AWS CLI)