简体   繁体   English

来自自定义操作的 rasa 填充槽

[英]rasa fill slots from custom action

I'm trying to build a bot with rasa.我正在尝试用 rasa 构建一个机器人。 At the very beginning of the conversation it should fill some slots with data from the database.在对话的最开始,它应该用数据库中的数据填充一些槽。

I have a custom action:我有一个自定义操作:

class ActionFillSlots(Action):

def name(self) -> Text:
    return "action_fill_slots"

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

    example = "example"
    return [SlotSet("example", example)]

And in my domain.yml file i have set the slot like this:在我的 domain.yml 文件中,我设置了这样的插槽:

slots:
  example:
  type: text

And a response like:和这样的回应:

 utter_greet:
 - text: "Show { example }"

And in my stories.yml file, i have stories like:在我的 stories.yml 文件中,我有这样的故事:

- story: greet happy path
  steps:
  - intent: greet
  - action: action_fill_slots
  - action: utter_greet

If I run the bot with rasa shell --debug and then type something that matches the greeting intent, i get the following error:如果我使用rasa shell --debug运行机器人,然后输入与问候意图匹配的内容,我会收到以下错误:

Failed to fill utterance template 'Show { example }' Tried to replace ' example ' but could not find a valu e for it.未能填充话语模板“显示{示例}”试图替换“示例”但找不到它的值。 There is no slot with this name nor did you pass the value explicitly when calling the template.没有具有此名称的插槽,也没有在调用模板时显式传递值。 Return template without filling the template.返回模板而不填写模板。

In my debug window I can see, that the slot has been set by the action:在我的调试窗口中,我可以看到,插槽已由操作设置:

Current slot values: example: example当前槽值:示例:示例

I'm using rasa 2.1.0我正在使用 rasa 2.1.0

Does this help?这有帮助吗? let me know让我知道

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher

class ActionFillSlots(Action):

def name(self) -> Text:
    return "action_fill_slots"

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

    example = tracker.get_slot(example)
    dispatcher.utter_message(text = str(example))

    return []

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM