亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在生成引出槽響應時遇到問題

在生成引出槽響應時遇到問題

慕碼人8056858 2022-01-05 11:28:27
我想為某個插槽創建一個 dialogHook,而不是說驗證類型的事情。如果插槽返回 true,那么只有我會觸發我的誘導插槽,否則它會照常進行。請幫助我的方法是什么。我是對 lex 來說相對較新。我試圖在 childExists 上創建一個對話鉤子,但它不起作用。def lambda_handler(event,context):    os.environ['TZ']='America/New_York'    time.tzset();    logger.debug('event.bot.name={}'.format(event['bot']['name']))    return dispatch(event);def dispatch(intent_request):    intent_name=intent_request['currentIntent']['name']    if intent_name=='HotelReservation':        return book_hotel(intent_request)def book_hotel(intent_request):    slots=intent_request['currentIntent']['slots']    welcome=intent_request['currentIntent']['slots']['welcome']    location=intent_request['currentIntent']['slots']['Location']    fromDate=intent_request['currentIntent']['slots']['FromDate']    adultCount=intent_request['currentIntent']['slots']['adultCount']    nights=intent_request['currentIntent']['slots']['nights']    childExists=intent_request['currentIntent']['slots']['childExists']    source=intent_request['invocationSource']    session_attributes={}    if source=='DialogCodeHook'and childExists.lower()=='yes':        session_attributes={}        return elicit_slot (        session_attributes,            'HotelReservation',            'childCount',             'AMAZON.NUMBER',                        {            'contentType':'PlainText',            'content':'Please enter number of Children'            }        )    elif source=='DialogCodeHook':        output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}        return delegate(output_session_attributes, intent_request['currentIntent']['slots'])    else:        return close (            session_attributes,                'Fulfilled',{                'contentType':'PlainText',                'content':'Here is the temparature in'                }            )實際上我的插槽應該像往常一樣運行,但是在 childExists 插槽之后我想發送一個 elicit 響應 這是可用插槽的圖像
查看完整描述

1 回答

?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

根據我的理解,您正在詢問用戶Do you have any children并將響應存儲在childExists插槽中,如果答案是肯定的,那么您想詢問孩子的數量。


所以根據我的說法,你需要有一個額外的插槽childCount來存儲孩子的數量。由于此插槽并非總是必需的,因此請勿在 amazon lex 控制臺中將其標記為必需。


現在,您將在您的 中檢查這一點DialogCodeHook,并僅childExists == 'yes'在childCount. 我們使用這些條件的組合是為了確保它不會無限期地運行。


def book_hotel(intent_request):

    slots = intent_request['currentIntent']['slots']

    welcome = slots['welcome']

    location = slots['Location']

    fromDate = slots['FromDate']

    adultCount = slots['adultCount']

    nights = slots['nights']

    childExists = slots['childExists']

    childCount = slots['childCount']

    source = intent_request['invocationSource']

    if source == 'DialogCodeHook':

        output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}

        if childExists.lower() == 'yes':

            if not childCount:

                return elicit_slot (

                    output_session_attributes,

                    'HotelReservation',

                    slots,

                    'childCount',            

                        {

                            'contentType':'PlainText',

                            'content':'Please enter number of Children'

                        }

                    )

        return delegate(output_session_attributes, intent_request['currentIntent']['slots'])


    if source == 'FulfillmentCodeHook':

        return close (

            output_session_attributes,

                'Fulfilled',{

                'contentType':'PlainText',

                'content':'Here is the temparature in'

                }

            )

希望能幫助到你。


查看完整回答
反對 回復 2022-01-05
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號