【问题标题】:Next rule action not getting triggered when returning SlotSet in custom action in Rasa 2在 Rasa 2 的自定义操作中返回 SlotSet 时未触发下一个规则操作
【发布时间】:2021-11-25 06:43:05
【问题描述】:

我有以下规则:

- rule: submit form
  condition:
  - active_loop: user_offer_form
  steps:
  - action: user_offer_form
  - active_loop: null
  - slot_was_set:
    - requested_slot: null
  - action: action_get_offer
  - action: utter_ask_deal

这是自定义操作:

class ActionGetOffer(Action):
def name(self) -> Text:
    return "action_get_offer"

def run(self,dispatcher,tracker: Tracker,domain: "DomainDict",) -> List[Dict[Text, Any]]:

    dispatcher.utter_message(text = "Ok! Let me see what I can do!")


    product_price = 500
    platform_bargain_percentage = 5
    vendor_bargain_percentage = 5
    max_bargain = platform_bargain_percentage + vendor_bargain_percentage

    offer_price = int(tracker.get_slot("price"))
    print(offer_price)

    user_asked_percentage = (offer_price / product_price) * 100

    current_bargain = tracker.get_slot('current_bargain') + 2
    print(current_bargain)



    if user_asked_percentage > current_bargain:

    
        dispatcher.utter_message(text = "Okay so I just checked and sorry but we can't give away for that price!")

        if tracker.get_slot('current_bargain_price') == 0:
            current_bargain_price = (product_price - (((current_bargain)/100) * product_price))
        else:
            current_bargain_price = tracker.get_slot('current_bargain_price')

        if current_bargain <= max_bargain:
            dispatcher.utter_message(text = f"How about {str( product_price - (((current_bargain)/100) * product_price))}?")
        else:
            dispatcher.utter_message(text = "Hmm...wanna make a fresh offer then?")


        # dispatcher.utter_message(response = 'utter_ask_deal')
        return[SlotSet("current_bargain", value = float(current_bargain))]

这里是 utter_ask_deal:

  utter_ask_deal:
    - text: "Ok with this deal?"
      buttons:
      - title: "Yup"
        payload: '/inform_intent{{"deal":"true"}}'
      - title: "Nope"
        payload: '/inform_intent{{"deal":"false"}}'

规则一直执行到action_get_offer,但utter_ask_deal 没有得到执行,槽‘current_bargain’ 也没有得到更新。

有趣的是,当我不在 return 语句中使用 SlotSet 而是直接在代码中使用它时,正在执行下一个操作,但在这两种情况下都不会更新 slot。

有人可以帮忙吗?

【问题讨论】:

  • 嘿,您是否看到在您的操作服务器日志中执行操作action_get_offer(您能否分享相关的日志输出——最好是在调试模式下)。
  • 嗨@tttthomasssss!这是服务器日志输出。动作 action_get_offer 正在执行。 2021-11-25 13:52:25 DEBUG rasa_sdk.executor - Received request to run 'action_get_offer' 250 2 2021-11-25 13:52:25 DEBUG rasa_sdk.executor - Finished running 'action_get_offer' 但是下一个动作 utter_ask_deal 并没有执行。
  • 您是否在 rasa 服务器日志中看到它被预测(最好是 RulePolicy)?
  • @tttthomasssss 没有。这是日志2021-11-25 13:52:25 DEBUG rasa.core.processor - Predicted next action 'action_listen' with confidence 1.00. 2021-11-25 13:52:25 DEBUG rasa.core.processor - Policy prediction ended with events '[]'. 2021-11-25 13:52:25 DEBUG rasa.core.processor - Action 'action_listen' ended with events '[]'. 2021-11-25 13:52:25 DEBUG rasa.core.lock_store - Deleted lock for conversation '5839dd9c04734d25bf67dacb364a2978'.
  • 我认为您应该在设置新值之前重置“current_bargain”值,因为 action_loop 检测到“current_bargain”插槽不为空。检查此链接:forum.rasa.com/t/how-to-replace-update-slots-value/49392

标签: chatbot rasa rasa-nlu rasa-core


【解决方案1】:

机器人话语utter_ask_dealbuttons 标记周围有缩进问题,请尝试将其更改为:

utter_ask_deal:
- text: "Ok with this deal?"
  buttons:
  - title: "Yup"
    payload: '/inform_intent{{"deal":"true"}}'
  - title: "Nope"
    payload: '/inform_intent{{"deal":"false"}}'

更多信息可以从这里收集:https://rasa.com/docs/rasa/responses/#buttons

【讨论】:

  • 感谢您指出这一点。但是,在将代码复制粘贴到堆栈溢出时,这只是一个格式错误,并且代码文件中的缩进非常好。我更正了原始问题中的错误。
  • 不用担心。不客气:)
猜你喜欢
  • 1970-01-01
  • 2015-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-17
  • 2018-10-14
  • 2015-04-15
相关资源
最近更新 更多