我正在使用Python 2.7来创建Alexa技能。我在Python中创建了一个lambda函数并将其连接到Alexa技能。从开始到结束的所有步骤在测试中都很有效,但在Amazon Echo Device中不起作用。它说“回应存在一些问题”。完全模糊。我不知道如何调试这个。任何人都可以在这里建议我的选择吗?我理解如果某些东西在测试中起作用,它也应该在设备中工作。这是一个常见的问题吗?
总结一下,我正在寻找以下两个问题的答案:
提前感谢您的帮助。
答案 0 :(得分:2)
你可以尝试几件事,
一个。确保您已为已注册回声的语言创建了交互模型(例如: - 如果您的英语(英国)的回声设置,那么您应该需要英语(英国)的交互模型。请参见附图。)
湾如果您已经具有上述设置,请针对您的Lambda函数检查CloudWatch中的日志。如果您遇到问题,则会在日志中进行跟踪。
答案 1 :(得分:0)
我想分享一下我是如何解决这个问题的。我使用的是Python API。我查看了CloudWatch中的日志,由于某种原因,它在session_attributes中抛出了KeyError,这是一个传递的字典。为了澄清,这里是代码的前后,它解决了问题:
<强>之前:强>
def get_welcome_response():
"""
called by on_launch function
"""
session_attributes = {}
card_title = "Welcome"
speech_output = "some text"
reprompt_text = "some text"
should_end_session = False
return build_response(session_attributes, build_speechlet_response(
card_title, speech_output, reprompt_text, should_end_session))
def predict(intent, session):
"""
called by on_intent function
"""
session_attributes = session['attributes'] # was throwing KeyError
here, but not throwing while test
if 'value' in intent['slots']['petalLength'].keys():
session_attributes['petalLength'] = intent['slots']['petalLength']['value']
session['attributes'] = session_attributes
return ellicit_petal_width(intent, session)
elif 'value' in intent['slots']['petalWidth'].keys():
session_attributes['petalWidth'] = intent['slots']['petalWidth']['value']
session['attributes'] = session_attributes
return ellicit_sepal_length(intent, session)
elif 'value' in intent['slots']['sepalLength'].keys():
session_attributes['sepalLength'] = intent['slots']['sepalLength']['value']
session['attributes'] = session_attributes
return ellicit_sepal_width(intent, session)
elif 'value' in intent['slots']['sepalWidth'].keys():
session_attributes['sepalWidth'] = intent['slots']['sepalWidth']['value']
session['attributes'] = session_attributes
return get_prediction(intent, session)
<强>后:强>
def get_welcome_response():
"""
called by on_launch function
"""
session_attributes = {}
card_title = "Welcome"
speech_output = "some text"
reprompt_text = "some text"
should_end_session = False
return build_response(session_attributes, build_speechlet_response(
card_title, speech_output, reprompt_text, should_end_session))
def predict(intent, session):
"""
called by on_intent function
"""
#added the following and solved the problem
if 'attributes' not in session.keys():
session['attributes'] = {}
session_attributes = session['attributes']
else:
session_attributes = session['attributes']
if 'value' in intent['slots']['petalLength'].keys():
session_attributes['petalLength'] = intent['slots']['petalLength']['value']
session['attributes'] = session_attributes
return ellicit_petal_width(intent, session)
elif 'value' in intent['slots']['petalWidth'].keys():
session_attributes['petalWidth'] = intent['slots']['petalWidth']['value']
session['attributes'] = session_attributes
return ellicit_sepal_length(intent, session)
elif 'value' in intent['slots']['sepalLength'].keys():
session_attributes['sepalLength'] = intent['slots']['sepalLength']['value']
session['attributes'] = session_attributes
return ellicit_sepal_width(intent, session)
elif 'value' in intent['slots']['sepalWidth'].keys():
session_attributes['sepalWidth'] = intent['slots']['sepalWidth']['value']
session['attributes'] = session_attributes
return get_prediction(intent, session)
我的结论: 看起来会话对象在设备中运行技能时没有名为“属性”的键。但是,它在测试中运行时确实有“属性”键。