Introduction to AI Chatbots and Chatflow
All right, so in this video I'm going to show you how to build two AI chatbots. Now one of the AI chatbots that we're going to build is able to answer questions from the PDFs or text files from the knowledge base and the other chatbots can be able to trigger workflows like calling APIs to query data. For example, I want to get top three cheapest products and it's going to generate the query and be able to send to the API to get the results. It's going to format the response and then return the response back to us. For example, here's a response for the top three affordable products currently available.
And not only that, we can also be able to trigger a workflow to purchase an item. For example, I want to buy Apple, then it's going to trigger the workflow and once the workflow has succeeded, it's going to give us a confirmation saying that the order has added successful. And there's also additional features like displaying the follow-up questions after a chat. And not only that, we can also be able to upload files and be able to convert voice to text message inside of our chat application.
I will also show you how we can later embed our AI chat applications to our web applications. For example, here I have a web application run on my local machine and you can see at the bottom right corner that that there is a chat icon and if I were to click this you can see that I was able to see the conversation that I had with the chatbots. I can be able to interact directly with the chatbots here. For example, I'm just going to ask a questions to find item with price that are less than $300 and it's going to trigger this workflow. And here you can see these are the response that we got from the workflow and you can see that these results are all less than $300, including a follow-up questions. And of course, we can also be able to display the chat applications right in our applications. And if we were to scroll down, you can see that we can be able to continue with the chatbot in the chat input. So that's what we're going to build in this video. If you're interested, let's continue.
Introducing Dify.ai
Now we're going to build our chat applications using a tool called Dify, or D, depends on how you want to call it. It's a tool that's very similar to make.com or n8n or Zapier, which you can be able to also create workflows in this tool. And if you're interested to try it out, there's also a free tier that you can be able to follow along with this video. So I'm just going to begin start by talking about how we can be able to build a simple chat applications that can be able to answer questions from the knowledge base.
Creating a Knowledge Base
All right, so first we need to create our chatbots, but before we do so we need to create our knowledge base so that the chatbot have context on the information that that the chatbot can answer. So first we're going to click on knowledge and we're going to click on create knowledge here. So here I'm just going to upload a file. So basically I used ChatGPT here to generate the customer support chats as well as the product FAQ and the product information so that we can be able to use a simple knowledge information that we can feed to the chatbots to be able to answer those questions. So we're going to click on next and in terms of the text chunk we will just leave the default settings, but you can see that for text pre-processing rules we can also delete any email address or URLs that's contained inside all the files that we have. And we can also preview the chunk which we do see a text grouping for different files that we have here. We can also view other documents. Once we're satisfied with the text chunking, we can then look at some other informations like we can use a vector search or we can use a hybrid search. But once we're satisfied with the options, we can click on Save and process. So here you can see the embedding process is currently processing.
Okay, so the process has been completed for the embedding.
Building and Testing the Q&A Chatbot
Then we can click on Studio and click on create from blank and here we're going to choose chatbots that we're going to create for our applications. And we're just going to call it test bot. So it has some informations that we feed into the robot that's going to answer the questions that we give. So we're going to click on Create and we can be able to click on a add knowledge here. And we're going to use the fake customer data that we have feeded into the knowledge base, and then we can choose the models that we can be able to use. So we can choose a GPT-4, GPT-4o, and once we select the model, we can be able to debug and preview, which means that we can be able to ask questions to the robots to test. And here I basically say hi and it's basically saying hello, how can I assist you today? And I can be able to say what product do you sell? And you can see that it's basically using the knowledge that we feed into the chatbot to answer those questions. For example, the Ultra X Smartwatch is what we have inside of text files, so we can be able to use that to to generate the response. And if you were to look at the knowledge here, we also have the frequent asked questions. For example, can the Smartwatch make phone calls? And you can see that it supports the Bluetooth calling, so I'm just going to ask this question and let's see how it responds. And you can see that yes, we do have that, and it also give us the citation as well.
Embedding the Chatbot into a Website
So once we're satisfied with the result, we can then click on run app to be able to run the application, and this link is fully accessible to anyone who has access to this link. So then what we can do is we can click on create new chat and start chatbot to basically start the conversation with the chatbot. So here I can be able to ask the same question, what product do you sell? And you can see that we have a similar response that we got from the debugging session.
Now we can also embed this into a site. Now to embed it on the website, there's few option we can choose. One is we can be able to do iframe where it can be able to add anywhere on the website, or we can add the chatbot to the bottom of the website so user can be able to click it to open and close. We can also do like a Chrome extension where user have to install the Chrome extension to be able to use it. But in our case we can be able to test it by using a simple iframe. So here you can see I have a simple HTML here and I launched it with a Python server that's on a port 8000 and if I were to navigate to Local Host 8000, this is our application. You can see that our website has a chatbot that we can start the conversation. So here I'm just going to say hi and now you can see the chatbot is able to generate the response. So if I were to ask what product you sell, and you can see that we're able to get the correct answer from the chatbot.
Designing a Chatflow for API Automation
All right, so so far we learned about how we can be able to create a chatbot that can be able to answer questions from the knowledge base. Now, what we want to talk about is how we can be able to create a chat flow, which our chatbot is going to trigger a workflow and be able to return a response to the user. So we're going to select this and since I already have created a chat flow, I'm just going to walk you through how I create this process so you can get an idea on how you can be able to create a chat flow using a similar tools. You can see the workflow start by getting a prompt from the users. So once we have the prompt from the user, we're going to have a question classifier which will basically classify the user prompt and decide which workflow we want to trigger.
So if the user want a query for simple product informations like fetch me the topmost expensive items that we have then it's going to go through this flow. And then you can see that with this flow, we first have a API schema, which is a knowledge base, and this API schema has all the information about our API that we can use to generate our API query. So in terms of API query we're going to look two things. We're going to use the prompts that user creates as well as the current API schema, then we can be able to generate the API query that we can pass it to the API call. So here you can see this is the API call and we can make this call to our API to fetch the data. And this is going to be a get request. And once we have the data returned from the API, which is a JSON format, we're going to use a large language model to format the response. So I can also be able to click onto this and you can see that this is the system prompt and it's going to use the context which is from the API response as well as the user query. And based on the question that the user ask as well as the response that we get from the data, then we can be able to answer the questions and send it back to the user.
So you can see that's basically how we carry the data from the API and generate the response back to the client. And let's say if user wants to purchase an item, then the question classifier is going to decide a path. So if a user is going to purchase an item, then it's going to go through this path. So first, we're going to extract the product the user want to purchase, then we can be able to pass that product to an API call with the request body. And once the request is successful, then this module is going to return a JSON data, and we can be able to use this JSON data to be able to format the response. In this case, we're going to get a order status. So it depends on the response from the API, either the order is successful or failed, then we're going to format the response and return this back to the user. So pretty much that's how we create the workflow.
Conclusion and Recap
So that's pretty much it for this video. As you can see, we learned about how we can be able to create a AI chatbot that can be able to answer questions from knowledge base as well as how to create a AI Chat Flow that can be able to answer questions that can trigger a workflow and be able to answer questions from the users. So if you do found this video helpful please make sure to like this video and also consider subscribe. Thank you for watching. I'll see you in the next one.