简体   繁体   English

创建具有某些特定条件的 RASA Chatbot

[英]Creating RASA Chatbot with some specific conditions

I want to create a chatbot where,我想创建一个聊天机器人,

I have a branch of questions and answers like,我有一个问题和答案的分支,比如,

Q1. How are you
A1. - Fine.
    - Good.
Q2. Do you like travelling?
A2  - Yes
    - Absolutely
    - I like it.
Q3. Did you ever use RASA chatbot?
A3  - Yes
    - Almost 2 years.

now,现在,

  1. If I ask questions to the chatbot but miss some questions like forget to ask Q2, the chatbot will say that end of the conversion that I miss that questions,如果我向聊天机器人提问但遗漏了一些问题,比如忘记问 Q2,聊天机器人会在转换结束时说我遗漏了那些问题,

  2. After the chatbot say I miss some questions have to go throw all the questions from start again but,在聊天机器人说我遗漏了一些问题后,必须将所有问题从 go 重新开始,但是,

  3. When I ask those questions again the chatbot will give different answers than it gives 1st time.当我再次问这些问题时,聊天机器人会给出与第一次不同的答案。

    Example: 1st time when I ask Q1 and Q3 it gives answers -Fine and -Yes but when 2nd time I go throw the process for Q1 and Q3 it has to give different answers than -Fine and -Yes .示例:第一次当我问 Q1 和 Q3 时,它给出答案-Fine-Yes但是当我第二次 go 抛出 Q1 和 Q3 的过程时,它必须给出与-Fine-Yes不同的答案。

Now my questions are,现在我的问题是,

  1. Is it possible to make a chatbot with RASA where it will follow the three conditions up there?是否有可能用 RASA 制作一个聊天机器人,它将遵循上面的三个条件?
  2. If not then is any sort of alternative?如果没有,那么有什么选择吗?

yes, all three conditions are possible.是的,所有三个条件都是可能的。 Please correct me as I understood your question, I am adding follow solution as per the below understanding:请纠正我,因为我理解你的问题,我根据以下理解添加以下解决方案:
You want your assistant to ask How are you?你想让你的助手问How are you? and end-user answers Fine/Good , and so as Q2 and Q3 do.最终用户回答Fine/Good ,Q2 和 Q3 也是如此。

Solution解决方案
For this to work, you have to use forms in Rasa.为此,您必须在 Rasa 中使用 forms。 Below is a simple example for using this functionality.下面是一个使用此功能的简单示例。

  1. Make sure you have form for these questions and slots added.(facing issue, following this tutorial )确保您已添加这些问题和插槽的表格。(面临问题,遵循本教程
  2. Go to your actions.py Go 到你的 actions.py
  3. Add validations for each slot you have.为您拥有的每个插槽添加验证。 Here, you will find just one example here as an example.在这里,你会发现这里只有一个例子作为例子。
import os
from pathlib import Path
from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker, FormValidationAction
from rasa_sdk.executor import CollectingDispatcher

from utils.utils import get_html_data, send_email


class ValidateContactUsForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_contact_us_form"

    def validate_name(
        self,
        value: Text,
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: "DomainDict",
    ) -> Dict[str, str]:
        if value in ["Fine", "Good"]:
            return {"name": value}
        else:
            # return {"name": None, "requested_slot": "name"}
            return {"requested_slot": "name"} # to request the same slot again, 
            # assistant will ask same question again.

Note : return {"name": None, "requested_slot": "name"} This will close the form and restart the whole form, in this case, the form has just one slot, if you have more slots you have to nullify them too.注意return {"name": None, "requested_slot": "name"}这将关闭表单并重新启动整个表单,在这种情况下,表单只有一个插槽,如果您有更多插槽,则必须取消它们也。

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

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