简体   繁体   English

AWS LEX:插槽更新、意图更新,然后通过 Lambda function 发布新的机器人

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

I am writing a lambda function that has an array of words that I want to put into a slotType, basically updating it every time.我正在写一个 lambda function,它有一个我想放入 slotType 的单词数组,基本上每次都更新它。 Here is how it goes.这是怎么回事。 Initially, the slotType has values ['car', 'bus'].最初,slotType 的值为 ['car', 'bus']。 Next time I run the lambda function the values get updated to ['car', 'bus', 'train', 'flight'] which is basically after appending a new array into the old one.下次我运行 lambda function 时,值会更新为 ['car', 'bus', 'train', 'flight'] ,这基本上是在将新数组附加到旧数组之后。

I want to know how I publish the bot every time the Lambda function gets invoked so the next time I hit the lex bot from the front-end, it uses the latest slotType in the intent and newly published bot alias.我想知道每次调用 Lambda function 时我是如何发布机器人的,所以下次我从前端点击 lex 机器人时,它会在意图中使用最新的 slotType 和新发布的机器人别名。 Yep, also the alias!是的,还有别名!

I know for a fact that the put_slot_type() is working because the slot is getting updated in the bot.我知道put_slot_type()正在工作,因为插槽正在机器人中更新。

Here is the function which basically takes in new labels as parameters.这是 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

It looks like you're using Version 1 of the Lex Models API on Boto3.看起来您在 Boto3 上使用 Lex 模型 API 的版本 1。

You can use the put_bot method in the lex-models client to effectively create or update your Lex bot.您可以使用lex-models客户端中的put_bot方法来有效地创建或更新您的 Lex bot。

The put_bot method expects the full list of intents to be used for building the bot. put_bot方法需要完整的意图列表来构建机器人。 It is worth mentioning that you will first need to use put_intent to update your intents to ensure they use the latest version of your updated slotType.值得一提的是,您首先需要使用put_intent来更新您的意图,以确保它们使用您更新后的 slotType 的最新版本。

Here's the documentation for put_intent .这是put_intent的文档。

The appropriate methods for creating and updating aliases are contained in the same link that I've shared above.创建和更新别名的适当方法包含在我上面共享的同一链接中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM