Getting Started with GPT-4o in Spring and Java | Spring AI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up everyone and welcome to daily code buffer in this video we are going to see the latest and greatest by open AI that is GPT 4 so we are going to understand what is gp40 and how we can use GPD 40 with spring boot to create the robust spring AI applications so without any further Ado let's get started so first let's understand what is jp4 so GPD 4 is the latest and greatest model by open AI which also stands for o that is Omni okay because it is going to use the all forms of data it's going to use the text voice audio video everything it is a flagship model by openi and it is much faster 50% faster than the previous models and 50% cheaper than the previous models if you go through all the details I'll share the link for you to go through it but this is here you can see that this is the gp4 this is a new model available and and if you click here we'll get more details about this model you can see that this is the latest model available here earlier we were using GPT 4 or GPD 3.5 turbo this is the latest and it is much faster you can see that it is twice the fast and 50% cheaper now why this makes a difference because earlier if you have seen that earlier models that we were using those were really slow whenever we are asking some queries then it will take a lot of time to understand it and to give the data as well and the costing is also high and if you you see this is something it's a platform. open.com where you can use the apis and you can only use GPT 4.0 when you have added the credits to it when you have added some money to it okay it is not a free one it's a paid one the only thing is it's much faster and way cheaper as well so earlier models everything based on the tokens right we can have the less token utilized for quering this gp4 so what we are going to do is we are going to create the Springwood application because spring AI is a library which will help us to to utilize the different GPD models and we can utilize those GPD models to get the data for us and we can create a robust application using AI we do not have to worry about how we can handle the data and anything we just integrate with spring Ai and spring AI gives a lot of different ways to handle those data so we are going to go through each and everything in detail I have also created couple of videos regarding spring Ai and those will be linked in the description below for you to check out but those will be with Charity 3.5 model this we are going to use with the 40 model so enough J jabber let's create the application and let's hit it so what I'm going to do is I'm going to do start. spring.io and from here we're going to create the application so I'm going to create the Java application which is with M1 and spring 3.3 spring boot I'm going to in the group as daily code buffer and it will be spring gp4 okay uh this is my artifact name this is better right and my packaging would be jar and Java version would be 21 and I'm going to create the web application okay now to support for open AI there are a lot of AI direct plugins available you can see that a your AI search Mall AI stability I Azure openi and many things okay but as we are going to use the open model here okay I'm going to directly use open here okay you can see that it is a spring AI support for chat jbd the I language model and Dolly the image generation model from open a so if I use it it will be the open ai's implementation of spring AI if you use any other it will be added for their implementation as well okay so I'm going to use the open here and I'm going to generate the project and open in intellig idea you can use any of the ideas for your choice let's generate the project and open an intelligy idea project is generated let's go to the download section this is the project let me open intelligy idea I'm going to open downloads and this spring GPD 40 okay so this is my project let it load we'll go back here what you have to do is you have to go to platform. open.com okay and here you will be able to you have to log in with your account and from here you will be able to get your API key because with the API key only you'll be able to execute this API and you'll be ex able to execute this model queries on this model once I go to the API keys I can generate my API keys is I already have one okay if you see I already have one API key available this is my API key but you can go ahead and create one for yourself and I have added this API key in my application so I'll show you that as well how we can add it so let's just go back to the application and what we have to do is we have to go to the resources application. properties and here we have to add our key so let's add it here you need to add your key that is a spring. a. open api. API key to key ideally you can add this API key in your environment variables and you can use it I'll be directly pasting it okay and I'll be going to delete this API key as well later and then what you have to do is you have to add the model which model that you want to use so I'm going to add spring. a. open. chat. options. model and I'm going to use gp40 so if I go here okay and if I go to the I need to search the models here docs here okay and this is the check GPD 40 and if I go here let it open and here this is the model GPD 40 or you can use GPD 40 15th October one model okay so I'm going to use this model here and this is what I have added okay I'll quickly add my Epi key as well and I'll close it I have also added my Now API key now what we will do is we will create a controller and we will add a method to call this apis so I'll go to the Java and I'll going to create a class that is AI controller okay and this is uh rest controller okay now here I'm going to add the data so what I'm going to do here here I'm going to do public string find popular players okay it's going to be F public find popular players and this is going to be the get mapping and I'm going to add to a root of it okay and I'm going to take the request param here and that request param is string Sports category okay so in sports category I'm going to take the players list here now to use the chat GPD client what we need is we need a chat client object okay so I'm going to add private chat client here chat client you can see that chat client is a part of the spring framework AI chat okay and I'm going to Auto wire it that's it now using this chat AI chat client you will be able to call it now what I can do is I can just tell return checkline do call method and you should be able to get the data awesome so this is marked as uh deprecated but earlier you will be able to use it okay so now what we'll do we'll use the prompt only so let's do one thing let's add the prompt and prompt template and let's use it so what I'm going to do is add the prompt here okay this is your prompt list of five most popular Personalities in sports category so whatever the sports category that I'm using that one then I'm going to use prompt template template equals to new prompt template and I'm going to pass the message here okay and then with this prompt template I'm going to create the prompt prompt prompt equals to prompt template sorry it is template right so template dot create and here I need to pass the list of parameters that I'm going to pass okay so it will be map off right and I'm going to pass key and value so my key is sports right my key is sports and value is also Sports okay so here my prompt is created now with this prompt I can call my chat client so what I will do I just say chck response response equals to chat c do prompt and I'm going to pass the prompt do call. chat response now what we can do is we can do return response dot get result dot get output do get content that's it okay so with this prompt I am creating a prompt template here and within that prompt template I am passing Sports category that whatever the input that I'm getting that should be replaced with this content with this Dynamic value here and I'm getting the chat response from the chat client here okay and I am getting the response back simple thing now what I will do is I will start my application and let's see what's happening and there is an issue I cannot aome chat client is not found so if I go here we have one implementation that is a default chat client implementation right so let's try this way rather than rather than Auto wiring it we will create a Constructor and use it okay let's start our application and see okay there is no qualifying Bean for this chat CLI so let's try to fix it we have chat c and this sh C is off AI okay okay I am trying to use using the Builder here let's see it if it's working awesome it is working now so with Builder is working so now what I will do is I will go to the browser and I will go to Local Host 880 Sports equal to tennis okay this is my API and I should be getting some data here and yes I am getting some data okay because I have just hit for the tennis and for tennis I'm getting the data so you can see that it's a very simple application that we have created that we have created a prompt template and a prompt and a chat response and we are getting the data and we using the chat client to get the data and we are just passing the sports category that we are whatever we are taking here okay so if I'm taking Cricket I should be getting the data for cricet and it should be much faster than the previous models okay so we are getting the data for Cricket as well let's go back to tennis awesome this is tennis so here you can see that we are getting this list here right and this list is not that much useful we cannot do anything with this data it's a string right so we need something that we can handle the data internally we need to pass this data if I want to use this data and to itate through it I if I want to use in a bean or anything that is something that I should be able to do okay so what I will do is there are output pares available within spring AI that we can use to do this so let's try to use those output parsers as well and let's anal this data and let's convert the data in the format that we want okay so here if you see that currently I want a list of five most popular personalities and I'm getting this way so let's do one thing let's use output parser and let's get the list of data okay so to use the output parser there are multiple output parsers available so what I will do is let me go to Output parsers okay there is one called list output parser it's a converter right so you can see that this is a converter available earlier versions of spring it was having parser but now it's a converter so there is a converter available and using this converter we can do multiple things so let's go to its parent interface and it is implementing structured output converter and a converter okay so this is basically a converter where you can convert the data and there is a converter available and there is a format provider as well so there are three implementations of format there is a bean output list output and a map output so either you can get a data in the terms of map in terms of list and in terms of bean okay so let's use the list one here so what I will do is I can go to AI controller rather huh so I can use list output converter converter equals to new list output converter okay now what it takes is a default service so I'll just say def new default conversion service okay so my converter is ready so now what I have to do is I can just say that I want some data in a format okay I will just add one thing now this as a new element I have to add here as well in prompt right so I'll just say I need a format let me just remove this because this is a format and format I will get from my converter okay so I'll just use converter do get format now if you see this if you go to this format here you can see that there is one extra prompt added that your response should be a list of comma separated values like Fu bar and bass okay so now with this extra information chat GPT should give me the data in the comma separated values and using the comma separated values this output converter should convert the data into the list now to do this what I have to do is I have to wrap this response which I'm converting getting back into that wrapper right that is a converter so I'm going to do converter do convert right and I'm going to do this now as we have added the converter now my return type is list of string and here I have string so what I will do I will just do this is a list of string now so rather than me getting data this way which is just a string I should get a list of the sports personalities right so what I will do is now I will just restart my application and my application is restarted and now if I go back and if I hit the same API again hoping that we getting the list you can see that now I'm getting the data in a list let's check for cricet I'm hoping that we are going to get for Cricket as well yes so you can see that now we have a more usable data right now with this we can do something we can iterate through it we can now get more information regarding this many things that can be done so this was one of the output part output converter that is the list output converter let's take one more example of a bean converter as well so what I'll do is I will just copy this entire thing okay let's just create it new so now rather than list output converter what I will do is I will do it's a bean output converter okay equals to new Bean output converter and I can pass the class so suppose I'm going to pass player do class so I can create a player I have not created let's create it so let's create a player class rather than class we can create a record okay and I'm going to take some data here so first let's understand if this is working yeah now your be output converter is ready now what I'm going to do is I will go to the player class and I can say I need string player name and list of string as a achievements okay so you can see that I have simply created a bean and I want the data into this Bean now rather than just getting some string or a list okay that I want a play and its achievement so now what I'm going to do is I am just going to say I'm going to just change the now my prompt because now it's getting me list I don't want list now I need a player and my players information achievements so rather than this I'm just going to change to this generate a list of career achievements for the person alities in sports category that whatever I'm passing and include the player as a key and achievement as the value for it and I'm going to still pass the format okay so now format what I can do is the same thing converter do format okay with this converter I'm going to take the format for it and here now you can see that it's an object right convert. convert so I'm going to say this is going to be now my player hope this works what are the different methods for convert let's see it takes the string and it pass the T and bean output converter right so here we need to pass so Bean output converter new converter player dot hopefully this should work okay now you can see that the issue is solved so now let's restart my application and now I should be getting some data in Bean so my application is restarted now now let's go back to the browser and let's hit Dennis awesome I'm getting null data because it's not able to pass it correctly let's see one more time you need to play around with this because this is not a g available yet okay and this is not released one yet so we are just playing around with it so we are getting some issue here most probably we are getting the data but we are not able to convert it correctly because there might be some issue in the prompt we need to give it correctly hopefully the player name if you see the player name achievement that is coming but it's coming as null let's see for Cricket if I'm getting anything awesome for everything we are getting null but but let's change the prompt and if he let's see generate a list of career achievements for the so what I'll do for the sports person and the name of sports person I'll say okay now if I restart it my restarted now rather than click I'll just pass Ms Tony awesome you can see that now I'm getting a player name and it's achievement you can see he has a lot of achievement right so now you can see that my prompt is now such a way that it can probably get the result in a map where a key is a player name and the data is a list okay which is how we have added here so you need to make sure that whatever the prom that you are setting up the same way that you should be able to get the data bag as well so you need to set it correctly right then only your output parsers output converters will work correctly so you can see that with just one change we were able to get it now we can get a list as well so you need to work around with this list and wrap it around that bean with a list of converter right so we have multiple now available so now you need to convert you need to wrap your bean converter to the list converter and you'll be able to get that data as well so this way you should be able to convert your raw output which you get directly as a string to the different sets of option we saw that list and up Bean you can also use map as well so if I use something else that is Muhammad Ali I should be able to get for Muhammad Ali as well you can see that I am getting the data for Muhammad Ali as well so this way you can see that now I'm able to get it correctly for every personalties I'll be getting the data in this format and I can iterate through it if I want to do it and accordingly I can work on it so this way you can create your application and work around with your data rather than just string you can use these output parcel and output converters to make your appc application robust so this was all about the chat GP 40 and how we can use the output converters to get the outputs in different format for our application to use and you can change it according to the requirements and according to the promps that you have set I will add the link for this project in the description below for you to check out if you have any doubts regarding any of the things that we have covered then do let me know in the comment section below I hope you like this video so give us a thumbs up and subscribe to my channel for the upcoming videos I will see you in the next video till then Happy cording bye-bye
Info
Channel: Daily Code Buffer
Views: 6,308
Rating: undefined out of 5
Keywords: openai, artificial intelligence, chatgpt, gpt-4o, gpt-4o demo, gpt-4o api, gpt-4o app, spring ai, spring ai project, how to learn openai, spring boot, java, ai with java, ai with spring boot, spring boot genai
Id: FXj3CUf6YRE
Channel Id: undefined
Length: 19min 57sec (1197 seconds)
Published: Sat Jun 29 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.