【问题标题】:How to add Dynamic Entities in Alexa with Python?如何使用 Python 在 Alexa 中添加动态实体?
【发布时间】:2020-05-23 17:53:48
【问题描述】:

我正在用 Python 开发 Alexa 技能,我需要为用户动态添加实体以更新插槽类型,以便用户可以选择一个选项。

我的页面 Use Dynamic Entities for Customized Interactions 有 Node.js 和 Java 的文档和示例,但没有 Python 的示例。查看 Python SDK 的 Documentation,我不清楚如何在 Python 中做同样的事情。

我创建了一个名为 test 的 Slot Type 并尝试了以下代码:

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 中添加动态实体的正确方法是什么?

【问题讨论】:

    标签: python amazon-web-services alexa alexa-skills-kit


    【解决方案1】:

    我在链接中找到了答案:https://forums.developer.amazon.com/questions/210684/dynamic-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)
    

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-31
      • 2013-08-22
      相关资源
      最近更新 更多