【问题标题】:Get the user's value of an intent in RASA Core/NLU在 RASA Core/NLU 中获取用户的意图值
【发布时间】:2019-09-09 10:34:57
【问题描述】:

我有同样的问题:Get Intent Value in RASA Core/NLU 但我想要用户为给定意图提供的值。

例如:

User: I want to take it (this sentence is an intent called: 'use_it')
Bot: ....
User: .... (Later in the chat I decide to answer with the same phrase of intent 'use it') 
Bot: you said previously "I want to take it"

我怎么能做这样的事情:tracker.get_slot 但出于意图?

我不想要最后一个意图的名称,我想要用户给定意图的文本。

【问题讨论】:

    标签: rasa-nlu rasa-core


    【解决方案1】:

    在您将意图文本存储在插槽中的意图之后执行custom action

    from rasa_core_sdk import Action
    from rasa_core_sdk.events import SlotSet
    
    class ActionStoreIntentMessage(Action):
        """Stores the bot use case in a slot"""
    
        def name(self):
            return "action_store_intent_message"
    
        def run(self, dispatcher, tracker, domain):
    
            # we grab the whole user utterance here as there are no real entities
            # in the use case
            message = tracker.latest_message.get('text')
    
            return [SlotSet('intent_message', message)]
    

    然后您可以在utter template 中使用设置槽的值:

    slots:
      intent_message:
        type: text
    
    templates:
      utter_last_intent:
        - "you said previously: {intent_message}"
    

    【讨论】:

    • 执行此操作时出现此错误:AttributeError: 'UserUttered' object has no attribute 'get' 将在消息中提供更多详细信息
    • 我已将 tracker.latest_message.get('text') 更改为 tracker.latest_message.text,现在我得到:NameError: name 'SlotSet' is not defined
    • 解决了最后一个()我只是忘了导入SoltSet。我的最后一个问题是机器人识别“intent_message”插槽,但是当我在模板中使用它时它没有显示。它显示:您之前说过:{intent_message} 有什么帮助吗?
    • 我的工作是在保存新插槽后添加另一个服装动作。在第二个 costum 动作中,我做了类似的事情:' message = tracker.get_slot('intent_message') response = """你之前说过:{} """.format(loc) dispatcher.utter_message(response)'跨度>
    • 我在示例中添加了导入和插槽定义。现在应该这样工作。
    【解决方案2】:

    您可以使用跟踪器来完成任务。

    text=tracker.latest_message['text']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 2018-01-06
      相关资源
      最近更新 更多