Hybrid Chatbots: How to Chat with Multiple Data Sources (Pinecone, ChatGPT & More)
Creating a Customized Chatbot using AI: A Technical Deep Dive
We are going to create a chatbot that we want to query and how this looks in action so we can run stream alert run app dot Pi. So here we have the app running NBA GPT chatting with multiple data sources now I've brought it up like this because I want you guys to watch the terminal carefully here because when I put a query in it it's going to take it through that intent classification process and it's going to print out where it's being sent to so you can see for each of these Handler functions it will print using the buffet Handler print using the brands and handle Etc so we're going to be able to see if this is working correctly.
So I want to increase AOV from an e-commerce business. How can I do that? Then, I'll use the homozy Handler. So it's working correctly now we need to wait for it to get that information back and then create the answer since you need to generate it from the information it's pulling. So let's see what it says. And see here we can see we've gotten an answer back from the homology Handler, it's actually referencing some of the different podcast episodes that it's being pulled from which is helpful sometimes helpful not but this is an example of the homozy Handler being used correctly.
And this time we can test out the buffered Handler by asking a question about investing. So I'll say how can I referred into the market. And here we have using the Buffett Handler so it's correctly identified it as a investing relating question. Or we can even ask something more specific to Warren's skill set on his own personal opinions. How do you evaluate a stop. Using the buffet Handler and it's answering Ed Warren Buffett would ask yourself if the company is easily understandable good solid history all those regular stuff that came out of the letter to investors that have been put into the vector database this is pulling from.
So the final example that we can do is entrepreneurial based questions. So how can I vote with a full life as using Branson Handler to live a fulfilling life as an entrepreneur. You need to do what excites you and brings you Joy as Richard regins suggests don't just think about the cost or speed of your business but focus on creating something amazing and valuable so this is all pulling from the Crypt databases when we query it so the intent classify system is working correctly.
And there's only one last thing to do which is to ask it a generic question that isn't related to either of the databases or any of the databases sorry. So I'll say what color is the ocean and it says using other Handler down the bottom. So we're correctly identify buying it as an other based question and here we have the ocean often absorbs blue reflects something like that a lot of that so what we have here is a custom mods chatbot that can intelligently route queries to the relevant database so that it can get specific knowledge applied to the question.
So we have Warren Buffett for investing our looks from Aussie for business and Richard Branson for entrepreneurial advice all of these is essentially like sprinkles on top of chat gbt because now any query that comes in that's regular can be sent to the church CPT API but with augmented chat gbt by giving it these different custom knowledge bases in different areas with the specific knowledge of the different grades in respective field. So I think it's really cool that you can do this and I hope you guys got something out of this.
I'll be sharing this code if you want to steal it off my GitHub you can check that out in the description but I'm sure you guys have a bunch of interesting use cases for this kind of stuff within your own businesses. If you can get in touch with me as a consultant or get in touch with my development company if you'd like to build something out with us we do these sort of projects all the time and I thought I'd give you guys an example so that you can visualize it and sort of get an idea of what's possible with these tools at the moment. So that's about it for the video guys thank you so much for watching if you haven't already signed up to my AI newsletter in the description also my AI entrepreneurship Discord they're down there too so if you want to watch any more videos they'll be here here and in the next slide but thank you so much for watching and I'll see you in the next one.
WEBVTTKind: captionsLanguage: enin front of us this example of the four functions that the chatbot can do all from within the same UI so here we have a regular query being answered as if it's chat gbt here we have a business related question querying a homozy database here we have a stock related question querying a Warren Buffett knowledge base and finally we have a entrepreneurial based question answering that question from a Richard Branson knowledge base so all four all in the same place but intelligently relating to the relevant databases in this video I'm going to be showing you how to create a hybrid custom mods chatbot that can not only answer user queries on your custom mod space but can also answer and serve as a regular purpose chatbot similar to chat gbt by setting up a system that can intelligently route the queries based on what the user is needing to do so if it's a question about your custom knowledge base the query will go to the custom knowledge base if it isn't related to your custom knowledge base it will be relative to the chat GPT API or gpt4 whatever you want so firstly I'm going to be breaking down how these systems work and how you're able to have multiple different data types attached to a bot and essentially send the queries to them only when it's relevant so this is how you create really flexible and multi-purpose Bots with tons of different data that's intelligent enough to know what the user is asking for and where if you're new to the channel my name is Lee Motley and I help entrepreneurs wrap their heads around AI by giving you simple and easy to understand tutorials breaking down the complex Concepts down to this simplest form and if you haven't already subscribed to my AI newsletter or join my AI entrepreneurship Discord you can get those links in the description so the example app that I'm going to be using to illustrate how these systems work is called MBA GPT and it's something that I whipped up for the purposes of this video that I thought you guys might find interesting and maybe give me some ideas about how you could actually apply this technology to your business and to your personal life now the idea behind this app is to be able to connect multiple different data sources or in this case Vector databases filled with information so in this case I've taken Alex from Ozzy Warren Buffett and Richard Branson and I've found the content online from PDFs Etc on all three of these guys so that I have a ton of information to sort of make up some kind of knowledge base for each of them and then what I want to do is connect all three of the knowledge bases into the app and allow the app to essentially route the query depending on what the user is asking so if I'm asking something about business I've told it to Route it to the Alexa mozzie database so get all those information on how to scale online businesses Etc and use that to answer the question but if the user is asking about investing then it's going to be routed to the Warren Buffett custom knowledge base and look for any similar things within the database there and bring that back and answer it and then finally anything related to entrepreneurship and the lifestyle side of things and and who you want to be as an entrepreneur is going to be relative to the Richard Branson side so the key thing here is that the chatbot is going to be able to intelligently route the user's query to the database that has the information relevant to get that answer so investing for Warren Buffett business for Alex Modi and Entrepreneurship for Richard Branson and the final nail in the coffin here is that if the query is not related to business investing or entrepreneurship it is then going to be relative to the chat EBT API and treat it as a regular question so if you're asking something like what color is the sky or what color is the C it's going going to go this isn't about investing this isn't about business this isn't about entrepreneurship we're going to classify this as other and let's route that to the chair GPT API and get an answer so in this way the chat bot and how you're able to use it is going to be super super flexible and that anything that doesn't match what we have information on in the vector databases can just be sent to the chat GPT API and answered as a regular question so that's a lot out of the way but that's how these apps work and I'm going to jump in and show you an example of it now so first things first I needed to get them information on all of these guys in order to use to create a custom knowledge base that we can then query so you can see on the left here I've got a docs folder and it has Branson and it has a buffet folder Richard Branson I found some stuff on the internet all sorts of things most of these are actually not written by him but in the case of Warren Buffett we have some letters to investors that have been compiled all sorts of things in Berkshire Hathaway really really good stuff of all of his investment a philosophy and and how he likes to go about investing so here's all the information I have two PDFs on each of them and then for Alexa mozzie I've already done all of this sort of they data collection and putting into a database so if you haven't seen my Alexa multi 500 chatting to podcast video where I essentially create an AI version of him that's going to be available up here if you want to watch that but essentially I already have that playing Vector database set up and ready to go with I think at the 163 different our customers put in there so that I can just plug straight into this app and I don't actually need to ingest anything to create the Buffett and Brands and indexes I just have this indexing.pi file which is essentially using a lang chain and it's going to be creating a chroma DB out of each of them and saving it to this DB folder so that's all done here I can just run the script once and then it's going to save it and then I don't have to do it ever again I can just load them each time instead of having to recreate them now I went to the app.pi file you can see where most of the magic is actually happening so what we have set up here is actually called an intent classifier now Lang chain has a similar thing to this in terms of their tools but this is sort of a straight to the point way of doing it without using all these libraries you can essentially just use language models to to set up your own intent classifier and have a little bit more control over it so I prefer to use this setup currently but what we have here is the XT Delta text input so the text input is on the chatbot when people type something in and when they submit it this is what's going to be triggered so this generate response function is up here as in the Alex mozzie bot so this is where all the magic is happening as soon as the user's message comes in we send it straight to this intent classifier function which is here at our utils.pi now this may look a little bit complex but essentially all we're doing is using a open AI chat completion using the 3.5 turbo model and we're essentially using the GPT 3.5 turbo to classify what the user is asking for so here you can see it's using this prompt and it's actually replacing the prompt with what the user sent so in our prompts file we have the prompt here now this is what I'm calling a classification prompt we do a bit of role prompting here Etc same sort of stuff but the real magic is here where I say your task is as follows your analyze user inputs and classify each input into four different categories four categories of business question investing question entrepreneur question or other if you can't tell what it is say other so here we have of category is business question output 0 investing question one entrepreneur question two other three Etc so these are the three categories Alex and Aussie four business question Buffett for investing question and uh Richard Branson for entrepreneur question and other is just sending it to the chat GPT API so here we do a little bit of a shop prompting as I'm sure you're familiar with if you've watched my other videos I generated all of these with chat gbt I just said give me some examples of prompts that are related to business and put it in this format so this is essentially some examples of how it should deal with it and how it should output and then we have user input and prompt so that takes us back to here which is where we're going to be taking the user prompt from what they've just sent in put it into the intent classifier function replace that prompt with what the prompt is it might be can you write me a plan about diversifying my portfolio so that it's for an inflationary environment or something so what this is going to do is send that prompt off with their sort of insertion and then what we're going to get back is a number that we can then use going back to our app.pi file up here and pass to the route by category function so here it's going to the intent classifier Returns the number that we get from the big prompt that we sent off and that number is then going to be passed into this route by category function so essentially we figure out what category it is and then we route them to different handlers so these are Handler functions up here and each one of these handles essentially what the user query is and gives us back what we need for that specific I guess custom knowledge base that we're sending it off to so if it's related to business it's going to be routed to this homology Handler it's going to query the homozy database and give back a bunch of information from that database and Etc if it's related to investing it's going to be sent to the buffer Handler and if it's related to entrepreneurship it's going to be sent to the Branson Handler and finally the other Handler is here now what happens after the Handler functions have returned their information gets a little bit more messy but I won't take you through that now I'll just show you this in action and show you how we are actually routing to the correct Vector database that we want to query and how this looks in action so we can run stream alert run app dot Pi so here we have the app running NBA GPT chatting with multiple data sources now I've brought it up like this because I want you guys to watch the terminal carefully here because when I put a query in it it's going to take it through that intent classification process and it's going to print out where it's being sent to so you can see for each of these Handler functions it will print using the buffet Handler print using the brands and handle Etc so we're going to be able to see if this is working correctly so how can I increase aov from an e-commerce business and then bam using the homozy Handler so it's working correctly now we need to wait for it to get that information back and then create the answer since you need to generate it from the information it's pulling so let's see what it says and see here we can see we've gotten an answer back from the homology Handler it's actually referencing some of the different podcast episodes that it's being pulled from which is helpful sometimes helpful not but this is an example of the homozy Handler being used correctly and this time we can test out the buffered Handler by asking a question about investing so we can say how can I referred into the market and here we have using the Buffett Handler so it's correctly identified it as a investing relating question or we can even ask something more specific to Warren's skill set on his own personal opinions how do you evaluate a stop using the buffet Handler and it's answering Ed Warren Buffett would ask yourself if the company is easily understandable good solid history all those regular stuff that came out of the letter to investors that have been put into the vector database this is pulling from and now I guess the final example that we can do is entrepreneurial based questions so how can I vote with a full life as using Branson Handler to live a fulfilling life as an entrepreneur you need to do what excites you and brings you Joy as Richard regins suggests don't just think about the cost or speed of your business but focus on creating something amazing and valuable so this is all pulling from the Crypt databases when we query it so the intend classify system is working correctly and then there's only one last thing to do which is to ask it a generic question that isn't related to either of the databases or any of the databases sorry and we can say what color is the ocean and it says using other Handler down the bottom so we're correctly identify buying it as a other based question and here we have the ocean often absorbs blue reflects something like that a lot of that so what we have here is a custom mods chatbot that can intelligently route queries to the relevant database so that it can get specific knowledge applied to the question so we have Warren Buffett for investing our looks from Aussie for business and Richard Branson for entrepreneurial advice all of these is essentially like sprinkles on top of chat gbt because now any query that comes in that's regular can be sent to the church CPT API but with augmented chat gbt by giving it these different custom knowledge bases in different areas with the specific knowledge of the different grades in respective field so I think it's really cool that you can do this and I hope you guys got something out of this I'll be sharing this code if you want to steal it off my GitHub you can check that out in the description but I'm sure you guys have a bunch of interesting use cases for this kind of stuff within your own businesses if you can get in touch with me as a consultant or get in touch with my development company if you'd like to build something out with us we do these sort of projects all the time and I thought I'd give you guys an example so that you can visualize it and sort of get an idea of what's possible with these tools at the moment so that's about it for the video guys thank you so much for watching if you haven't already signed up to my AI newsletter in the description also my AI entrepreneurship Discord they're down there too so if you want to watch any more videos they'll be here here and in the next slide but thank you so much for watching and I'll see you in the next onein front of us this example of the four functions that the chatbot can do all from within the same UI so here we have a regular query being answered as if it's chat gbt here we have a business related question querying a homozy database here we have a stock related question querying a Warren Buffett knowledge base and finally we have a entrepreneurial based question answering that question from a Richard Branson knowledge base so all four all in the same place but intelligently relating to the relevant databases in this video I'm going to be showing you how to create a hybrid custom mods chatbot that can not only answer user queries on your custom mod space but can also answer and serve as a regular purpose chatbot similar to chat gbt by setting up a system that can intelligently route the queries based on what the user is needing to do so if it's a question about your custom knowledge base the query will go to the custom knowledge base if it isn't related to your custom knowledge base it will be relative to the chat GPT API or gpt4 whatever you want so firstly I'm going to be breaking down how these systems work and how you're able to have multiple different data types attached to a bot and essentially send the queries to them only when it's relevant so this is how you create really flexible and multi-purpose Bots with tons of different data that's intelligent enough to know what the user is asking for and where if you're new to the channel my name is Lee Motley and I help entrepreneurs wrap their heads around AI by giving you simple and easy to understand tutorials breaking down the complex Concepts down to this simplest form and if you haven't already subscribed to my AI newsletter or join my AI entrepreneurship Discord you can get those links in the description so the example app that I'm going to be using to illustrate how these systems work is called MBA GPT and it's something that I whipped up for the purposes of this video that I thought you guys might find interesting and maybe give me some ideas about how you could actually apply this technology to your business and to your personal life now the idea behind this app is to be able to connect multiple different data sources or in this case Vector databases filled with information so in this case I've taken Alex from Ozzy Warren Buffett and Richard Branson and I've found the content online from PDFs Etc on all three of these guys so that I have a ton of information to sort of make up some kind of knowledge base for each of them and then what I want to do is connect all three of the knowledge bases into the app and allow the app to essentially route the query depending on what the user is asking so if I'm asking something about business I've told it to Route it to the Alexa mozzie database so get all those information on how to scale online businesses Etc and use that to answer the question but if the user is asking about investing then it's going to be routed to the Warren Buffett custom knowledge base and look for any similar things within the database there and bring that back and answer it and then finally anything related to entrepreneurship and the lifestyle side of things and and who you want to be as an entrepreneur is going to be relative to the Richard Branson side so the key thing here is that the chatbot is going to be able to intelligently route the user's query to the database that has the information relevant to get that answer so investing for Warren Buffett business for Alex Modi and Entrepreneurship for Richard Branson and the final nail in the coffin here is that if the query is not related to business investing or entrepreneurship it is then going to be relative to the chat EBT API and treat it as a regular question so if you're asking something like what color is the sky or what color is the C it's going going to go this isn't about investing this isn't about business this isn't about entrepreneurship we're going to classify this as other and let's route that to the chair GPT API and get an answer so in this way the chat bot and how you're able to use it is going to be super super flexible and that anything that doesn't match what we have information on in the vector databases can just be sent to the chat GPT API and answered as a regular question so that's a lot out of the way but that's how these apps work and I'm going to jump in and show you an example of it now so first things first I needed to get them information on all of these guys in order to use to create a custom knowledge base that we can then query so you can see on the left here I've got a docs folder and it has Branson and it has a buffet folder Richard Branson I found some stuff on the internet all sorts of things most of these are actually not written by him but in the case of Warren Buffett we have some letters to investors that have been compiled all sorts of things in Berkshire Hathaway really really good stuff of all of his investment a philosophy and and how he likes to go about investing so here's all the information I have two PDFs on each of them and then for Alexa mozzie I've already done all of this sort of they data collection and putting into a database so if you haven't seen my Alexa multi 500 chatting to podcast video where I essentially create an AI version of him that's going to be available up here if you want to watch that but essentially I already have that playing Vector database set up and ready to go with I think at the 163 different our customers put in there so that I can just plug straight into this app and I don't actually need to ingest anything to create the Buffett and Brands and indexes I just have this indexing.pi file which is essentially using a lang chain and it's going to be creating a chroma DB out of each of them and saving it to this DB folder so that's all done here I can just run the script once and then it's going to save it and then I don't have to do it ever again I can just load them each time instead of having to recreate them now I went to the app.pi file you can see where most of the magic is actually happening so what we have set up here is actually called an intent classifier now Lang chain has a similar thing to this in terms of their tools but this is sort of a straight to the point way of doing it without using all these libraries you can essentially just use language models to to set up your own intent classifier and have a little bit more control over it so I prefer to use this setup currently but what we have here is the XT Delta text input so the text input is on the chatbot when people type something in and when they submit it this is what's going to be triggered so this generate response function is up here as in the Alex mozzie bot so this is where all the magic is happening as soon as the user's message comes in we send it straight to this intent classifier function which is here at our utils.pi now this may look a little bit complex but essentially all we're doing is using a open AI chat completion using the 3.5 turbo model and we're essentially using the GPT 3.5 turbo to classify what the user is asking for so here you can see it's using this prompt and it's actually replacing the prompt with what the user sent so in our prompts file we have the prompt here now this is what I'm calling a classification prompt we do a bit of role prompting here Etc same sort of stuff but the real magic is here where I say your task is as follows your analyze user inputs and classify each input into four different categories four categories of business question investing question entrepreneur question or other if you can't tell what it is say other so here we have of category is business question output 0 investing question one entrepreneur question two other three Etc so these are the three categories Alex and Aussie four business question Buffett for investing question and uh Richard Branson for entrepreneur question and other is just sending it to the chat GPT API so here we do a little bit of a shop prompting as I'm sure you're familiar with if you've watched my other videos I generated all of these with chat gbt I just said give me some examples of prompts that are related to business and put it in this format so this is essentially some examples of how it should deal with it and how it should output and then we have user input and prompt so that takes us back to here which is where we're going to be taking the user prompt from what they've just sent in put it into the intent classifier function replace that prompt with what the prompt is it might be can you write me a plan about diversifying my portfolio so that it's for an inflationary environment or something so what this is going to do is send that prompt off with their sort of insertion and then what we're going to get back is a number that we can then use going back to our app.pi file up here and pass to the route by category function so here it's going to the intent classifier Returns the number that we get from the big prompt that we sent off and that number is then going to be passed into this route by category function so essentially we figure out what category it is and then we route them to different handlers so these are Handler functions up here and each one of these handles essentially what the user query is and gives us back what we need for that specific I guess custom knowledge base that we're sending it off to so if it's related to business it's going to be routed to this homology Handler it's going to query the homozy database and give back a bunch of information from that database and Etc if it's related to investing it's going to be sent to the buffer Handler and if it's related to entrepreneurship it's going to be sent to the Branson Handler and finally the other Handler is here now what happens after the Handler functions have returned their information gets a little bit more messy but I won't take you through that now I'll just show you this in action and show you how we are actually routing to the correct Vector database that we want to query and how this looks in action so we can run stream alert run app dot Pi so here we have the app running NBA GPT chatting with multiple data sources now I've brought it up like this because I want you guys to watch the terminal carefully here because when I put a query in it it's going to take it through that intent classification process and it's going to print out where it's being sent to so you can see for each of these Handler functions it will print using the buffet Handler print using the brands and handle Etc so we're going to be able to see if this is working correctly so how can I increase aov from an e-commerce business and then bam using the homozy Handler so it's working correctly now we need to wait for it to get that information back and then create the answer since you need to generate it from the information it's pulling so let's see what it says and see here we can see we've gotten an answer back from the homology Handler it's actually referencing some of the different podcast episodes that it's being pulled from which is helpful sometimes helpful not but this is an example of the homozy Handler being used correctly and this time we can test out the buffered Handler by asking a question about investing so we can say how can I referred into the market and here we have using the Buffett Handler so it's correctly identified it as a investing relating question or we can even ask something more specific to Warren's skill set on his own personal opinions how do you evaluate a stop using the buffet Handler and it's answering Ed Warren Buffett would ask yourself if the company is easily understandable good solid history all those regular stuff that came out of the letter to investors that have been put into the vector database this is pulling from and now I guess the final example that we can do is entrepreneurial based questions so how can I vote with a full life as using Branson Handler to live a fulfilling life as an entrepreneur you need to do what excites you and brings you Joy as Richard regins suggests don't just think about the cost or speed of your business but focus on creating something amazing and valuable so this is all pulling from the Crypt databases when we query it so the intend classify system is working correctly and then there's only one last thing to do which is to ask it a generic question that isn't related to either of the databases or any of the databases sorry and we can say what color is the ocean and it says using other Handler down the bottom so we're correctly identify buying it as a other based question and here we have the ocean often absorbs blue reflects something like that a lot of that so what we have here is a custom mods chatbot that can intelligently route queries to the relevant database so that it can get specific knowledge applied to the question so we have Warren Buffett for investing our looks from Aussie for business and Richard Branson for entrepreneurial advice all of these is essentially like sprinkles on top of chat gbt because now any query that comes in that's regular can be sent to the church CPT API but with augmented chat gbt by giving it these different custom knowledge bases in different areas with the specific knowledge of the different grades in respective field so I think it's really cool that you can do this and I hope you guys got something out of this I'll be sharing this code if you want to steal it off my GitHub you can check that out in the description but I'm sure you guys have a bunch of interesting use cases for this kind of stuff within your own businesses if you can get in touch with me as a consultant or get in touch with my development company if you'd like to build something out with us we do these sort of projects all the time and I thought I'd give you guys an example so that you can visualize it and sort of get an idea of what's possible with these tools at the moment so that's about it for the video guys thank you so much for watching if you haven't already signed up to my AI newsletter in the description also my AI entrepreneurship Discord they're down there too so if you want to watch any more videos they'll be here here and in the next slide but thank you so much for watching and I'll see you in the next one