Build AI chatbot with custom knowledge base using OpenAI API and GPT Index

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi this is Serena Nick from Tech foundation and in this video I'm going to show you how to create your own AI that can answer the questions based on your custom knowledge base so why do you have to create custom AI if you already have charge repeating well you can ask chargepc something about the general knowledge on the internet like for example what is ux design or what is product management and charge GPT will give you a decent answer based on something it has seen before on the internet and there is no way that charger PC can answer questions about the specific knowledge for example about my specific user research because there is no way it can access this data and that's why I've decided to create my own AI it's pretty easy just few lines of code we are going to use open AI API so still we are going to use GPT 3 model and we just upgraded in that way that it knows about our custom context how are we going to let this model know about our custom context well we just give it in the prompt you might ask why cannot we then use just check GPC for that because we can give the context in the prompt also in charge repeating the problem is that usually user research databases are quite big and if you want to implement any other custom knowledge database it's usually big so you cannot put everything just in one prompt and that's why we have to create a little bit more flexible way to give the context in the prompt and we are going to do this by breaking our knowledge database on small chunks and indexing these small chunks so when we query our AI it will be able to find the relevant context in all our database and based on only this relevant context give us the answer so we are not going to give all our knowledge in one prompt in one query but we are going to find the relevant knowledge and give only these pieces of information to our Ai and that's how it works pretty easy so instead of going and giving all the content effects we are we need to find a way to find a relevant context and that's why we need an external library to do this and that's why we cannot do it manually but we have to do it in code indexing that data is not an easy task but luckily for us there is already an open source library that we can use so we don't have to go into the technical details how to do that but we just need to figure out how to use this Library the library is called GPT index and it is also using gpt3 API in order to break your data and make an index out of it so we just need to figure out how to use it and it's pretty simple I'm going to show you now how I've assembled a small project in Google notebook it is called collab environment so you can also follow this tutorial and try it on your own so the first thing that we need to do is to upload our data that we want to Index right and if you want to use your custom knowledge database then you need to create a folder here named context data I've called it context data and then slash data but you can call it whatever you want and then just change the name here so you create a folder with all the files from your knowledge database and it will be there uh I've prepared already a folder for you that we are going to use in this tutorial and these are uh just fake interviews so I cannot share with you the real interviews because it's a sensitive information and it's private information I cannot share it so I've decided to create fake interviews also with the chargerp team I've actually asked jgpt to create an interview script for me about cooking habits and the use of domestic appliances it created not very good interview script but for the sake of experiment I think that's fine so after that I've asked the GPT to give me an interview script for these questions and I gave it just example of what an interviewee is so I created just a small use case like business professional living alone who tries to control on his diet and for the this small use case 2gbt was able to give me an interview script that later I was using as the custom knowledge base so in this example we are going to use a fake user research data unfortunately it also means that we cannot be we cannot get any really insightful information out of it because still tgpt provides you uh quite blank data so it's more like a boilerplate than um real insights but unfortunately I cannot share with you the real information so that's what we have so I've created a repository for you that you can copy into your project and there is already a piece of code for that we are going just to run it and what it does it clones our git repository that is here and add the information here so now it's not there I just need to update it yes reload please um yeah I don't know why it doesn't show it from the beginning but anyway now we have our context data and we have a data folder inside where we have all our interviews you can check this interviews interviewer answers and interviewee answers and interviewer questions so for our examples we are going to use just for interviews of course in the real scenario you're going to have much more then we need to install the dependencies so we are going to use the GPT index library and this library in turn uses the line Channel Library so we are going to use actually two libraries that we need to install now we run the code it is installing all right we install down dependencies and now we are going to create our functions that we are going to use and it's only a few lines of code just two functions for us so first we need to import everything that we need from DPT index and line chain and if you want to learn more about it you can just go to the documentation and it is written here what you need or you just copy it's the same and then we are going to write just two functions first one is construct index and these functions this function take the directory path in our case it will be context data select data and it creates an index out of it so instead of having just the row data like we have here it will create a Json index here that will index all the information that it finds here and that's all the first thing that we are doing here is just setting parameters for the large language model that we are going to use so it's just the parameters from open AI API and you can also find the parameters here so maximum length the temperature that is responsible to how the answer of AI is different from one another so if you ask the same question will it be always the same transfer and then the temperature will be zero or will it give for um different answers and then the temperature will be higher so you can read more about the settings for lash language model in the open AI API documentation and you can then play in the playground just asking questions to I for example what is ux design and then checking what answer it will get and that's what we are doing here we set the parameters like maximum input size we set that temperature the model name because there are different models and you can learn more in the open AI documentation and so on so after we set all the parameters we are going to use the functions that are defined in the GPT index Library so we just have to Define our path that we are going to use to create our index and that's basically all after defining the path and loading the data we are just creating the index and saving it to the local folder and that's basically all what we do just loading the data running the index and then saving the index in Json format here and then we have the second function and what it does is only querying our AI model with the question and context information so we first identify the index that we are going to use and then just query the AI with the user input so here we ask a user to input something what we uh what we want to ask our Ai and then we just query our AI with the context information and displaying everything in markdown format so pretty easy we just have to run this code and for now you won't see anything because we just we just let this notebook know that these are our two functions we didn't run them yet then we need to set our open API keys so uh to in order to use openai API we need a key and you can get it by signing up on their website so after you sign up you'll have here API keys so if I go here view API Keys it will be there if you don't have anything you can create a new secret API it will create an API for you that you can copy I copy this one press OK and just go here and run the code it will ask me to put my open AI key here so that's what I will do and you will do as well I won't show you my key because you need to use your own and the reason for this is because using openai API is not free but it's relatively cheap so for example for all my experiments I've spent only 14 cents and you'll get 18 dollars for free so they call it credit but whatever now it's time to construct our index so remember we defined the function here construct index and now we just need to run it with the path of the data that we want to index so in our case it's context data data so let's run it all right so we have created our index and it will appear here I don't know why this Co-op environment doesn't show it immediately but if you reload it will show it so let's just do it after we reload we can see that index.json is now here it wasn't there before so it all worked and now what we need to do is just start asking questions so quite exciting let's try uh remember our data was about interviews about cooking and using domestic appliances and the information from these interviews is what our AI will use to answer our questions for example I can ask what people like about cooking at home because the interviews were about cooking at home and we were asking this question to our interviews let's try to see what it will answer so it transfers that people like cooking at home because it allows them to relax and unwind after a long day it's Health it healthier and more affordable than its and out and so on so all this information was mentioned in our interviews unfortunately this time it didn't break it down but we actually can ask our AI also to break it down into clusters and then it will be easier for us or for example we can even ask to brainstorm something for example marketing campaign based on our interviews and already use AI to brainstorm something about our project and it's very exciting because now we can actually use AI to brainstorm with us to brainstorm about our project based on our information so it won't use just the general information from the internet but it will use the information relevant to us in order to brainstorm more ideas after you played enough with your AI you can just stop this it will show you the error but this is because we just stopped this code from happening so it's not there just the keyboard interrupt so don't be worried about it and that's it just few lines of code actually the only thing that we do this is the install independencies let's close it uh it's just this one so we just Define the functions and that's all and then we just run the functions I hope this video was helpful for you and now you are able to create your own AI that will use your custom knowledge base don't forget to like this video And subscribe to the channel because here you could find a lot of relevant and free information for designers bye foreign
Info
Channel: Irina Nik
Views: 41,672
Rating: undefined out of 5
Keywords: UX/UI design, User experience, Design, Design course
Id: vDZAZuaXf48
Channel Id: undefined
Length: 14min 50sec (890 seconds)
Published: Sun Feb 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.