0

我正在创建一个机器人来帮助用户根据提供的名称搜索文件,并且我正在使用一个插槽来存储名为“SEARCHCONTENT”的文件名的内存,并且我正在使用“SEARCH”实体来帮助机器人识别搜索词的不同同义词。这是我用于搜索文件的 nlu 数据:

## intent:searchSynonyms
 - [search](SEARCH)
 - [look for](SEARCH)
 - [find](SEARCH)
 - [where is](SEARCH)

## intent:file
- file
- file [bills](SEARCHCONTENT)
- [search](SEARCH) file
- [search](SEARCH) file [mouse](SEARCHCONTENT)
- [search](SEARCH) for a file
- [search](SEARCH) for a file [laptops](SEARCHCONTENT)
- [searching](SEARCH) file
- [searching](SEARCH) file [accounting](SEARCHCONTENT)
- [where is](SEARCH) the file
- [where is](SEARCH) the file [order summary](SEARCHCONTENT) located
- [look for](SEARCH) the file
- [look for](SEARCH) the file [degree planner](SEARCHCONTENT)
- [find](SEARCH) file
- [find](SEARCH) file [design report](SEARCHCONTENT)

在域文件中,我指定了将“文本”作为输入的插槽名称:

slots:
  SEARCHCONTENT:
    type: text
    auto_fill: false

然后我继续创建我的表单:

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet
from rasa_sdk.forms import FormAction
class FormActionFileSearch(FormAction):
    """Custom form action to find file"""

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

    @staticmethod
    def required_slots(tracker: "Tracker") -> List[Text]:
        return ["SEARCHCONTENT"]

    def slot_mappings(self) -> Dict[Text, Any]:
        return {"SEARCHCONTENT": self.from_entity(entity="SEARCHCONTENT", intent=["file"])}

    def submit(
        self,
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: Dict[Text, Any],
    ) -> List[Dict]:
        search_content = tracker.get_slot("SEARCHCONTENT")
        dispatcher.utter_message("Searching file " + search_content)

现在,我要做的就是打印文件名以检查它是否正确地从插槽中提取值。
然后我继续到 domain.yml 文件添加表单操作名称:

forms:
  - form_action_file_search

然后我继续在我的 config.yml 文件中添加表单策略:

policies:
 - name: FormPolicy

然后我继续为文件名搜索创建故事:

## file path affirm
* file{"SEARCHCONTENT":"car budget"}
- form_action_file_search
- form{"name": "form_action_file_search"}
- form{"name": null}
- utter_assistance
* affirm
- utter_askAssistance

然后我将所有意图和操作添加到 domain.yml 文件中,这就是它的外观:

intents:
- file
- affirm
entities:
- SEARCH
- SEARCHCONTENT
slots:
  SEARCHCONTENT:
    type: text
    auto_fill: false
forms:
  - form_action_file_search
responses:
  utter_assistance:
  - text: Is there anything else you need?
  utter_askAssistance:
  - text: How can I help you?
actions:
- utter_assistance
- utter_askAssistance

当我运行机器人并输入“搜索文件帐户摘要”作为输入时,它给了我以下错误:
在此处输入图像描述

4

1 回答 1

0

您可以尝试将您的插槽类型更改为非功能化。

slots:
  SEARCHCONTENT:
    type: unfeaturized
    auto_fill: false
于 2020-09-27T17:50:41.087 回答