在生成引出槽响应时遇到问题
Having problem in generating elicit slot response
我想为某个插槽创建一个 dialogHook 更确切地说是验证类型的东西。如果插槽 returns true 那么只有我会触发我的引出插槽否则它会像 usual.Please 帮助我 approach.I 对 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'
}
)
#for fullfillment function
def close(session_attributes,fulfillment_state,message):
response={
'sessionAttributes':session_attributes,
'dialogAction':{
'type':'Close',
'fulfillmentState':fulfillment_state,
'message':message
}
}
return response
#for elicit slot return
def elicit_slot(session_attributes, intent_name,slots,slot_to_elicit,message):
response= {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'ElicitSlot',
'intentName': intent_name,
'slots': slots,
'slotToElicit': slot_to_elicit,
'message': message
}
}
return response;
def delegate(session_attributes, slots):
return {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'Delegate',
'slots': slots
}
}
实际上我的插槽应该 运行 像往常一样但是在 childExists 插槽之后我想发送一个 elicit 的响应
This is the image of the slots available
据我了解,您是在询问用户 Do you have any children
并将响应存储在 childExists
槽中,如果答案是 yes 那么您想要询问 children 的数量。
所以根据我的说法,你需要有一个额外的插槽 childCount
来存储 children 的数量。由于并不总是需要此插槽,因此 不要在 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'
}
)
希望对您有所帮助。
我想为某个插槽创建一个 dialogHook 更确切地说是验证类型的东西。如果插槽 returns true 那么只有我会触发我的引出插槽否则它会像 usual.Please 帮助我 approach.I 对 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'
}
)
#for fullfillment function
def close(session_attributes,fulfillment_state,message):
response={
'sessionAttributes':session_attributes,
'dialogAction':{
'type':'Close',
'fulfillmentState':fulfillment_state,
'message':message
}
}
return response
#for elicit slot return
def elicit_slot(session_attributes, intent_name,slots,slot_to_elicit,message):
response= {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'ElicitSlot',
'intentName': intent_name,
'slots': slots,
'slotToElicit': slot_to_elicit,
'message': message
}
}
return response;
def delegate(session_attributes, slots):
return {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'Delegate',
'slots': slots
}
}
实际上我的插槽应该 运行 像往常一样但是在 childExists 插槽之后我想发送一个 elicit 的响应 This is the image of the slots available
据我了解,您是在询问用户 Do you have any children
并将响应存储在 childExists
槽中,如果答案是 yes 那么您想要询问 children 的数量。
所以根据我的说法,你需要有一个额外的插槽 childCount
来存储 children 的数量。由于并不总是需要此插槽,因此 不要在 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'
}
)
希望对您有所帮助。