gpt4 book ai didi

amazon-web-services - 在 AWS LEX 中从一个意图调用另一个意图

转载 作者:行者123 更新时间:2023-12-04 21:32:04 25 4
gpt4 key购买 nike

我是 AWS 领域的新手。现在我正在研究 AWS LEX。我想从一个意图调用另一个意图。我发现了以下问题,但由于我无法发表评论,因此我创建了另一个问题。

How to call Intent B from intent A in AWS lex?

  • 我的问题是我将把上面链接中第一种方法的代码放在哪里?
  • 如何从意图调用 lambda 函数以及 JavaScript 中的代码格式是什么?
  • 最佳答案

    My question is where will i put the codes of the 1st method from the above link?



    当意图-A 被调用并且您正在回复用户时,届时您将使用该代码。基本上代替 dialogAction类型 Close我们正在使用 ConfirmIntent .
    您可以阅读有关响应格式的更多信息 here .

    完整代码:
    def build_response(message):
    return {
    "dialogAction":{
    "type":"Close",
    "fulfillmentState":"Fulfilled",
    "message":{
    "contentType":"PlainText",
    "content":message
    }
    }
    }

    def delegate(session_attributes, slots):
    return {
    'sessionAttributes': session_attributes,
    'dialogAction': {
    'type': 'Delegate',
    'slots': slots
    }
    }

    def confirm_intent(session_attributes, intent_name, slots, message):
    return {
    'sessionAttributes': session_attributes,
    'dialogAction': {
    'type': 'ConfirmIntent',
    'intentName': intent_name,
    'slots': slots,
    'message': {
    'contentType': 'PlainText',
    'content': message
    }
    }
    }

    def perform_action_A(intent_request):
    source = intent_request['invocationSource']
    output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
    slots = intent_request['currentIntent']['slots']
    # whatever you want to do
    if source == 'DialogCodeHook':
    # Perform basic validation on the supplied input slots.
    return delegate(output_session_attributes, slots)

    if source == 'FulfillmentCodeHook':
    # action fulfillment code
    msg = "Hi, I am a xxx-BOT. i can help you with following: A B C"
    return confirm_intent(output_session_attributes, 'intent-B', slots, msg)


    def perform_action_B(intent_request):
    # some code
    if source == 'DialogCodeHook':
    # Perform basic validation on the supplied input slots.
    return delegate(output_session_attributes, slots)
    if source == 'FulfillmentCodeHook':
    # action fulfillment code
    build_response('Final close message')


    def dispatch(intent_request):
    intent_name = intent_request['currentIntent']['name']
    # Dispatch to your bot's intent handlers
    if intent_name == 'intent-A':
    return perform_action_A(intent_request)
    if intent_name == 'intent-B':
    return perform_action_B(intent_request)
    raise Exception('Intent with name ' + intent_name + ' not supported')


    def lambda_handler(event, context):
    logger.debug(event)
    return dispatch(event)

    How to call a lambda function from a intent and what is the code format in javascript?



    我没有用 javascript 编写任何 lex bot,也许是 this link可能会帮助你。

    测试事件代码:
    {
    "currentIntent": {
    "name": "intent-A",
    "slots": {
    }
    },
    "invocationSource": "DialogCodeHook",
    "sessionAttributes": {},
    "bot": {
    "name": "Your_Bot_Name"
    },
    "userId": "Some_User_Id"
    }

    对于 Fulfillment 更改 invocationSource 的值至 FulfillmentCodeHook .另外,如果有的话,给插槽。

    澄清一下, configure test events用于通过模拟请求来测试 Lambda 代码。您可以直接将 Lambda 函数与 Lex 集成并使用 Lex 控制台进行测试。

    希望能帮助到你。

    编辑 1:用代码更新了答案。
    编辑 2:更新了测试事件代码。

    关于amazon-web-services - 在 AWS LEX 中从一个意图调用另一个意图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48923225/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com