簡體   English   中英

AWS LEX:插槽更新、意圖更新,然后通過 Lambda function 發布新的機器人

[英]AWS LEX: Slot update, intent update and then new publishing bot through a Lambda function

我正在寫一個 lambda function,它有一個我想放入 slotType 的單詞數組,基本上每次都更新它。 這是怎么回事。 最初,slotType 的值為 ['car', 'bus']。 下次我運行 lambda function 時,值會更新為 ['car', 'bus', 'train', 'flight'] ,這基本上是在將新數組附加到舊數組之后。

我想知道每次調用 Lambda function 時我是如何發布機器人的,所以下次我從前端點擊 lex 機器人時,它會在意圖中使用最新的 slotType 和新發布的機器人別名。 是的,還有別名!

我知道put_slot_type()正在工作,因為插槽正在機器人中更新。

這是 function,它基本上將新標簽作為參數。

def lex_extend_slots(new_labels):
    print('entering lex model...')
    lex = boto3.client('lex-models')
    slot_name = 'keysDb'
    intent_name = 'searchKeys'
    bot_name = 'photosBot'
    res = lex.get_slot_type(
        name = slot_name,
        version = '$LATEST'
    )
    current_labels = res['enumerationValues']
    latest_checksum = res['checksum']
    arr = [x['value'] for x in current_labels]
    labels = arr + new_labels
    print('arry: ', arr)
    print('new_labels', new_labels)
    print('labels in lex: ', labels)
    labels = list(set(labels))
    enumerationList = [{'value': label, 'synonyms': []} for label in labels]
    print('getting ready to push enum..: ', enumerationList)
    res_slot = lex.put_slot_type(
        name = slot_name,
        description = 'updated slots...',
        enumerationValues = enumerationList,
        valueSelectionStrategy = 'TOP_RESOLUTION',
    )
    res_build_intent = lex.create_intent_version(
        name = intent_name
    )
    res_build_bot = lex.create_bot_version(
        name = bot_name,
        checksum = latest_checksum
    )
    return current_labels

看起來您在 Boto3 上使用 Lex 模型 API 的版本 1。

您可以使用lex-models客戶端中的put_bot方法來有效地創建或更新您的 Lex bot。

put_bot方法需要完整的意圖列表來構建機器人。 值得一提的是,您首先需要使用put_intent來更新您的意圖,以確保它們使用您更新后的 slotType 的最新版本。

這是put_intent的文檔。

創建和更新別名的適當方法包含在我上面共享的同一鏈接中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM