ChatGPT and Spring Boot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] [Music] foreign [Music] [Music] foreign [Music] [Music] [Music] foreign [Music] thank you foreign [Music] thank you foreign [Music] thank you [Music] thank you [Music] [Applause] [Music] today [Music] hey hi good good to see you all I am uh I will make this quick because it's really easy I love this I love what just happened here so I woke up I'm in um I'm in Malaysia at my my partner's uh mother's home and uh we're on route to uh we're going to Australia and by the way I'll be in Australia I'll be in Sydney I'm doing a a thing at the Microsoft reactor this week uh this coming week so if you're there uh yeah come come say hi come come out but anyway I'm anyway I'm in uh Malaysia we just came here to drop off some some luggage and um I just came from Taiwan yesterday and uh uh I was it's Father's Day and I was like oh I'm so excited it's Father's Day and I checked on the internet and sure enough really cool things happen somebody one of my friends from uh uh from from China actually um uh who now lives in the states uh he tweeted Out Source Code two to a um a starter to use chat gbt and I was like well fine if he's doing it then I'll bite I want to see what it's like so uh and it's actually really easy so what we're gonna do today friends is we're gonna look at it and uh yeah I mean it's not it's not going to be very difficult uh he did a great job and it's a it's using spring boot 3 and it's using the declarative interfaces so even the code that he wrote was not particularly onerous um uh but you know somebody's got to do it otherwise what's the point right so let's just dive right into it huh um let me close all this stuff down here one second I'm shedding my old workspaces here okay downloads okay I'm gonna share my screen uh okay higher screen what could go wrong huh there we go ah let's see Hello everybody yes good morning from the Philippines hi well I guess yeah good afternoon you're in the same time zone as I am I'm in Malaysia basically the same time zone right uh if not exactly the same um uh yeah and it's really not that hard yeah Simon you're absolutely right I just haven't done it yet because I'm I'm I like my sleep I just I've got sleep hey from Turkey good good afternoon from Turkey Turkey is it is it well I guess it must be yeah that's a few hours ahead isn't it I guess you must be just just crossing the date line right or the the afternoon line um so yeah that's interesting uh okay so yes Simon is making a great Point hello from Uzbekistan hi goodness good hello hello hi hello I love it I love it we are all here good morning hello good afternoon good evening Happy Father's Day to those of you that celebrate uh it's not everybody that has a great father uh worth celebrating uh or and or that is a father but for those of you who celebrate um Happy Happy Father's Day and it's also not everybody that celebrates it today this is not a worldwide thing it's just certain places uh I know in the U.S for example um okay but Simon as always in with the win he has some great points and that's what I want to talk about first which is if you're gonna use uh chat DBT then um you need to make you need to pay if you want to use the API right hello from Kenya hi from India good afternoon from India good afternoon from Kenya oh that's great that is great um let's see let me reconnect my apparently my LinkedIn is no longer connected that seems um poorly timed let's see here uh yeah so anyway um apparently I'm fishing my own thing okay I'm gonna just log in right here so yeah anyway one thing you have to know is you have to have a key in order to have a key you need to have a paid I mean you can have a key but you can't really do anything with it without a paid plan so you have to go to chat uh you know a platform.openapi.com and then get yourself a um let's see it was sent to my email address okay well I don't know whatever um you have to go to chat you have to go to platform.openapi.com and uh and then you know create a key but then also actually maybe you should do this first maybe you go to uh usage let's try that usage this is my usage you can see I don't use it a lot this is my first day uh using it members I don't know what is it billing there you go create a paid account it'll be right here it'll say it'll say that you need to create a paid account uh in order to use to do anything fun right um yeah I did I'm reading Simon's message there about because I tweeted the other day what you know with all this AI wouldn't it be great if we could just have something be a really good inbox for email it seems like we've got use cases for AI except for the stuff that still sorely needs it um hello hi so yes so you go to uh chat gbt or platform.openai.com because that's the organization that administers chat gbt uh go there make sure you've got a paid account it's pay as you go so they're going to ask you to put a five dollar credit card on deposit you know five dollar deposit on your credit card do that uh if only because you want to experiment and it's not all that expensive and I think there's even like a a certain amount of credits you can get I don't know whatever it doesn't anyway five dollars I appreciate that that's not universally cheap but for me it's it's not enough that I I really worried about it and all I wanted to do is to try it out after all so create the paid account um and then once you've done that go create a key so you're going to want to go to a user API Keys create a an API key here remember to note it do not put it on your screen I'm certainly going to try and avoid doing that myself uh and if there's any possibility that I might have done that I'll just delete this key after the Stream um and and remember they charge you based on the sort of the the shape of the request the amount of text uh Etc that you send in so so it's it's it can get expensive and it depends on which engine you're using there's actually a number of different engines that you can use to uh hello hola como estas yes hi good to see you there's a number of different engines that you can use to talk to uh you know via one API so you get one HTTP API and you can use a number of different engines um but in order to do this work we're going to use a project here uh not my project I didn't write it I'm you know entirely too lazy .com bye my friend like I said uh Jackie right um and he's you know he's a I I don't think it's okay so maybe I'm not giving away the plot yeah he's I don't know if you can infer this or not but you know Alibaba our socket broker right so he's doing really cool stuff with spring and spring boot um uh and just generally an interesting human being and he uh he built a a new thing recently called uh gbt Springwood starter updated 16 hours ago and he just tweeted it and you know as you can imagine um can I make a Discord Community yes I should absolutely would any of you join my Discord Community if I were to create one that's a good I wish I had a way to administer a poll just put a one in the chat would you uh if you're interested that way I'll I'll know if there's any value in that Earth it would just be yet another siled place I would hang out there I would love to have a a place I can just go and you know chat with people yeah um so okay uh yeah so he created this spring boot starter and it's a spring boot three starter um we're gonna use it today there's already some opportunities here uh for improvement you know it's already really good um and uh I can you know I'll send a pull request that's what I'll do right after this but I do have to get this done and get packed and get to the airport because I'm going to Australia so um let's see let's try this out okay friends what we're gonna do is we're gonna go as usual start that spring that I own okay look at that we've got a lot of people saying yes and one person saying I should add a poll on YouTube but also if you're in the chat I you know I just want to know just want to know okay so I'm going to call this before a I not z i a i we're going to use um the gravyam native image support uh and that's it right that's it how many cups of coffee have I had today yeah that's a fair question friends that's a very fair question I'm even more excited than usual uh about this super simple little opportunity here this uh vbt support so uaoai.zip okay now like I said you need a key again I have that uh open a i I have that I have an environment variable called open AI key you'll have to specify that to use the starter so we'll we'll come back to that in a second I'm not going to use it yet but we need to bring that in the dependency that we need in order to use this uh obviously is here and it's on Maven Central already so just watch this what I copied and pasted I copied a um Maven artifact dependency declaration and I pasted a Gradle one which is still one of my favorite magic tricks okay so that's on the class path application of properties now we know there's an openai dot key equals this okay so I'm just gonna point that to that and then I'm ready to go okay and uh we are now let's see AI application and what you know simple example the example that he has in the project is basically what we're going to see right that that code I think is simple enough and it's basically just using a prompt to ask uh chat gbt to write an email um and there's two different variations and we'll go over both of them they're already interesting enough and I just feel like we could uh have some fun pretty quickly here so the first example is uh just a very simple makeup make a request to the completions API we don't have to by default it's going to use chat gbt35 turbo right now there is a chat gbt4 and actually there are a number of other uh sort of full text models and and other things as well but for our purposes just to get started let's just start simple okay so we'll say that mean nope nope that's different in application Runner um chat GPT so return new application running so we're just gonna talk to the API uh you could easily build an HTTP controller or something like that I just want you to see what it looks like to use the API in isolation so in order to do this work we'll inject the auto configured chat DBT service so DPT okay and we can say GPT dot chat and we pass in a chat completion request right so chat completion request that uh functions and then or or just of so here's a very simple prompt right and we'll just do the prompt that he's got in the um an example because I think it really works it's really kind of illustrative uh please write an email inviting uh let's say Josh long.com and uh Josh at Coffee software.com to the production party uh later today at 1700. okay so that's the prompt and I'm just going to pass in this prompt right here of our response um I use the service I'll say the service uh you know GPT dot chat pass that in okay and that'll give us a reactive stream so actually we don't even need to do that we can just work with it so we say uh map response and here he's very helpfully broken it out so you can get access to some of the um constituent parts of the request including uh the the uh model the object the reply text the usage and normally you know how that you know how it streams when you do when you go to a chat.openai.com it actually gives you responses in sort of you know one line at a time as though as a typewriter that apparently is part of the API so if you want you can get a stream you know and you can actually just stream it as well um or you can ask API the auto configuration to just combine everything I guess so there's that and then we'll just uh subscribe so system out print line very good okay so pretty straightforward let's just try it very simple example I'll leave it to your imagination to see how this works but right now okay here we go run now again I I tried this with a free account before and I got a 429 too many requests I kept on getting denied so bear that in mind you need to put a credit card in that is the big part okay okay already pretty good right like um so subject invitation to the production party at 1700 dear Josh I hope this email finds you in good health and High Spirits no glorified and yet it does this it's amazing um as you're an esteemed member of our community a presence at the event would be greatly appreciated blah blah blah you know invited to we we have also extended this invite to your yeah your email address Josh and blah blah please let us know if you'll be able to attend and kindly RSVP to this email okay so it's yeah it's great right um uh yeah so that's that's pretty great but maybe I want to integrate uh with a function maybe I want to have some sort of connection to my code as opposed to just this freeform nebulous bit of text and chat DBT is pretty good if you give it a little bit of a if you give it some ideas um about how to create a thing that has the shape that fits into a method of your choice in your local code base okay so let's rewrite this now with a chat pbd function and the auto configuration that we're using um it even has a really convenient little uh component model that you can use to define and declare and register these functions unfortunately at the moment it doesn't it doesn't support package private so I'm going to do a little you know you could make the class public that's easy fix but you know me I'm kind of allergic to public classes for no reason so I'll do it inside public static class uh my chat PPT functions okay and uh you know we'll we're going to create a function that implements uh and I don't quite understand this part yet either I think again there might be work that we could do I can already see a few things I want to submit uh to improve this library but it's just so useful already that I think we can no just proceed so this interface doesn't there's no it's just a marker it's like serializable but it doesn't even need to be if you look at the implementation it would it's I think it doesn't need to be there so what we're going to do is we're going to have a TPT function and I'm going to name it send email and the value is uh send email to Receiver right so I'm going to create a arbitrary function send email I'm going to take a type called a send email uh you know let's say my email chat DBT function I'm gonna have a a public record send email request it'll take a list of uh recipients and a subject and a some content oops content come on there we are good all right oh good we've got this uh we've got this payload we want to send this function we want to use this function uh to when given a request to do something interesting with it right and uh and so let's just I know you know the example that he has is plenty good we'll just log things out so actually your request we can just you can just log out the request can't we so request dot uh you know to string very good and you know I can just print out or return email sent to uh spring.join this and then request dot recipients okay good okay so there's our custom function we need to tell gbt how to map this Json payload to something that's interesting so we'll use some parameters here so this would be uh recipients we have our parameter for subject of email and we have another parameter yet for the content of email okay and we can just make overly explicit very very explicit uh you can he has and I don't know if this makes any difference so we'll just do as he's doing we're gonna use uh you know some type some null ability annotations here okay so there we go there's our basic function chat gbts we'll take a when we send an email we'll have it use this with the parameters after it's done some analysis uh to then actually make the call so here we're going to say commented this out okay chat DBT dot chat and then here we'll say uh completion request that functions okay and the functions same thing as before we'll use uh the uh the prompt like this message right and uh we're gonna provide a list of function names right to to invoke so send email and uh what is this functions there we go that one okay so then we'll get that map the completion response get reply combine text dot subscribe all right how about that good so okay so we're just so this is the name of the function you can see it's so named here as well uh we've given it this chat gbt function annotation this is from the uh starter you know org Maven search Chat gbt model function so we'll go ahead and restart this now okay look at that so we have [Music] recipients you know it it correctly parameterized it says okay the recipients are these two people the subject is invitation to con to production party content equals dear Josh best regards your name and then of course we print out send email sent to the array that we then joined uh via strings now friends okay I'm I mean that's so at this point you've got the basic demo um I want to show you one more thing uh and this is something I expect I'll just send a pull request for and it'll no longer be a problem for you but um what if you want to run this in brow VM well you'll need to register a few types and uh as it happened I already I already figured out which types those are so register for blah blah blah there we go okay activity message function call because remember we're going to be sending requests over the wire so some materialization is required just register some of these types for serialization uh and then same thing for this uh this record here we need to register that as well so we'll say class okay and uh and then we can just compile so we say cradle W native compile okay uh and then let's see as to uh well so right now he's supporting chat good question which library is he supporting right now it's chat gbt35 turbo and you can check that out um if you um here where's that code while it's compiling functions you can see it's just hard coding in the request chat gpt35 turbo 0613 I reckon you could probably just use gpt4 and so on uh test cognizer uh good question um so you're new to the chat gbt AI stuff yeah yeah I would you know the big picture stuff right it's a it's a a very very very smart Auto completion that over a corpus of Works uh that includes billions of reference points is able to show you kind of what would fit naturally after a particular token and it can do that for whole paragraphs you know and so it can produce stuff that is statistically going to be correct because it has been correct before um and it's just really smart you can get more you can get access to more models yes well I paid for the chat dvd4 I have a Plus account there as well so I know that was kind of a paywall at one point and I went for that um but yeah so anyways Chad TPT I'm sure you must have seen that part this is just a Java he's uh this the maintainer of this Amazing Project is writing some code so that we can then talk to the rest API and the code to do that by the way again it's just a nice feature in Spring boot 3. is based on declarative interface clients so you just specify an interface HTTP here's the interface it's this is the hard part right here right that and providing a web client that has a header uh where you have a default header of type authorization Bearer and then the open API key so that's most of the code here is this is just the extra wiring land functions and all that um is extra right [Music] uh okay so these are this is all spring stuff right very very convenient very powerful and I compiled it to a native application so build native Native compile AI let's see if it does the thing okay there you go um so there's two requests right I made the same request twice did I keep them both I think I did no I commented that one so it's just one request good so there you go my friends um spring Cloud session and security it would be really helpful Alex how Alex are you are you reading my slack messages are you reading them Alex I don't know how you're reading my slack it's it's wrong but I but but you're but you're right I am uh I am interested in doing that and um and what I mean by that is uh github.com this week in I just bid so do you remember a few weeks ago I I had a great discussion with um Steve reisenberg around how to build uh oauth to do an oauth authentication server and a resource server and a client and all that um uh and well basically that set me down a little rabbit hole and it's one of the reasons I've been so uh slow at a post is just because I've been reworking stuff so I actually now have a production worthy and I'm gonna do a video on that as well production worthy instance of the authorization server with persistence and you know long-lived tokens and uh all that stuff and dynamic clients and you know all that stuff I have a production authorization server and then I then I'm using a Gateway with spring Cloud gateway to do oidc um you know incept uh and then that in turn is using spring session by the way both the resource server and the uh off server using spring session to store their state again so you get persistent sessions uh and uh and it's all Spring Security of course so you could I don't know how you know my headspace but trust me that's what we're going to look at next in fact that was one of the things I wanted I'm not done with the production authorization server there's just a few more things but you know if you want to follow along uh offline you can see that here gosh long authorization API here's the code right the uh this is the more real um authorization server API okay so back to the chat gbt friends that's basically it uh Simon you you say a good point you make a good point which is you prefer if he had called it open AI starter and not Chad TPT starter and too few people realize chat DPT is just one of the open a models it's true very true um but there you go that's that we have a we have an application that talks to chat gbt runs native takes oh by the way look at that I mean the application itself started up in 43 milliseconds so you know 1 20th of a second uh and uh it's using chat DBT so like I mean you imagine if we had used spring Cloud function instead of this it would be a little bit faster and great for serverless you could do all sorts of interesting things now and of course this application takes whatever tens of megabytes of ram instead of hundreds or you know worse okay I think that's it for now um yeah Alex uh stop stop reading my mind stop it get out of my mind uh we will be talking about that stuff soon I try just it's very much in my uh in my headspace at the moment uh this code as always is on my GitHub repository so if you go to github.com software go ahead and get that key uh nope coffee software show don't know who that is probably fine uh there you go coffee software show chat TBT and spring boot three it kind of Rhymes it's actually three that one but whatever you know um we'll do more I've just been this last week was absolutely nutty and I've been so busy with this uh I told you a couple weeks ago a few weeks ago I I uh I found out I had to move every app workload from one cluster to another and uh it it would offered me a rare opportunity to move everything and figure out why it wouldn't run in the new cluster a new shiny uh kubernetes cluster and it was a real pain real hemorrhoid inducing experience but but uh you know I got to rewrite some View apps and update some spring apps to go to go from like 2.1 to 3.1 you know a whole generation version change and and I'm now integrating oauth and oledc login across the different apps because they've got like bespoke login approaches across the number of different services that are run to maintain my content so all that stuff uh yeah it's uh it's been fun and then and this this oauth tangent wow that authorization server is neat you know it's really good um it's been years I've been waiting for something like that we did that video with Steve Eisenberg if you haven't seen that video friends if you haven't seen that video uh like oh it was so good it was so good this one this just changed my mind it just blew my mind right really going full auth with a new spring authorization server in which we looked at uh authorization server resource server oidc client and even a strategy for like building a uh like if you have an HTML5 client you can use the gateway to proxy to that client and also proxy to your API from the same Gateway so now you can avoid like having to dance around jot tokens in the client JavaScript code they just talk to you know their one API forward slash you know whatever uh and they get they get Jason back right the the browser's already authenticated so yeah this this is this is one of my all-time favorite videos that I've ever been a part of seriously Steve crushed It Go watch this uh it's just it was very hard very hard to like top it um uh and you know it's okay thank you everybody I hope you got something out of this if you uh and I I think I'll set it I'll set up a Discord that'll be fun um I'll start putting that in the um in the show notes and stuff maybe I can put it in the wallpaper uh behind the scenes when I do the live streams and stuff you know um okay and and also give that project give uh chat gbt spring boot starter Linux China chat TVG spring booster give that project a uh a uh thumbs up because it's just it's interesting and it's nice and it deserves our appreciation all right my friends wish me luck I'll see you on the other side I'll be in Australia in in a day or so happy Father's Day to all of you like I said who celebrate bye
Info
Channel: Coffee + Software
Views: 3,640
Rating: undefined out of 5
Keywords:
Id: XnbvFqmMmfU
Channel Id: undefined
Length: 36min 0sec (2160 seconds)
Published: Sun Jun 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.