How to incorporate your AI model to your chatbot Help Center June 01, 2022 12:33 Updated Index Overview Using AI on Builder's Output Conditions Validation waterfall AI-based chatbots Hybrid chatbots Using the content assistant Overview First, make sure your artificial intelligence (AI) model is properly set up and published. Also make sure that the following steps have been completed: Set up and connect an NLP provider (IBM Watson, Microsoft LUIS and Google Dialogflow). Create at least one intention with a few text samples. Train and publish the model in the respective provider. Now you can start calling your AI through your chatbot, by using AI on Builder's output conditions. You can create three main types of AI-powered chatbots: An AI-based chatbot, in which every message from the user is sent to the NLP provider. This provider further identifies the intents and entities and then redirects the flow. A hybrid chatbot, with one or more main flows. If the user leaves the flow, AI is responsible for bringing them back to the experience. A chatbot that employs a content assistant. The assistant replies users using pre-configured text. This chatbot is perfect for a FAQ format. Using AI on Builder's Output Conditions In order to incorporate AI to your chatbot flow, we are going to use output conditions from Builder's blocks. First, we will set the data source to “Identified Intent” or “Identified Entity”, and the condition to “Equals to” to integrate with your AI model. A best practice we recommend in this tutorial is to capture the messages that fall into the exception block and process them using the AI feature. We should be careful when creating the list of output conditions and remember to leave the more specific above the more generic ones. This should be done for the sake of order (checking precedence) to avoid specific conditions never being checked. Check the example illustrated below. It shows two conditions that verify the intention “Generate a second invoice”; however, the second condition also needs to verify that the entity “invoice” exists. In this case, what happens if the condition that verifies the intent comes first than the condition that verifies the entity? Note that, if the intention “Generate a duplicate copy” is identified, regardless of whether there is an "invoice" entity or not, the first condition will be satisfied. When that happens, the second condition will not even be checked! However, if the condition that verifies the entity (i.e., "invoice") comes first, and there is the intent “Generate a duplicate copy” in the user's sentence, we have two possible scenarios. First scenario: if the entity is identified, this condition will be satisfied. Second scenario: if the entity is not identified, then the next condition is checked, and correctly satisfied. Validation waterfall A good practice for using AI in chatbots is to run a pre-validation routine when submitting the user's message to the NLP provider. Please remember that this message can be an image, a video or an audio file and not contain text to be processed. In addition, the message may be too small (a single word), too large (such as a fragment of text that is copied and pasted several times), or simply a brief greeting or farewell. These are some common examples of messages that the chatbot can receive that fall into the exception block. These messages do not need to be sent to the NLP provider. They can be previously discarded with a pre-validation, generally known as a “validation cascade”. First, we add some conditions to validate the user's input text. The purpose of this action is to verify that we are dealing with a regular text, prior to sending it to the AI to process. If this piece of text is not an ordinary text, let's direct the output to the standard Error block. Now click on the Exception block and then access the “exit conditions” tab. Next click on the “Add Output Condition” button and a new condition will be created at the end of the list. We are going to check whether the Builder variable that stores the type of received content is an image, a video or an audio file, and then we direct it to the standard Error block. AI-based chatbots The first step is to add a validation waterfall to the flow's exception block. This action filters messages, based on their importance, before sending them to the AI. The ideia is to avoid the processing of unnecessary messages. Next, download the flow here and import it into the Builder to follow the step-by-step tutorial. This chatbot, known as FAQ, is used to answer questions with NLP (Natural Language Processing), making the conversation more fluid. The flow starts in the “Start” block, followed by the Welcome message, and then goes to the “Exception” block, where all the AI dealings take place. The first image shows the flow. The second image presents the output settings using AI of the “Exception” block, which uses entities and intents to access each specific block. When a message is sent to the chatbot, it goes to the “Exception” block, where the information is analyzed. This analysis checks whether the message fits one of the intents or entities. If one of these cases is identified, it is sent to the corresponding block, following the flow. If nothing is found, an error message will be sent, explaining that the message was not recognized. Using AI enables us to improve our chatbot. If the amount of intents and entities is not enough, we can create new intents and entities. After that, we can always train our AI and publish it again. Hybrid chatbots In this section, we will show you how we can integrate AI into a chatbot that handles services for an online store. It has a simple flow with a few menus and submenus. If you want, you can download this flow here and import it into the Builder to follow the step-by-step tutorial. Regarding the flow, after the Welcome block you will find a menu block displaying some topics that the chatbot can handle. Depending on what the user chooses, this person will be redirected to a submenu with options detailing that particular topic of his/her choice. The problem is that, in this scenario, the user may often not be able to get to these submenus and find the desired option, or he/she may even send an unexpected message. Thus, we can set up the AI to process every message that deviates from the standard flow and redirect users to the block that best matches their needs. The following image shows the chatbot flow we are going to use in this tutorial. First, we add a validation waterfall to the exception block of the flow in order to filter messages before sending them to the AI, the ideia is to avoid the processing of unnecessary messages. Now, in the output conditions of the exception block, we add conditions that will be satisfied if certain intentions and/or entities are recognized and checked in the user's sentences. First, we create a condition in such a way that, if the intent that says “Generate a duplicate copy” is recognized, the flow will be redirected to the “Duplicate copy menu” block. Thus, if the user says something related to generating a duplicate copy of a document, and the NLP provider is able to identify this intent, the user will be automatically redirected to the block that deals with this topic, with no displaying of error or misunderstanding messages to the user. If you are having trouble creating exit conditions to check intents and entities, please check out again our section Using AI on Builder's Output Conditions. You can also create more complex output conditions by identifying entities in a sentence, in addition to intents. For example, we create a condition in a way that, if the intent "Make a change" and the entity "Payment method" are both recognized in a user's sentence, the flow will be redirected to the block "Change payment method", as shown in the following image. Finally, this process of creating output conditions with intents and entities can be extended. You can create as many conditions as necessary, making your chatbot increasingly assertive during a conversation, creating a much more fluid and natural conversation. If you would like to download the final flow to see how it looks after you have created the output conditions, click here. Using the content assistant It is also possible to set pre-configured responses for a given combination of intents and entities. To do so, you have to register these combinations (along with the respective responses in the content assistant) in a submenu located in the AI tab. To learn more about this, click here. After registering the desired combinations, we will set up the content assistant's search in the Builder's chatbot flow. To do so, we will also use the exception block to capture messages that deviate from the conventional flow. These will be sent to the NLP provider so the the intents and entities present in the sentence can be identified and then the provider returns the appropriate content, if any. First, access the Builder. Click on the Exception block and then go to the “Actions” tab. Click on the “Add input action” button and create a new action of the type “Check content assistant”. A new action will be created with the fields: “Variable”, “AI reliability” and “Variable for return value”. In the “Variable” field, fill in the variable that stores the content of the message sent by the user (“input.content”). Filling the AI reliability field is not compulsory. If it is not filled in, the reliability registered in the chatbot settings will be used. In other words, you can leave this field blank. The return variable field will be filled with “contentResult”, but it can be filled with any other name of your choice. Now you have to set up in the output conditions that, if a combination is identified, it must redirect to a block that will display the content of that combination. Next, create a new block with a suggestive name (e.g., “Content Assist Response”). In this block, add a text "balloon" with the variable's “Value” attribute you set to store the response from the content assistant. To do so, use the “@” operator. If you have set the variable as “contentResult”, it will look like this: “contentResult@Value”. All set! Finally, click the Exception block again, but now go to the “Exit Conditions” tab. Click the “Add output condition” button to create a new condition. Create a condition in such a way that, if there is a variable that stores the response from the content assistant (e.g., “contentResult”), then it goes to the block that displays that content (e.g., “Content assistant's response”). Remember to place this new output condition above more generic conditions to guarantee that it will be checked and executed correctly. For more details, see the section “Using AI on Builder's output conditions”. Congratulations! Now you have a chatbot that uses AI to provide automatic answers if a user's sentence does not fit the flow as expected. For more information, visit the discussion on the subject in our community or the videos on our channel. 😃 Related articles How to configure Dialogflow as your AI provider Using the AI tool inside Builder How to use the Content Assistant After all, what is AI (Artificial Intelligence)? FAQs