Generative AI In AWS-AWS Bedrock Crash Course #awsbedrock #genai

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 here is an amazing crash course on Amazon Bedrock uh many people were requesting for this uh now what exactly is Amazon Bedrock it is the easiest way to build and scale generative AI applications within your AWS platform itself right right now many companies are using this they are using this because understand one thing that there are so many different different companies who are providing llm models for or liim models for different different text Generation animage generation task right there's open AI there is cloudy to there is Google there is even Amazon also has its own llm model like which is named as Titan and similarly there's also Facebook which is like Lama 2 model so understand each and everything is that what is the main problem right now if you want to use these apis if you want to use these models everybody has a different different setup right now what Amazon Bedrock actually provides you it provides you one AWS platform where all the models will be available and through their API calls you can probably use any of this kind of models right now open AI is not there but other than that I could see almost each and every model that was available in Amazon Bedrock now why this is important because a single platform here you don't have to worry about scalability you don't have to worry about other things uh with respect to the cost that is uh uh in the Amazon Bedrock right it is slight more than the open aai and probably in the future it may also get reduced but at the end of the day you should know what exactly Amazon Bedrock is and probably I'll show you in this particular video different different task I will try to code it and I'll try to show you how you can use these apis itself so here is what is Amazon bedrock and easiest way to build and scale generative AI application with Foundation model I'll also discuss about what are this Foundation models as I said so many different different companies are coming up with some llm models so that is the Foundation model you can do the fine tuning here itself you can use any of these models perform any task and even directly you can use it in your application wherever it is required okay so if I talk about uh Amazon Bedrock it is fully managed service that makes FMS that is foundation models from leading AI startup and Amazon available via and API so you can choose from a Vari range of FM to find the model that is best suited for your case so with bedrock serverless experience you can start quickly private customiz FM Foundation model with your own data and easily integrate and deploy them in your application using AWS tools so here you don't have to even worry about the deployment the scalability and everything as such so uh let me just go ahead and click on get started so this is how it looks like now what all companies it specifically support because I'm also going to show you the entire coding also right how you can use all these models right now in this Foundation model uh there are different different models like from AI 21 Labs you can see Jurassic 2 series is there from Amazon you have Titan models from Cloudy you have this cloudy models by anro anthropic uh you have Lama 2 you have stable diffusion by stability AI you have this command by cair so this through this you'll be able to perform different different use cases like chat text image right and it also provides you Hands-On lab uh along with that some kind of learning course some basic learning course which you can probably get started to now here are some of the examples here you can see what all uh different different use cases you can solve with respect to different different models right so with the help of Titan text G1 you can see action items from a meeting transcript Advanced Q&A with citation uh with Lama 2 chat 13B right this 13 billion parameters you have you can create chain of thoughts then here also you have with 70 billion parameters with cloudy you can have character role play code generation content generation contract entity extraction create an image create an image here you can see creating a table of product description uh then you have debug code with Lama 2 uh 13 billion parameters Lama 2 chat then you have Jurassic then you have this right so as soon as you probably click on anything let's say I'm want to go and see that how it is going to create an image so here it is what it looks like right this is the entire API request that you have to probably call and with the help of this this image will be generated let's say I will probably let's see here okay I can open this in playground and I can give my own so HDM of a beach so this is the playground where you can with uh sunset with Sunrise I can basically write like this right so as soon as I give this prompt and if I run it you'll be able to see that I'll be able to see this entire image so it actually creates this this is from the stable diffusion itself right so here you'll be able to see once we wait it uh we'll be able to run it and now here you can see this is an amazing image that is created and you can use HD image cinematic display all different different things you can probably put over here uh I still go with respect to the overviews so as I showed all these things are there examples you can probably see all these things are there you can go ahead and check out in the playground let's say there is something called as creating table of product description here you can see this is the prompt right sunglasses keywords polarized is this is there let's say this is your table you can probably ask any kind of questions and get with respect to the answers also over here right so different different use cases is there at the end of the day I'll just not show you this apis now let's go ahead and Implement all these things right and there are steps some steps which uh we will be seeing completely from scratch again uh you can use any of the services at such yes there is some pricing because at the end of the day you using some cloud services right it always depends on the tokens that you're specifically getting so based on that Amazon Bedrock basically charges you so if you want to see the pricing you can probably go ahead over here and write Amazon bedrock and you can click on pricing right so Bedrock pricing here is the link here you'll be able to see the pricing overview different different pricing is there and this is for th000 input tokens right price per th000 output tokens input tokens output tokens so all these prices is there you can compare it with open AI models and all but still this pricing uh will get reduced as we go ahead more custom Solutions will probably come up right so this is there all good things and you'll also be able to understand uh see Titan is also having this multimodel Bings but at the end of the day we should know that how we can actually create entirely completely from scratch so let me go ahead and start uh this let's see whether I have opened any vs code or not so I will go ahead and start my vs code so let's see over here here is a folder that I've have created over here let me rename this to uh AWS bedro Rock okay and let me show you okay um Bedrock okay and uh let me just quickly show you how you can probably start it okay so I'll show you the entire setup from starting and all what what all things is basically required over here and uh you also require an IM key over here itself right so first of all I will open the terminal now after opening the terminal over here I will open the command prompt as usual we will go ahead and and uh create a new environment that is always a good idea okay so for creating a new environment I'll write cond create minus P VNV python equal to 3.10 with Y okay so I hope everybody knows about this so this will basically create my V andv environment and once that environment is created I will activate it till then I will also go ahead and install requirements. txt Okay so once I install requirement. txt I will be requiring some libraries like boto 3 so boto 3 is a library which will actually help me to connect all the services that we have in Amazon Bedrock right uh AWS Bedrock also so this is some of the things along with this uh I will also go ahead and import or install AWS CLI right so guys now after creating the environment I will go ahead and activate the environment so V andv so my environment has been activated now what I'm actually going to do over here I'll save this requirement. txt and then we will go ahead and install this two libraries one is PIP install pip install minus r requirement. dxt so once I specifically install all these requirements one is two two only libraries are required boto 3 and aw CLI now the next thing till this requirement is getting installed we also need to create and IM user so that we will be able to configure it with the ews itself right so what I'm actually going to do I'll go and click on the homepage okay I will sign into into the console again and here I will search for I am am user okay so once you go to the IM user you'll be able to see that I will go ahead and create a user itself so right now there are multiple users so let me do one thing let me go and see the user already chish is created but I will just create one more user let's say test test admin okay so this is the user that I will specifically create and I will click on next I will say attach policies directly I will select this option and I will give the administrator access okay so administrator access basically means that we are giving the administrator access itself right but again when you're working in the company you will definitely not get this access uh instead uh based on the services that you are specifically using that access you will get okay um I will go ahead and create the policy so let's see once I go over here then it'll ask for some permission so okay forget about policies then I will go ahead and here you will be able to see that I'll select the next button okay after selecting the next button you can see I'm getting the administrator access along with this what I'll go I'll do go ahead and create the user itself now this is the user that you can see over here test admit right and now let me click on this create access key right so I definitely require an access key so for that I will go ahead and create this over here you can select command line interface since we are going to use it for CLI I will go ahead and click on this I understand and then I will go ahead and click on the next Once I click on the next you'll be able to see there some description value it will ask for I will say test key okay and let me go ahead and create the exess key key so here you can see I have the accs key I have the secret SS key now what you can do is that in this particular case uh you can download this right so that later on you'll not be able to see this so it is a good idea that you download this in the form of CSV file so I'll download this in the form of CSV file and inside this CSV file I'll get these two values one is access key one is the secret access key so let me do quickly go ahead and copy this and now I will go ahead and configure it right we need to configure it over here so so already you know that we have also made sure that this AWS CLI is available over here and it is installed now what we are going to do quickly is that we will go ahead and configure it from the command line so let me go ahead and write AWS configure right so here you'll be able to see it is asking for AWS key ID so I will copy and paste it over here so I will copy this and I will paste it over here okay so once I probably paste it you'll be able to see that it will also ask for secret access key so here I will copy it and let me quickly go ahead and paste it over here so here is what see right now you're able to see the exess key but don't worry I will delete this as soon as I complete this video Now the default region it is basically asking so right now it is Us East one so if I go ahead and see my Amazon Bedrock right now where I am pointing to so please make sure that you point it to us East one if you are not pointing over here you can basically whatever region you are pointing you have to write it over there but right now according to me I'm going to point pointed over here right that is with respect to us East one now one more additional setting you really need to do is that go to the model access because see initially when you are in this Us East one this model access will not be given right so over here you have to access you you need to have the status of access granted then only you'll be able to use the specific models now for that when you click on manage model access right automatically the selection will come and here you will be able to just save the change ches you here one option of activate changes will come see in the bottom side like save changes is over here no so here I have enabled it and this access is granted right now if it is not granted then this all will be disabled right now right so what I will do just to show you an example let me just reload this page let me show you whether I have granted some other see let's say with respect to Singapore if I'm in Asia Pacific Singapore region right now inside the sing singapur region you will be able to see that see something is not available over here right like these two are not available so I will skip Singapore let's go to Tokyo okay just to show you an idea because I have already activated in Us East one so if I probably see with this reason here you'll be able to see this much access you have available to a request available to request so if I probably click on manage model and if I probably just click on this let's say these are available aable right I just need to click on request model access so for this reason only this three models are available this two models are available so my always suggestion would be that you go to us East one right in Us East one you'll be able to see multiple models like this right multiple models you'll be able to see it okay so you have to request for the access right if I probably you can select Us East one also or you can also select Us West it is up to you Us West 2 so here also they provide you the access of all the models right so understand one thing why I'm showing you all these things because initially you really need to request the access and this is also what I have requested already so here you'll be able to find out more use cases right so everything is available right but by default I will go ahead and use this Us East of n Virginia okay so right now again my access is granted so you if your access is not granted you have to request for it okay okay so once this is done I'll go back to my command prompt here the default region is US e one so I'll press enter this is what I really want and default output format I want in the form of Json so I will go ahead and write Json okay so this is the initial setup you really need to do now let's start working on different different models so so guys now once we have actually configured now we will go ahead and use any of these models as an example and we'll try to perform various Tas ask so in this example uh let me do one thing uh let me take an example of content generation in Cloud okay so cloudy cloudy one we can specifically take or uh let's say I want llama 2 you can actually take llama 2 so it's it's up to you so let's first of all start start with this llama 2 itself uh and for this I'm going to specifically use Lama 2 70 billion parameters okay the chain of thoughts okay and with respect to to every model you will be getting some model ID content type so this is how is the API request needs to go so we'll form this entire API request through our code and then we will go ahead and hit this okay so let me quickly go ahead and start my coding okay so here I will rename this to Lama 2 Lama 2 so here is the file guys Lama 2. Pui so I will start my code over here so first of all let me go ahead and write import boto 3 I'm going to import boto along with it I'm also going to import Json uh the first thing as usual you will be able to see that whenever I see this files right see Chain of Thought over here I have to create my API request with the help of model name model ID then I need to also put content type then app uh accept then my body should look something like this prompt with all these information see uh in Lama 2 so basically your uh your prompt uh will start with or prompt first character will probably start with first word will start with this okay it's just like an instruction okay I NST then here you have multiple options you can probably see this right uh you have options like Max gen length then temperature then top P9 something like this okay so top P basically means I think it is with respect to the probability so let's quickly go ahead and set up that entire command promp so what I will do is that I will copy this entirely okay and I will create one Json okay I will write test. Json so that I have that format over here so this is the Json I have to make sure that I have to put all my API request in this form okay for using Lama 2 Now quickly I will go ahead and write one prompt uncore data I will say hey uh this prompt data I want to do something like that I'll act I'll say act as a as a shape Shakespeare and write a poem on machine learning let's say this is my prompt that I specifically want to use okay now the most amazing thing is that Amazon AWS Bedrock is quite good you know it provides you easy API the API request you just need to use it and uh start serving it start using it in your application so I will first of all go ahead and use this Bedrock so I will write Bedrock is equal to boto 3 do client and then I will specifically use my servicecore name uh servicecore name is equal to and I have to give the service name as Bedrock uh- runtime so this is the first thing that we really need to do this is the client name like this is the service name that we really need to use and with the help of boto 3 we'll be able to connect to the Bedrock itself so this is my Bedrock over here now the next thing is that I need to form the payload right so this will basically be my payLo load structure as a dictionary I will try to find give the values in key value pair as usual if I probably see the test Jon this is what is my body so I need to have in the form of key value PR prompt is equal to some value then you'll be able to see Max gen length some value temperature some value top underscore P some value so similarly I will also give my payload in this format so here I will write prompt colon and here I will go ahead and write ins since this is my intro right and uh this intro will be concatenated with my prompt underscore data right so this I'm concatenating with my prompt andore data and in the end I have to probably also end this instruction okay so this is how my prompt this this prompt body has got created right this this is what it has got created right because the prompt will get inserted over here now along with this prompt I need to provide some more different different Val values right what all values I need to provide one example is that I'm getting from my API Max genore Len okay and this will also be in the form of key value Pairs and here I will mention 52 okay and then the next thing is that I will go ahead and write temperat with colon5 comma topor P colon9 okay so these are my initial values that I've actually set up and this is nothing but this is my payload the payload that is specifically going over here so once we do this the next thing what I will do this is basically my body so I will write body json. dumps I'll basically convert this into a Json and I will use my payload over here okay so once my body is basically created the next thing what I'm actually going to do over here I'm going to basically write my model ID and use model ID name as usual the model ID name is this one meta this one version one something okay so I'll paste it over here so this basically becomes my model ID itself now I'll go ahead and create my response now in the response what I need to do I just need to write Bedrock the Bedrock object that is created over here dot invoke invoke uncore model okay now inside this I will give my first parameter the first parameter is nothing but body the body will be initialized to this specific body itself uh whatever body we have actually created the second parameter is nothing but my model ID so model oops just a second Bedrock so I have to use this model ID okay so this will basically be my second parameter that I really need to give model ID and this I will initialize to what we need to initialize to this model ID right so my second parameter is also done body is done model ID is done after model ID I need to to give my accept token as usual what is the accept token in test. Json it is nothing but application sljs so I'll paste it over here oops I'll paste it over here done the next parameter after this will be nothing but let me see content type okay so I have to also give my content type over here this will also be my application slon I guess again I'm just seeing this API so whatever values are there my body is ready my accept model ID content type everything is ready these are the four parameters I need to give in my invoke model right what model I'm specifically invoking now once I get this uh you'll be able to see that once I probably go ahead and write response underscore this will basically be my response inside this response understand once I get this specific response I'll write I'll take the body part okay so inner part uh because there will be lot many different different contents that will be coming up so if I write json. loads I will take this value and I will say response. getet so inside this there will be a key which will be called as body okay inside that body you will find out entire information of the response that you're able to get in this particular case whatever text I'm writing act as a six and write a poem on machine learning so this is basically my prompt and it'll give that specific text inside this body okay so I will write this okay um just body. read this is done now I will go ahead and print I can also print it but I don't want it so let me go ahead and write response _ text now inside this one thing that you'll be able to see that whenever we use llama 2 if you don't know I've also created videos with respect to Lama 2 the open source model if I use this response uncore body there will also be a key see inside this body there'll be a body key inside that there will be another key which will be called as generation which will have the entire text of the response that we want okay so I will just go ahead and print this response uncore text done now let's see if everything is working fine or not and whether we will be able to see each and everything so this is very simple a prompt is over here we have invoked the Bedrock then there is a payload then here you have this entire body uh body I've created in the form of Json then model ID accept content type the main thing is understand this test Json right and then you'll be able to do it so perfect let's execute this now and let's see whether everything is working fine or not okay so I will just go ahead and write python llama 2 oops clear the screen okay python Lama 2. py okay so it'll take some time again uh as you all know uh some response time it'll take with respect to the API that we have uh and again now we are hitting the specific API from the cloud uh from the AWS server itself right in AWS Bedrock so so here is the entire text here you'll be able to see in the fair digital R where data do flows free a wondrous od. rise called machine learning yes see this is a this is a science a craft a Mystic spell the dot enable machine to learn and tell with algorithm sharp and data site was computers do not don't gain wisdom and they insides. last and again based on the token size it'll be charging okay so all the information see now whatever prompt you want to give over here right let's say what I'll go ahead and write what is generative like write a poem on generative AI you'll be able to see this you'll get some response over here so I'll save this now I will go ahead and run it okay now similarly you can actually do it with cloudy to you can do it the stable diffusion I'll also show you an example with respect to stable diffusion and then you can also explore that uh as said uh now let's go ahead uh you know we will try to do it with the help of Cloudy to and again uh with respect to that also we'll try to see okay so this is one text generation so here also you can see um in the realm of scode and circularity a Marvel of man's engineer a creation that do rival the generative AI Wonder to see so all the information are specifically coming over here now let's tie another API and then after this we will go ahead and try uh you know the image generation with the help of stable diffusion so cloudy uh let's see where is cloudy cloudy content generation okay so here is my API I'll copy this it is always good to keep a test Json like this okay now almost each and everything is same okay I'll tell talk about like what all changes will basically happen Okay so Lama 2 uh let me just copy this four lines of code will be almost same then I have my payload I will also copy this and then we'll change the payload okay so we'll change the payload so inside this payload you have prompt is equal to human you are an expert social media generation so whatever prompt basic prompt data right so here I don't have to probably create this I don't want this okay so this will basically be my prompt data done then let's go with the next parameter so what are the next parameter come on guys till then hit like I'm working so much hard yeah come on okay anthropic version is there stop sequence is there temperature uh this is there Max tokens is there see Max token to sample is there so let me just quickly go ahead and write what all things I require over here so I will go ahead and write Max uh tokens okay so this will be 512 Max Tok tokens then I have my temperature then I have my this top P parameter looks something like this okay Point top P will be 08 okay something I'm putting some values temperature let's keep it to8 let it be more creative okay so this is basically my payload okay now everything almost looks same uh you'll be able to see that I will uh okay I think uh there is another one let's see content generation is also there this is also there okay fine no worries okay so I will I think I've used another version let me use another one also which I have already tried so it'll be looking good okay so cloudy2 so let's quickly go ahead and create my body so here you have this one so body json. DS payload model ID will be this one right Bedrock this everything is there body model ID application and content type so once we get the response this time when when we get the response body okay like this when we get this specific body now inside this body you'll be able to see that there in the case of llama 2 inside this body we have generation but here inside this body we will be having some more steps okay so that will be some more uh key value pairs so here I've written it so it will be nothing but completions of zero get data and then get text so in completions there it is just like a list of key value pairs so I will just take the first one and then probably display the data inside that whatever text is basically coming and then we will go ahead and response underscore text okay so now everything works fine I think I've used this model or other model so this is version to okay in Cloudy let's see in Cloudy some other version is also there um I don't know from where I found out but it was available here only Advan Q a yes I used I used this one I guess yeah Advanced Q&A I used this model IDE I guess okay perfect so once we do this uh let's go ahead and run it now now I'll go to my terminal now let's see whether each and everything will run fine or not once I tried with Lama 2 now I'm triying with cd2 right so I will write python cloudy to cloudy Dot py okay so here also you'll be able to see the print statement oh this was quite fast right so here you can see O Gentle AI with your boundary power to think and create with no efforts so you are specifically getting this specific output also so this was with respect to cloudy again you can try anything that you want just take this Json just try to play with it uh let's say I I take this information only and use this model let's see I will paste it over here I will take this entire thing and paste this model so here itself I'll change it I think cloudy I may get an error because I don't know whether we are able to manage it or not so I told access denied see so this model is not available the version one is available I guess I think I I explored this early find it somewhere if I probably search this you'll be able to find it I guess let's see but anyhow you try it out from end I and I'll be giving you the code like this we are not able to search Advan Q&A and all okay fine uh next start with uh I think uh see in us why that is not working right because if I go ahead and see the model EXs the Cloudy model is not available see cloudy instant is not available so that is the reason that version one was available and I was still exploring things right and I probably got in that but no worries we'll now go ahead with stable diffusion so so let's go to the base model see version 2.1 these all models are specifically there if I go to examples let's see with respect to stable diffusion so 1.0 is there point8 is there we'll go with the recent one and again I will go ahead and copy this okay so this will basically be my next text Json okay so I will keep all these things over here itself now let me quickly create one more file save this one more file stable diffusion now here we will try to create an image in AWS itself from AWS py okay now for stable diffusion also almost all the things will be same I've already created the code but here what I will do I will just show you what all things I will do see stable diffusion basically means I have written a prompt data see provide me a 4K HD image of beach also use blue sky rainy season and simatic display okay now with respect to this text Json here you can see body has something called as text prompt and then you have text in information and with respect to the text information this is basically my prompt along with this you have parameters like weight CFG scale seed this this this is there so what I do first of all I will set in that format only so first of all I create my promt template where I have my text my prompt data with weight okay so this becomes my entire this information understand this thing guys you just need to set it that's that's it text is equal to this information with weight so I've kept it in the form of list with key value pairs so that is what I'm getting it over here inside this prompt template then I've used BTO client I've used the service name runtime now remaining is all my payload so inside this what all payload you require see first of all I require text prompt the second thing that I required is seed steps width height right width height so let me do one thing I will change this to 1024 I will also change it to 1024 so these are all the parameters I've set step size is nothing but 50 width is 1024 height is 1024 so this becomes my entire payload I have converted this into the Json I've used this model ID because this is the same model ID I'm able to get it over here right stability. stable diffusion X1 V1 it's very simple once you do one right everything will be able to use it so here I've used that then I've invoked this model with content type model ID body everything once I get the response now see what response you will get in this format right when you probably see the response body there you'll be getting key value pairs with something called as artifacts inside that you will find a base 64 encoded response of the images so what we did is that we took this particular artifact of zero we took that base 64 we encoded it with utf8 and this is how you read any encoded image right from that encoded image we have converted that into bytes and then we have saved that particular image to some output directory so output directory output folder will get created and I am creating one image over here right so uh that is what we are specifically doing with respect to this right so file name will be nothing but inside that particular output directory and then we can open that specific image if you want okay we are writing that image sorry we are writing that image inside this particular PNG that is same see whatever things we did over here only the thing that is changing how you're converting that bytes information that we getting into an image and saving that in our folder okay so let me quickly execute and run it and show it to you and then you will be able to understand okay so here I will be showing you python stable diffusion Pui so once I execute it here you now okay request steps 400 generation error what is this error let's see uh okay that is an error let's see what is the error bedrock in invoke model let me [Music] see I think there was a small minor mistake X1 version this this this Clon 3 okay let me see here so now it is working I did some minor mistake over there which I have fixed it okay so this is the bite information that we getting see the image bytes now if I see my output folder this is my image okay so if I go ahead and see find in folder okay sorry I will go ahead and preview in folder reveal in file explorer so if I go ahead and create this image see this image this is how the image is basically created and it's look good right but what is the prompt I've used over here if you see uh with respect to this um my stable diffusion py here we have basically created something like this provide me a 4K HD image of a beach so I hope you got an idea with respect to this uh now in the upcoming videos what I'll do is that I'll create some amazing projects by using this specific apis but in short once I deploy this projects I can deploy it anywhere I want right hugging face spaces anywhere itself so my suggestion would be that try as as many as you can see different different like character role play what is the Improv promp you really need to give based on that try to create use cases which will be amazing for you right so this was it for my side I hope you like this particular video please if you like this particular video please make sure that you hit like like share with all your friends I'll see you in the next video have a great day thank you one all take care bye-bye
Info
Channel: Krish Naik
Views: 28,250
Rating: undefined out of 5
Keywords: yt:cc=on, aws bedrock tutorials, claude 2 code generation, amazon titan in bedrock, llama2 in bedrock, generative ai tutorials using AWS bedrock, code genertaion using AWs bedrock
Id: 2maPaQutcWs
Channel Id: undefined
Length: 37min 16sec (2236 seconds)
Published: Sun Feb 04 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.