我正在用Python开发一个Alexa技能,我需要为用户动态添加实体来更新槽类型,以便用户可以选择一个选项。
我的页面 使用动态实体进行自定义交互 有Node.js和Java的文档和例子,但没有Python的例子。看了一下 文件资料 的Python SDK,但我不清楚如何在Python中做同样的事情。
我创建了一个名为 检验 并尝试了以下代码。
test_directive = {"object_type": "Dialog.UpdateDynamicEntities", "update_behavior": "REPLACE", "types": [{"name": "test", "values": [{"id": "round-rock", "name": {"value": "Round Rock Express", "synonyms": ["Round Rock", "Express"]}}, {"id": "corpus-christi", "name": {"value": "Corpus Christi Hooks", "synonyms": ["Corpus Christi", "Hooks", "Corpus"]}}]}]}
response_builder.add_directive(test_directive)
但我得到了错误信息
'dict' object has no attribute 'object_type'
在Python中添加动态实体的正确方法是什么?
我在链接中找到了答案。https:/forums.developer.amazon.comquestions210684dynamic-entities-in-python.html。. 在Python中的一个小例子。
entity_synonyms_1 = EntityValueAndSynonyms(value="entity 1", synonyms=["synonym 1", "synonym 2"])
entity_1 = Entity(id="entity_id_1", name=entity_synonyms_1)
entity_synonyms_2 = EntityValueAndSynonyms(value="entity 2", synonyms=["synonym 3", "synonym 4"])
entity_2 = Entity(id="entity_id_2", name=entity_synonyms_2)
replace_entity_directive = DynamicEntitiesDirective(update_behavior=UpdateBehavior.REPLACE, types=[EntityListItem(name="custom_type", values=[entity_1, entity_2])])
response_builder.add_directive(replace_entity_directive)