{"id":24080,"date":"2021-06-14T00:25:00","date_gmt":"2021-06-14T07:25:00","guid":{"rendered":"https:\/\/www.springboard.com\/blog\/?p=24080"},"modified":"2023-06-25T20:57:48","modified_gmt":"2023-06-26T03:57:48","slug":"rasa-chatbot","status":"publish","type":"post","link":"https:\/\/www.springboard.com\/blog\/data-science\/rasa-chatbot\/","title":{"rendered":"How to Build a Secure AI Chatbot Using RASA &#038; Python"},"content":{"rendered":"\n<p>In this series 2 of the blog post on how to build a secure AI Chatbot using RASA and Python, we will learn how to level up from Basic NLU to Dialogue Management &amp; Custom Actions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Build a Secure AI Chatbot: What Did we Do in Part 1?<\/h2>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.youtube.com\/watch?v=Nk9K4s8g9yQ&#038;t=3421s\n<\/div><\/figure>\n\n\n\n<p>If you haven\u2019t read part 1 of this blog, you can read it here in the blog: <a aria-label=\"chatbot using RASA (opens in a new tab)\" href=\"https:\/\/in.springboard.com\/blog\/chatbot-using-rasa\/\" target=\"_blank\" rel=\"noreferrer noopener\">chatbot using RASA<\/a>.&nbsp; In the first part, we discussed in detail the RASA framework. Using the RASA NLU component of the framework we started coding <a href=\"https:\/\/www.springboard.com\/blog\/data-science\/rasa-chatbot\/\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/www.springboard.com\/blog\/data-science\/rasa-chatbot\/\" rel=\"noreferrer noopener\">\u201cTrippy: The Travel Agency Chatbot\u201d<\/a>. For Trippy, we created the training data and trained the model to identify the intent in the user query. So far, Trippy is able to identify when to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Greet the customer.<\/li>\n\n\n\n<li>Give information regarding flights or trains from one source to another destination.<\/li>\n\n\n\n<li>Show upcoming itineraries for a customer.<\/li>\n<\/ol>\n\n\n\n<p>So basically the Chatbot can do natural language processing(NLP) on the incoming query and identify the intent.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Objective of Part 2?<\/h2>\n\n\n\n<p>In this part, we will use RASA Core components which form the dialogue engine to make an AI chatbot converse with the customer. So far, we have created three files in the \u201c<strong>trippy<\/strong>\u201d base directory:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>trippy\/data\/<strong>nlu.md<\/strong>:  The nlu.md file holds the training data.<\/li>\n\n\n\n<li>trippy\/<strong>config.yml<\/strong>: The config.yml file holds the configuration of the pipelines.<\/li>\n\n\n\n<li>trippy\/<strong>rasa_train.py<\/strong>: This file has the code to train the model and parse a sample text to extract the intent of the query.<\/li>\n<\/ol>\n\n\n\n<p>In this blog, we will learn how to use the concept of Stories, Domain and Custom Actions to code the desired capability. So, let\u2019s begin.<\/p>\n\n\n<div class=\"bg-leaf-50 p-4 my-3\"><h4 class=\"fw-bold text-center\">Get To Know Other\tData Science Students<\/h4><div class=\"row row-cols-1 row-cols-lg-3\"><div class=\"col\"><div class=\"card success-story-card h-100 d-flex justify-content-between mb-0\"><div class=\"flex-grow-1 text-center\"><a class=\"d-inline-block rounded-circle\" href=\"\/success\/pizon-shetu\" style=\"width:125px;height:125px;overflow:hidden\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/res.cloudinary.com\/springboard-images\/image\/upload\/v1651030560\/Student%20Success\/Pizon_Shetu.jpg\" alt=\"Pizon Shetu\" style=\"object-fit:contain;max-width:170px;height:125px\" \/><\/a><p class=\"fw-bold mb-0\">Pizon Shetu<\/p><p class=\"text-muted lh-1\">Data Scientist at Whiterock AI<\/p><\/div><div class=\"w-100 d-block d-md-none mt-3\"><\/div><p class=\"mb-0 mx-auto text-center\"><a class=\"btn btn-primary mx-auto\" href=\"\/success\/pizon-shetu\">Read Story<\/a><\/p><\/div><\/div><div class=\"col d-none d-md-block\"><div class=\"card success-story-card h-100 d-flex justify-content-between mb-0\"><div class=\"flex-grow-1 text-center\"><a class=\"d-inline-block rounded-circle\" href=\"\/success\/corey-wade\" style=\"width:125px;height:125px;overflow:hidden\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/res.cloudinary.com\/springboard-images\/image\/upload\/v1680712086\/Corey_Wade_LinkedIn.jpg\" alt=\"Corey Wade\" style=\"object-fit:contain;max-width:170px;height:125px\" \/><\/a><p class=\"fw-bold mb-0\">Corey Wade<\/p><p class=\"text-muted lh-1\">Founder And Director at Berkeley Coding Academy<\/p><\/div><p class=\"mb-0 mx-auto text-center\"><a class=\"btn btn-primary mx-auto\" href=\"\/success\/corey-wade\">Read Story<\/a><\/p><\/div><\/div><div class=\"col d-none d-md-block\"><div class=\"card success-story-card h-100 d-flex justify-content-between mb-0\"><div class=\"flex-grow-1 text-center\"><a class=\"d-inline-block rounded-circle\" href=\"\/success\/nick-lenczewski\" style=\"width:125px;height:125px;overflow:hidden\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/res.cloudinary.com\/springboard-images\/image\/upload\/v1667235351\/Student%20Success\/Nick_Lenczewski.jpg\" alt=\"Nick Lenczewski\" style=\"object-fit:contain;max-width:170px;height:125px\" \/><\/a><p class=\"fw-bold mb-0\">Nick Lenczewski<\/p><p class=\"text-muted lh-1\">Data Scientist at Ovative Group<\/p><\/div><p class=\"mb-0 mx-auto text-center\"><a class=\"btn btn-primary mx-auto\" href=\"\/success\/nick-lenczewski\">Read Story<\/a><\/p><\/div><\/div><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Dialogue Management: Teaching the AI Chatbot How to Respond<\/h2>\n\n\n\n<p>The dialogue management aspect is handled by the \u201c<strong>Core<\/strong>\u201d model of the RASA framework. A core model learns from data in the form of \u201c<strong>stories<\/strong>\u201d. You can learn more about Stories <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/rasa.com\/docs\/rasa\/core\/stories\/\" target=\"_blank\">here<\/a>. In short, a story is a formatted representation of a conversation between a user and the chatbot. An example of a story from the official <a href=\"https:\/\/rasa.com\/docs\/rasa\/core\/stories\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">documentation<\/a> is as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"353\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-1200x353.png\" alt=\"rasa chatbot\" class=\"wp-image-46193\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-1200x353.png 1200w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-400x118.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-768x226.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-1536x452.png 1536w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-380x112.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-700x206.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot.png 1600w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-380x112.png 420w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><figcaption class=\"wp-element-caption\">Source: <a href=\"https:\/\/rasa.com\/\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/rasa.com\/\" rel=\"noreferrer noopener\">RASA<\/a><\/figcaption><\/figure>\n\n\n\n<p>Let\u2019s understand the format of a story.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Every story starts with a name denoted by ## followed by a name. You can name a story anything. It is just like naming a variable.<\/li>\n\n\n\n<li>An * denotes messages sent by the user in the entity: value pair format.<\/li>\n\n\n\n<li>A <strong>\u2013 <\/strong>denotes the name of the action taken by the bot.<\/li>\n\n\n\n<li>In case an action returns an \u201cevent\u201d then it should be specified immediately on the next line following the action.<\/li>\n<\/ul>\n\n\n\n<p>Before we go ahead and create stories for Trippy, let&#8217;s also understand the concept of <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/rasa.com\/docs\/rasa\/core\/domains\/\" target=\"_blank\" rel=\"noreferrer noopener\">Domains<\/a> and <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/rasa.com\/docs\/rasa\/core\/actions\/\" target=\"_blank\" rel=\"noreferrer noopener\">Actions<\/a>.<\/p>\n\n\n\n<p>A <strong>DOMAIN <\/strong>is a universe in which the AI chatbot functions. It includes all the intents, entities, slots, actions and optionally responses that the bot should be aware of. We covered intents and entities in detail in part 1. Let\u2019s understand the other three.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SLOT \u2013 <\/strong>Placeholder for information that needs to be tracked during a conversation. Example of a \u201ccategorical\u201d slot from the documentation:<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"268\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3-1200x268.png\" alt=\"rasa chatbot, ai chatbot using rasa 3\" class=\"wp-image-46194\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3-1200x268.png 1200w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3-400x89.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3-768x172.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3-1536x343.png 1536w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3-380x85.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3-700x157.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3.png 1592w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-3-380x85.png 420w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><figcaption class=\"wp-element-caption\">Source: <a href=\"https:\/\/rasa.com\/\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/rasa.com\/\" rel=\"noreferrer noopener\">RASA<\/a><\/figcaption><\/figure>\n\n\n\n<p>You can read more about other types of slots <a href=\"https:\/\/rasa.com\/docs\/rasa\/core\/slots\/#slot-classes\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ACTIONS \u2013 <\/strong>These are things that the bot is expected to do or say in response to the user\u2019s query. There are four kinds of actions that the RASA framework supports:<\/li>\n<\/ul>\n\n\n\n<p><strong>Utterance actions: <\/strong>start with&nbsp;utter_&nbsp;and send a specific message to the user.<\/p>\n\n\n\n<p><strong>Retrieval actions: <\/strong>start with&nbsp;respond_&nbsp;and send a message selected by a retrieval model.<\/p>\n\n\n\n<p><strong>Custom actions: <\/strong>run arbitrary code and send any number of messages (or none).<\/p>\n\n\n\n<p><strong>Default actions: <\/strong>e.g.&nbsp;action_listen,&nbsp;action_restart,&nbsp;action_default_fallback.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>RESPONSES \u2013 <\/strong>These are simply the messages that the bot sends back to the user. These can be directly stored as strings in the domain file or can be generated as action responses or by creating a custom Natural Language Generation service. You can read more about responses <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/rasa.com\/docs\/rasa\/core\/responses\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/li>\n<\/ul>\n\n\n\n<p>Now that we have an understanding of Stories and Domain, let&#8217;s create the stories and domain files for Trippy. If you recollect from Part 1, Trippy is coded to handle the following intents:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>greet<\/li>\n\n\n\n<li>thanks<\/li>\n\n\n\n<li>bye<\/li>\n\n\n\n<li>search_flights<\/li>\n\n\n\n<li>search_trains<\/li>\n\n\n\n<li>find_itineraries<\/li>\n<\/ol>\n\n\n\n<p>First, we will create the stories.md file. Here is a snippet of the stories.md file. You can request access to the complete file by sending us a request &lt;form_link&gt;.<br><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"1296\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4-1200x1296.png\" alt=\"rasa chatbot, ai chatbot using rasa 4\" class=\"wp-image-46195\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4-1200x1296.png 1200w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4-400x432.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4-768x829.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4-1422x1536.png 1422w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4-380x410.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4-700x756.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4.png 1450w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-4-380x410.png 420w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><figcaption class=\"wp-element-caption\"><em>Snippet of stories.md file<\/em><\/figcaption><\/figure>\n\n\n\n<p>Now, let\u2019s create the domain.yml file. This file should contain all the intents, entities, actions and responses. The domain.yml file is as shown below:<br><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1058\" height=\"1254\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-5.png\" alt=\"rasa chatbot, ai chatbot using rasa 5\" class=\"wp-image-46196\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-5.png 1058w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-5-400x474.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-5-768x910.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-5-380x450.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-5-700x830.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-5-380x450.png 420w\" sizes=\"(max-width: 1058px) 100vw, 1058px\" \/><figcaption class=\"wp-element-caption\"><em>Snippet of stories.md file<\/em><\/figcaption><\/figure>\n\n\n\n<p>If you look at the responses section of the domain.yml file, you can see that it defines the responses for utter_ actions. There are other actions which are named action_ which are not defined here. Since these actions are not expected to return static text and in real-world, these should execute some query\/search etc. these are examples of Custom Actions. You can read more about how to configure custom actions here. We will use the python code to define our custom actions. For this, we will create a file \u201cactions.py\u201d. In this file, we define and map a class for each of the custom actions mentioned in the domain.yml file.<\/p>\n\n\n\n<p>In a real-world scenario, the AI chatbot needs to compute, retrieve, process information gained from intent and entity extraction. This file actions.py is where you can do all of that.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"722\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6-1200x722.png\" alt=\"rasa chatbot, ai chatbot using rasa 6\" class=\"wp-image-46197\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6-1200x722.png 1200w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6-400x241.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6-768x462.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6-1536x924.png 1536w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6-380x228.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6-700x421.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6.png 1600w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-6-380x228.png 420w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><figcaption class=\"wp-element-caption\"><em>Snippet of actions.py file<\/em><\/figcaption><\/figure>\n\n\n\n<p>There are some additional steps required to be performed to make these custom actions available for the AI chatbot. We need to define the endpoint url in the file endpoints.yml. Don\u2019t create this file right now, it will get created automatically (as we perform some steps later).<\/p>\n\n\n\n<p>You may have noticed that we also defined an action <strong>utter_unclear<\/strong> in stories.md and domain.yml file. This action will be taken when the chatbot is not quite confident about the intent\/entity predictions. To leverage this, we need to set and define some policies in the config.yml file. The file snippet is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"894\" height=\"634\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-7.png\" alt=\"rasa chatbot, ai chatbot using rasa 7\" class=\"wp-image-46198\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-7.png 894w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-7-400x284.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-7-768x545.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-7-380x269.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-7-700x496.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-ai-chatbot-using-rasa-7-380x269.png 420w\" sizes=\"(max-width: 894px) 100vw, 894px\" \/><figcaption class=\"wp-element-caption\"><em>File: config.yml<\/em><\/figcaption><\/figure>\n\n\n\n<p>Now that we are using more framework components, it will be better to use less python code and more framework function to tie all these configurations and data together. So we will do things a little differently from part 1. It is recommended that you create a new directory for this.<\/p>\n\n\n\n<p>Pre-requisites:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install rasa<\/li>\n\n\n\n<li>Install spacy<\/li>\n\n\n\n<li>Install rasa-sdk<\/li>\n<\/ol>\n\n\n\n<p>Steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a new directory and switch<br>&gt;&gt; mkdir trippy_2<br>&gt;&gt; cd trippy_2<\/li>\n\n\n\n<li>Create a new Rasa project<br>&gt;&gt; rasa init &#8211;no-prompt<br>This will automatically create all the files that the project needs (with some data for the default demo project).<\/li>\n\n\n\n<li>Copy the data from the trippy\/data\/nlu.md to trippy_2\/data\/nlu.md file.<\/li>\n\n\n\n<li>Copy the data from the stories.md file to trippy_2\/data\/stories.md file.<\/li>\n\n\n\n<li>Copy the data from the domain.yml file to trippy_2\/domain.yml file.<\/li>\n\n\n\n<li>Copy the code from actions.py to trippy_2\/actions.py<\/li>\n\n\n\n<li>Copy the configuration from config.yml to trippy_2\/config.yml file.<\/li>\n\n\n\n<li>Edit the trippy_2\/ endpoints.yml file. Uncomment the following lines:<br>action_endpoint:<br>url: &#8220;http:\/\/localhost:5055\/webhook&#8221;&nbsp;In a different shell, start the action sever:<\/li>\n\n\n\n<li>In a different shell, start the action sever:<br>&gt;&gt; cd tripp_2<br>&gt;&gt; rasa run actions<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"167\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions-1200x167.png\" alt=\"rasa chatbot, rasa run actions\" class=\"wp-image-46199\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions-1200x167.png 1200w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions-400x56.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions-768x107.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions-1536x213.png 1536w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions-380x53.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions-700x97.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions.png 1600w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-run-actions-380x53.png 420w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>    10. Start the training:<br>     &gt;&gt; rasa train<br>    11.Start the shell to engage with the model:<br>     &gt;&gt; rasa shell &#8211;endpoints endpoints.yml<\/p>\n\n\n\n<p class=\"has-text-align-center has-text-color\" style=\"color:#201dcb\"><em><strong>Inspired by this analysis and want to learn how to do it \/ wish to replicate this for your project? We can help you there. Just leave your email address in this <a href=\"https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLSd2dmlshHPTgA0wosbMSIq1SxsOo5yliZPhLTKSJWqBknvhZQ\/viewform\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">google form<\/a> and we will share the analysis with you within 48 hours.<\/strong><\/em><\/p>\n\n\n\n<p>An image of interaction with Trippy is as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"1034\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1-1200x1034.png\" alt=\"rasa chatbot, rasa python 1\" class=\"wp-image-46202\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1-1200x1034.png 1200w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1-400x345.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1-768x662.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1-1536x1324.png 1536w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1-380x328.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1-700x603.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1.png 1564w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1-380x328.png 420w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><figcaption class=\"wp-element-caption\"><em>Interaction with Trippy using Shell<\/em><\/figcaption><\/figure>\n\n\n\n<p>Additionally, you can also see that the custom actions are also able to receive the entities and intents extracted from the code.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"213\" src=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1200x213.png\" alt=\"rasa chatbot, rasa python\" class=\"wp-image-46200\" srcset=\"https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1200x213.png 1200w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-400x71.png 400w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-768x136.png 768w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-1536x273.png 1536w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-380x67.png 380w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-700x124.png 700w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python.png 1600w, https:\/\/www.springboard.com\/blog\/wp-content\/uploads\/2021\/06\/rasa-chatbot-rasa-python-380x67.png 420w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><figcaption class=\"wp-element-caption\"><em>Entities and Intents extracted from Query in the Custom Action Code<\/em><\/figcaption><\/figure>\n\n\n\n<p>You can see that Trippy is much more evolved now and is able to handle a sequence of flows in an expected manner. These capabilities are achieved using framework components without having to write a lot of code with complex IF-ELSE like statements that are good from maintainability and scalability aspects.&nbsp;In a real-world scenario, one rarely exposes chatbots through command-line. Trippy as of now interacts with the user through the Rasa shell. In the next Blog of this series, we will learn how to deploy Trippy on a Messaging Platform. We will be deploying Trippy on Slack.&nbsp;We will soon publish part 3 of the series. <\/p>\n\n\n\n<p><em>For further reading, <a href=\"https:\/\/www.springboard.com\/blog\/data-science\/data-science-definition\/\" data-type=\"post\" data-id=\"2291\">learn more about data science here<\/a> or see the breakdown of the <a href=\"https:\/\/www.springboard.com\/blog\/data-science\/data-scientist-job-description\/\" data-type=\"post\" data-id=\"2371\">job description of a data scientist here<\/a>.<\/em><\/p>\n\n\n\n<p class=\"rm has-background\" style=\"background-color:#efeff6\"><strong>Since you\u2019re here\u2026<br><\/strong>Curious about a career in data science? Experiment with our <a rel=\"noreferrer noopener\" href=\"https:\/\/www.springboard.com\/resources\/guides\/data-science-process\/\" target=\"_blank\">free data science learning path<\/a>, or join our <a rel=\"noreferrer noopener\" href=\"https:\/\/www.springboard.com\/courses\/data-science-career-track\/\" target=\"_blank\">Data Science Bootcamp<\/a>, where you\u2019ll get your tuition back if you don&#8217;t land a job after graduating. We\u2019re confident because our courses work \u2013 check out our <a rel=\"noreferrer noopener\" href=\"https:\/\/www.springboard.com\/success\/\" target=\"_blank\">student success stories<\/a> to get inspired.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this series 2 of the blog post on how to build a secure AI Chatbot using RASA and Python, we will learn how to level up from Basic NLU to Dialogue Management &amp; Custom Actions. How to Build a Secure AI Chatbot: What Did we Do in Part 1? If you haven\u2019t read part [&hellip;]<\/p>\n","protected":false},"author":100,"featured_media":24084,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_eb_data_table":"","footnotes":""},"categories":[67],"tags":[],"marketing_tags":[],"class_list":{"0":"post-24080","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science"},"acf":[],"_links":{"self":[{"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/posts\/24080"}],"collection":[{"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/users\/100"}],"replies":[{"embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/comments?post=24080"}],"version-history":[{"count":4,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/posts\/24080\/revisions"}],"predecessor-version":[{"id":46206,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/posts\/24080\/revisions\/46206"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/media\/24084"}],"wp:attachment":[{"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/media?parent=24080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/categories?post=24080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/tags?post=24080"},{"taxonomy":"marketing_tags","embeddable":true,"href":"https:\/\/www.springboard.com\/blog\/wp-json\/wp\/v2\/marketing_tags?post=24080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}