RASA表单“非类型”对象不可编辑

2024-04-27 17:02:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个bot来帮助用户根据提供的名称搜索文件,我正在使用一个插槽来存储名为“SEARCHCONTENT”的文件名的内存,我正在使用“search”实体来帮助bot识别搜索词的不同同义词。以下是我要搜索文件的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)

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

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

当我运行bot并输入“搜索文件帐户摘要”时,它会给我以下错误:
enter image description here


Tags: 文件thetextfromimportformforsearch