Step By Steps Tutorial To Create Conversational Q&A Chatbot Using Gemini Pro Free API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello all my name is krishn and welcome to my YouTube channel so guys in this video we are going to see how we can actually build a conversational Q&A chat bot with the help of Gemini Pro API not only that we'll also try to save all this chat in the form of a history and we will also display all the results that we all had a conversation about that is the reason we are discussing about conversational Q&A chatbot so before I go ahead guys we will keep the like Target of this specific video to th000 so that I will definitely get motivated and I'll try to bring more similar kind of projects for every one of you out there now before I go ahead please let me go and go ahead and show you the demo so this is how the demo demo will look like so if I ask hi you can probably see I will be getting the answer the response how can I assist you today the chat history is I have asked hi bot says hi hello how can I assist you so let's say if I go ahead and ask what is generative AI okay all the previous information I really need to record it somewhere right so let's see after this the chat history right now is this much right so generative AI also known as so and so all the information is coming up and after that your chat history will also get updated and the best thing is that I'm streaming all the specific data okay so how streaming actually works and all we'll also be discussing about that so here you can see in the history I've asked what is generative Ai and this is specifically all the information now this is what we are going to Implement step by step I'll show you each and everything again all the files regarding this all the code regarding this will be given in the description of this particular video so let me go ahead and let me solve this specific project so guys I have opened my VSS code over here and right now uh if you remember in my previous video I've discussed about all these things like vision. py how you can actually play with images with the help of gini API Gemini Pro API then we also discussed about some kind of simp simple Q&A chatbot now in this video I am going to show you this entire code with respect to this QA chad. py so here is what is my entire code I'm going to specifically write step by step I'll try to show you what all things is basically required as usual first of all we need to have an environment file with respect to Google API key this you can actually get it from makes. google.com so from there which will basically provide you all the features to create the API key for gini pro the first thing is EnV file once we create the EnV file then we will go ahead and start implementing our code if you have not seen all the videos in My Gin playlist I would suggest go ahead and have a look so let me quickly write over there all the code so first of all I will go ahead and uh load all the environment variables so for this I will use forv um import load uncore EnV okay and then we will go ahead and initialize load. EnV and and finally I'm going to import streamlet as St so I'm going to use streamlit over here and remember one thing guys there are some important libraries that you need to install that is present in the requirement. txt everything will be provided in the description of this particular video the GitHub code right so I'm going to use streamlet Google Genera VI and python. EnV all this Library needs to be installed before ahead right so I'm importing stream rate. asst then I will go ahead and import OS because I will be requiring it and then I will say import Google do generative AI as gen AI okay so I'm going to use this Library only for doing all my task now initially whenever we load any environment key first of all we need to set this in my gen AI so for doing that I will write gen ai. configure configure is a method where it will be asking for the API key that I have and since I've already loaded that from my environment variable so you can see that os. get En EnV I'm using this Google API key okay now the next thing over here I will try to create a function function to load gini pro model okay so here you can probably see gini pro gini pro model and get response okay so I'm doing this and here you have model. gen AI dot generative model I'm going to initialize my generative model itself and in this case also I'm going to use gini Pro okay so Gemini pro and gini pro vision for conversational Q&A we will specifically be using this one that is called as gini Pro okay and then we will go ahead and execute it and write chat model dot startor chat and here I'm going to specifically use history okay so this history will also maintain all the things that we are probably going to uh have in our conversation but I will show you another way where I'll use the power of streamlet to store all the history in a form of a session later on you can also put that inside your DB or you can also use it from your session itself right uh so first of all let me go ahead and Define my definition so here I will basically write definition get gini uncore response response and inside this response I will specifically give my question whatever question we have asked so this function should basically uh you know give me the response that I'm getting from the generative model itself like from the gini pro right so this question I will send it to my llm model and then I will specifically get the response so here I'm going to write response chat. sendor message and here I'm going to basically write question stream is equal to True okay so stream is equal to true because as the llm model is giving you the output we are going to stream it and we are going to display it right and then we will go ahead and return the response so once this response is basically coming this response is nothing but it is the output right when we specifically get response. text now we are going to initialize our stream late app for initializing it what we are going to do is that I'm going to use this three Fields one is the Q&A demo J Min L application page config and header it is very much common now the most important thing is that if I really want to record the History part right the history of the conversation we will initialize session state so in stream late it provides you session States for chat history if it does not exist so I'm saying if chatore history not in session State then we will go ahead and create a session state and we'll write chatore history over here so right now it is blank as soon as we have any conversation later on we'll try to record all those we'll try to put all those conversation inside this particular session state that is what we are going to look at then in the next step we are going to basically say input is equal to St do textor input and here I'm going to basically use input input and here we are basically going to write key is equal to input okay so input will be my variable name in short whatever text box I'm specifically using along with this I'm going to also use a submit button St do button and here I'm going to basically write ask the question okay so what I've actually done I've initialized my session okay session state so over here that the name of the session state is chat history okay now if I click on submit or input right basically both the fields input should also be filled okay so if both this satisfies both this conditions satisfies then what I will do I will write I will go ahead and call my get Gemini response and here I'm going to basically give my input whatever input I am probably giving it now as soon as it calls this function it is going to get that message and it goes to get that response okay now the next thing is that add user query and response to session chat history now see as soon as I probably have created this input this is what is my input that a user has given and this is what is the output that we have got right now what I'm actually going to do here for all this entire history right we going to save this in our chatore history session state so for that we will go ahead and write St do session State okay st. session State and here we are going to basically use chatore history okay chatore history and I'm going to do append with this specific let's say I'm going to write you basically you who sending the message and then I'm going to basically use input okay so I am storing all this session inside this particular U variable okay and finally I will get my response also so let me write over here St do subheader and here I will write a statement saying that the response is the responses and in short I have to probably display the response Now understand one thing we used something called a stream is equal to true that basically means this entire response can without getting the entire content can also be populated in whatever Pages we want to probably display right what what do I mean is that now my process did not have to wait for the entire content to come from llm so as llm is sending text Data whatever response it is basically sending it is going to display it in the front end screen okay so that is what we are basically looking at so now I'm going to write from Chunk in response see that is the reason when we write stream is equal to True okay that basically means we get the access of all the streaming data and then we can write a for Loop and I'm saying from Chunk in response and here I write st. write and we will go ahead and write chunk. text so we are displaying the text part by part and along with this I will go ahead and append this entire response okay and here instead of writing youu I will write bot okay and inside this instead of writing input I will go ahead and write my entire chunk. text so what I'm actually doing is that as soon as I get the response it is coming in the streaming manner we are displaying it and accordingly we are also appending in this chatore history okay now this is perfect this is done I'm finally what I will do is that I will just go ahead and create my history because I need to display all the history right so here I will go ahead and write the chat history is okay so this is what I am going to basically Implement and and here I will say for RO comma I will create two common variables in St do session State and here I'm going to use my chatore history okay okay chatore history and whatever is there it is either in the ski value pairs U colon bot colon some kind of answers here I'm going to basically write st. write I'll use a f one over here and I will say roll colon and then here I will say text so in this specific format okay roll colum text now let's go ahead and see if everything works fine or not okay and I will go ahead and open my terminal I'll delete this let's see so we are now displaying perfectly all our details uh this VNV has got activated I've already shown you in my previous video how to activate V andv environment also and here we will go ahead and write stream late run uh QA chat q a chat. py and let's see if everything works fine or not so it has got executed so here is my things I will say Hi how are you and then we will go ahead and ask the question let's see whether we'll get the response the response is I'm a conversational AI chat bought this the chat history is having all the details okay and it is giving chunk by chunk you can see over here right uh let's ask some other question my name is Krishna okay something Kish what is your name okay something like this and I will go ahead and ask the question let's see whether this is getting saved or not okay so here you can see how are you this my name is krishn what is your name I'm a chat bot assistant I do not have a name B designed to help users so and so so all the information that I probably type it over here along with the response it is getting recorded in the chat history now this is what I really wanted to show it to you and it was so much easy many people had asked this specific question in my upcoming video what I'm going to specifically do is that I'm going to create a PDF documents with the help of gini API I'll show you different embedding techniques how we can convert a word into vectors and then how we can utilize for a normal document Q&A kind of thing with the help of gini API right so I hope you like this particular video this was it from my side all the information regarding this will be given in the description this particular video thank you take care have a great day bye-bye
Info
Channel: Krish Naik
Views: 36,099
Rating: undefined out of 5
Keywords: yt:cc=on, chatbot tutorials, chtabot wwith gemini pro, build Q&A LLM appplication, generative ai tutorials, gemini pro tutorials, krish naik generative ai
Id: o4ZhXSVuPyc
Channel Id: undefined
Length: 14min 32sec (872 seconds)
Published: Mon Dec 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.