AWS Lex Python Codehook 参考
AWS Lex Python Codehook references
我对 Python(和编码)还是很陌生,但我正在尝试使用 Lambda 函数构建我自己的 Lex 机器人。我一直在关注教程,我可以理解它是如何工作的。问题是当我尝试为 Lex 编写自己的 Lambda 函数时,我找不到任何参考来帮助我编写代码,例如查看下面的代码。
def get_slots(intent_request):
return intent_request['currentIntent']['slots']
什么是“(intent_request)”,我在哪里可以找到它的参考资料?与“['currentIntent'] 相同,我怎样才能找出它是什么以及为什么它在那里??
抱歉,如果这对这里的大多数人来说似乎很愚蠢,但我无法开始编写代码并继续学习,如果我找不到任何文档来说明这些是什么以及为什么需要它们才能编写代码对于我自己的 Lex 机器人。
提前致谢!!!
intent_request
是从 Lex 到您的 Lambda 函数的传入 "request" 或 "event"。它包含有关用户输入和您的 Lex 机器人对该输入的处理的所有必要信息(触发特定意图、填充特定槽、确认等)
这应该是您要查找的文档。
Lambda Function Input Event and Response Format:
This section describes the structure of the event data that Amazon Lex provides to a Lambda function. Use this information to parse the input in your Lambda code. It also explains the format of the response that Amazon Lex expects your Lambda function to return.
这里是 Event/Request 格式:
{
"currentIntent": {
"name": "intent-name",
"slots": {
"slot name": "value",
"slot name": "value"
},
"slotDetails": {
"slot name": {
"resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" }
],
"originalValue": "original text"
},
"slot name": {
"resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" }
],
"originalValue": "original text"
}
},
"confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
},
"bot": {
"name": "bot name",
"alias": "bot alias",
"version": "bot version"
},
"userId": "User ID specified in the POST request to Amazon Lex.",
"inputTranscript": "Text used to process the request",
"invocationSource": "FulfillmentCodeHook or DialogCodeHook",
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
"messageVersion": "1.0",
"sessionAttributes": {
"key": "value",
"key": "value"
},
"requestAttributes": {
"key": "value",
"key": "value"
}
}
slots
数据在 currentIntent
中找到,并且在整个 intent_request
对象中。这就是您看到代码的原因:intent_request['currentIntent']['slots']
因此,要获取会话属性,您可以在此处找到它们:intent_request['sessionAttributes']
同样非常有用的是准确的用户输入文本:
intent_request['inputTranscript']
我对 Python(和编码)还是很陌生,但我正在尝试使用 Lambda 函数构建我自己的 Lex 机器人。我一直在关注教程,我可以理解它是如何工作的。问题是当我尝试为 Lex 编写自己的 Lambda 函数时,我找不到任何参考来帮助我编写代码,例如查看下面的代码。
def get_slots(intent_request):
return intent_request['currentIntent']['slots']
什么是“(intent_request)”,我在哪里可以找到它的参考资料?与“['currentIntent'] 相同,我怎样才能找出它是什么以及为什么它在那里??
抱歉,如果这对这里的大多数人来说似乎很愚蠢,但我无法开始编写代码并继续学习,如果我找不到任何文档来说明这些是什么以及为什么需要它们才能编写代码对于我自己的 Lex 机器人。
提前致谢!!!
intent_request
是从 Lex 到您的 Lambda 函数的传入 "request" 或 "event"。它包含有关用户输入和您的 Lex 机器人对该输入的处理的所有必要信息(触发特定意图、填充特定槽、确认等)
这应该是您要查找的文档。
Lambda Function Input Event and Response Format:
This section describes the structure of the event data that Amazon Lex provides to a Lambda function. Use this information to parse the input in your Lambda code. It also explains the format of the response that Amazon Lex expects your Lambda function to return.
这里是 Event/Request 格式:
{
"currentIntent": {
"name": "intent-name",
"slots": {
"slot name": "value",
"slot name": "value"
},
"slotDetails": {
"slot name": {
"resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" }
],
"originalValue": "original text"
},
"slot name": {
"resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" }
],
"originalValue": "original text"
}
},
"confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
},
"bot": {
"name": "bot name",
"alias": "bot alias",
"version": "bot version"
},
"userId": "User ID specified in the POST request to Amazon Lex.",
"inputTranscript": "Text used to process the request",
"invocationSource": "FulfillmentCodeHook or DialogCodeHook",
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
"messageVersion": "1.0",
"sessionAttributes": {
"key": "value",
"key": "value"
},
"requestAttributes": {
"key": "value",
"key": "value"
}
}
slots
数据在 currentIntent
中找到,并且在整个 intent_request
对象中。这就是您看到代码的原因:intent_request['currentIntent']['slots']
因此,要获取会话属性,您可以在此处找到它们:intent_request['sessionAttributes']
同样非常有用的是准确的用户输入文本:
intent_request['inputTranscript']