Let’s Build ChatGPT 2.0 with React JS and OpenAI on your PC!

ChatGPT clone using the latest React JS and simple HTML and CSS. Built on top of Node JavaScript and Express, this will let you run your own instance of ChatGPT on your own PC!

Chat GPT Starter Kit:

OpenAI Template:

This video will cover how to code from scratch a Chat GPT interface for the frontend and a backend using Open AI latest package! It is a beginner-friendly tutorial for using the OpenAI API and working with models that are provided like DaVinci, ada, etc. You can build your own chatbot interface and this guide is also intended to help build the foundations to work with prompts and outputs from the chatgpt models.

00:00 – Introduction
00:12 – Coding ChatGPT preview
00:34 – OpenAI Template Starter Kit
00:57 – ChatGPT Starter Kit
01:22 – Initialising Project
02:47 – Starting Frontend with Create React App
03:03 – Designing ChatGPT Side menu
05:51 – Styling ChatGPT Side menu
12:34 – Designing Prompt Input
13:42 – Styling Chat GPT Input
18:52 – Coding Chatbot Interface
20:31 – Styling the Chat message interface
28:15 – Adding OpenAI SVG Logo
28:53 – Starting Backend with Express
29:54 – Preparing OpenAI Configuration and API Key
32:48 – Creating Express API Routes
34:03 – React Frontend handle Submit function
37:11 – Cleaning up the React Components
41:54 – Creating Frontend API Request using Fetch
47:17 – Frontend Backend integration
53:02 – Adding Features to Select OpenAI Models
01:02:02 – Conclusion

#chatgpt #ai #openai

I’m going to code a better version of Chat GPT in this video chatgpt sometimes Doesn’t answer the questions you want or You want to build your own features or Have a custom version of the AI first We’ll rebuild the front end with the Same general design along with our Chatting interface so you can have your Own personalized chat GPT running at Your own discretion you’ll also be able To create new chats as well as access All the models inside of openai this Allows you to do more refine prompts Such as if you want a coding prompt Selecting a coding model will produce Much better results than what chat GPT Would normally do I don’t have any Sponsors so I’m going to sponsor myself Again in this video I’ve put together an Open AI starter kit a template to build Your own ideas on it’s built on top of The Merin stack and it has everything Ready to go for you to start interacting With openai building your own prompts And training the AI to essentially have Outputs that you want this should save You hundreds of hours and I’ve listed it On gumroad for 99 on top of that I’m Thinking that I’ll also introduce a Brand new template this will be a Chad GPT starter kit a template where you can Customize it and configure it any way You want it’ll only take about 5 or 10 Minutes to set up and I’ve listed it on

Gumroad if you want to try it out and Support the channel it’ll be very Similar to what we’re doing in the video Right now it’ll be just more expansive Saving you the time and effort from Building it yourself so without further Ado let’s begin this video let me Begin By creating the front end for the Website I’m going to start with a visual Studio code I’ve browsed into a folder Here that I’ve created called chatgpt Dash enhanced and I’m going to check my Node version so I’m going to type in Node-v I’m running version 18.12.1 I’m also going to check my npm Version which is 8.19.2 I’m going to install create or React to app I’m going to do this by Calling npx create react app and then I’m going to create an app here called Enhance chat GPT now if we browse into The full destruct are here we’ll see That we’ve got our folder here called Enhance GPT I want to change this to Something more specific so I’m going to Call this client since this is where our Front end will exist I’m going to also Change the name here to something more Like chat gpt-client and will also Create one later for the server we can Actually initialize that already so here In console what I’m going to do to Initialize that is simply type in Npm in it

Here we’ll include chat GPT server and Here is where we’ll have our server Later on so we’ve got our server here in The root folder and we’ve got a client Which is with create react app inside a Folder called client next we’re going to CD into the client folder and run Npmstat which will kick off the react Server we can now customize jumping back Into vs code we can expand out SRC and We can head to app.js and start Configuring the application look and Style we’ll need a side menu and a main Section so let’s start off with that This side menu here if we inspect it is Around 244 pixels wide so we have a General idea of how to do that we can do An S side I believe it is it’s an HTML Attribute and then over here we can do a Section and for the aside I’m going to Do a class name here and for the class Name I’m going to call this side menu Hit save on that and we’ve got an App.css file here so I’m going to browse Into app.css I’m going to pass in this Class name for side menu we’ll select The width here to be 240 pixels and I Think that should be okay the other Thing here is we’ve got an app file well An app class sorry and I think this Might be in the app CSS file so here I’m Going to do a display of a flex for it Hit save I’m also going to move this Side menu into the app CSS file so that

It’s all in one place and here I’m going To do a border of one pixel Solid white so we can see it let’s head Back to our react interface and we’ve Got our well side menu and we’ve got our Main menu here though it’s a little bit Large but we can work on that so what I’m going to do is make sure that we’re Not fully zoomed in now we’re not so it Seems more reasonable as to its sizing The other thing here is that this Section here has an expanded app all the Way so what we can do here is for the Section that we have here I’m going to Move the header and all of this code I’m Going to well remove it all together This section I’m going to give a Class A Name of I suppose a chat box We’re going to copy that class and paste It into here we’re going to give it a Flex of one and we’re also going to give It a border of one pixel so little white So we should be able to see some Separation but we’ve lost the background Colors here so I’m going to grab the Background color here we had earlier for The app header and I’m going to put this In the app itself so it can now be Visible the text though is still black So I’m gonna jump back into vs code I’m Going to select the color of the text to Be white Finally I sort of want this to utilize The whole Space here inside of our area

So we could do this in a couple of ways But I’m going to be lazy and position This to be absolute with a top of zero Bottom of zero right of zero and left of Zero if we hit save on that we can see That it’s utilizing the entire space now Let’s take a closer look at exactly what Colors are currently being used so if we Do a check on that we should be able to Use the little cursor here go to Hexadecimal and grab this color of 202123 I think it is let’s jump back in Here and for the aside menu let’s do the Background color here to have that Hexadecimal color If we hit save on that it should be a Darker version for us now which it is And then on the right hand side we have This vs code looking color so if I was Just to try and figure out what that is I can just do that little trick that I Did before where I can select the color Here palette and it’s a three four color So I’m going to also apply that here for The chat box we’ll do background color And we can utilize the same color for That so we’re getting closer there is a Slight larger width to this side menu Which I’m not sure what that might be it Might be actually the margins Coral I Know so something I normally like to do When I’m building out an interface is to Do a normalize so I’m just going to type In normalize CSS head over to the very

First example that we get we can install This and probably utilize it immediately But this is the syntax that we you use For that I’m going to jump back into vs Code Type in Normal CSS Paste that in and then over here in App.css I’m going to import that Normal.css and it should make sure that Things like border box and other stuff Like that just work properly then for This side menu I’m also going to expand Out its width a little bit more so let’s Head back here to side menu let’s do it With the two maybe 260 pixels and Refresh that to make sure that it’s more Or less the same and that looks much Closer Finally I’m going to add some padding to It something like a 10 pixel should do And I can remove the white borders now Because we can see some separation Between the two items With the padding I can see that it’s Actually a little bit too large now so Let me remove it back to 240 which Really shouldn’t happen if I’m using Border box but maybe it isn’t applied Properly so let me double check that I’ll jump back into our react Application here let’s go to app.css Normal.css is located here Is it doing border box Content box I believe that is correct

But maybe it’s not uh let’s go to border Box CSS normalize Uh how to do border box in this we have This just over here so I’m going to copy This into the normalized script and this Just means that essentially if we’re Doing anything like adding padding so Say I add 40 padding to it it’s not Going to suddenly be larger now it’s Still the same size this does mean that I do have to make it a little bit bigger Once more but I believe that should fix That problem that we’re having and the Size is now correct Moving on we can close most of this out And we can begin stylizing the left hand Side menu as well as the right hand side Chat interface So for the left hand side menu I’m going To add some features and content in There but mainly we just need this first Button here to start a new chat so That’s the first thing I’m going to do Let’s remove this H1 block and in here I’m going to pass in I think just a Regular div and I’ll call this of the Same thing which is a new chat Let’s jump in here we’ll call it new Chat uh we’ll put a class in here called I suppose side menu Button And hit save on that and generally Speaking I have an idea of what it looks Like in terms of the CSS so we can pass

It in here we’ll do something like Padding 15 pixels color is already set So we don’t need to do that border one Pixel solid white and Border radius was About 5 pixels let’s have a look so that Looks about the same it almost has a Little bit too much padding maybe 12 Pixels but otherwise it also needs to Have the little plus there I think that Might be like a font awesome icon I Can’t really tell it is an SVG but font Awesome often does this quite well I Don’t know if I want to go to the extent Of importing font awesome icons so I’ll Just leave it at that for the time being But I will want to do the text align to Be on the left hand side And I’ll probably want to reduce that Padding to 12 pixels so now we have this New chat working quite well Finally I’m gonna jump in here and I’m Gonna add in well I guess an icon but I’ll have the icon inside of a span and This span will just have a plus sign So what I’m gonna do is I’m gonna do Some styling for that span will do side Menu button spam Not spam span And here I’ll do something like padding Left can be six pixels padding a right Can be maybe 12 pixels and if we refresh That we’ve got our little plus sign next To our near chat there is a hover effect That’s happening where the background

Color is changing so we should probably Apply that so we should do an on Hover Effect here uh I’m gonna grab the save Menu we’ll do a hover we’ll do Background color can be RGB two five Five two five five two five five which Is the color white we have 0.1 being 10 Opacity Hit save on that and now when we hover Over it we can see that it has that Animation we could even go a step Further and do a transition ease 0.25 Seconds on all styling uh and then now We’ve got that little bit of a Transition when we hover over it similar To what we have over here That’s our first button the only other Thing here is that the text might seem a Little bit smaller or larger but I’m not Going to go to that level of detail I Think that’s enough to get us started Now let’s actually create this chat Interface that we have over here on the Right side let’s begin with the most Important thing which is the little Input at the very bottom of the screen Here as well as this text which maybe we Don’t really need but I think this input Should be easy enough to make the first Thing we can do is grab the color that It’s using which is just this lighter Shade of grade gray it also has a bit of A box Shadow and is quite large and has A lot of padding do that I’m going to

Pass in a new class here I’m going to Call this div class name we’ll call this The chat input holder And for this I’m going to also have Probably maybe an input or a text area Let’s do a text area and I suppose this Can be called the chat input text area Uh Text area And that should be enough for the basic Design but as you can see it’s sitting Here at the very top of our screen it’s Not really how we want it we want it to Be at the very bottom uh sort of Centered so what I’m going to do is jump Into our styling here we’re going to Grab this class chat input holder and First of all we’re going to update the Color that we have over here so for this Color actually maybe we can do that in The text input so let’s actually grab The chat input text area And also put this class in over here now I’ve forgotten what color that was Because I removed my copy pasta and let Me grab that again it’s a 404 color so I’ve definitely found that and let’s go Background Color and we’ll paste that in with a hex Value let’s make sure it’s not a Changing opacity so it’s just got the Cursor there so if we refresh and now It’s visible but it still has a border And it’s got no padding and stuff like

That so let’s do width 100 we’ll do Border say five pixels again uh we’ll do Border color none And I think that I’m sorry border radius here five pixels And Border none So that way we don’t even have to worry About the color hit save on that so now We can see it’s located over here it has A bit of an outline when we select it And it probably also needs a bit of a Margin so I’ll do margin to be 12 pixels And I’m also going to do outline to be None finally we have the box Shadow so Let’s do box shadow Here I want it to be subtle Um But let’s do something like maybe eight Pixels Oh sorry zero Eight pixels 4 pixels zero rgba we’ll do Black uh at 0.5 opacity So hit Refresh on that that still might Be a little bit heavy and we’ve got a Bit of an overflow happening because of The margin I applied so instead I’m Going to apply that to its parent I’m Going to do 12 pixels here and this over Here I’m going to set it to be just 0 Pixels 0 pixels eight I always get box Shadow confused I think It has to be the first two values are Zero and the last one yep so that looks Like a much better box shadow

Uh there’s no padding inside the text Box right now so I’m going to add some Padding inside of it let’s do padding 12 Pixels uh and check it now so now it’s Getting closer we also need to make sure That its color is white so let’s have a Look at it now it’s much closer And the font is a bit larger in this Example so I’m going to do font size 1.25 em so that should make it much Larger in comparison to what we had here And finally it should be in the single Line I also wanted to only have one row So I’m going to do rows is equal to one Let’s refresh now it’s starting to take Shape we don’t have a button at the very End there but I can figure that part out A little bit later for the time being I Just want to have it pointed down here At the very bottom and for it to have Some more padding on the left and right Hand side so I’m gonna jump back in to Vs code here to our styling and for the Holder I’m going to do a position of Absolute for this position I’m going to Put it to the bottom we’re going to do Left is a zero a right is zero and then For the size maybe ninety percent will Work a little bit better so here it is Exactly at the bottom but because we’ve Got this uh I suppose not being defined Inside of our other item we need to add A relative to our other item here I Think it was in the chat box

Where was that it’s a chat box here that Needs a position of relative And that way the actual absolute Position here is now at the bottom of Our text box It probably needs a little bit less box Shadow and some more padding from the Bottom too So what I’m going to do here is head Over to this chat chat box holder put 24 Pixels for that and have the shadow now We’re getting much closer to what we Normally have in chat gbt’s chat Interface they don’t have a placeholders Here so I’m gonna also remove the Placeholder so that it looks more Closely resembling well the chat gbt Version and I think we’re pretty good There I don’t think I need to change That much more than what it is already I’m not going to put in this whole chat GPT Preview or anything we could write our Own but I’m pretty happy with what we Have We can now build out this main section Here I don’t know how useful this could Be so in a way I think I’ll just skip That whole part and we can move into Creating the chat interface For chat GPT now which will be the fun Part let me create a new div up here and For this div I’m going to give it a Class name and for this class name I’m

Going to call this the chat log which is A pretty good one in here I’m going to Pass in a chat message and this chat Message will be I suppose having a Couple of things it’s got the message Itself and a small little Avatar of me So I think that should be easy enough to Do if we have a look there is also a Slight different color here when open AI Sends a message back but we can get to That shortly So for that I’m just going to do another Div here I’m going to pass this class Name here as Avatar We can add an image in there later on But for the time being I’ll leave that Empty then in here I’m going to pass in Another one called message and I’ll Close that off And I think we can close off the chat Log div over here so I’ve got a message This message has an avatar as well as a Message generally so chat message Avatar Message so this is me here that I’ll put In and this can be something like hello World let’s hit save on that to see what It looks like for us here it’s all text Centered and it doesn’t look very good Right now so let’s start customizing the CSS I’m gonna jump here into chat log and I’m going to start adding all these Classes in so we’ve got the chat log Class we’ve got the chat message class

We also have the Avatar class over here And we finally have the message class And normally you could Nest this if You’re using a SAS or less but for the Timing I’m just doing a simple design Over here Let’s do a padding with a scroll Happening here and let’s do a Actually no leave this as is we’ll just Add in the padding then this one here Can also have some more padding 12 Pixels should be enough This can be a border now this can be a Background Of a white here for the Avatar border Radius can be say 50 Width can be 40 pixels I think that’s a Good amount and height can also be 40 Pixels And finally for the message I’ll leave That empty for all of this I want the Text area oh sorry text align here to be Left So let’s hit save on that so that looks A little bit better we also need to have A display Of flex here for the text message I’m Thinking to add in a little bit more Padding on the left so maybe something Like 40 pixels uh and on the right 40 Pixels Let’s refresh here uh and I think did I Not add the display Flex properly I have To add it to message as well

Uh so let’s refresh that’s looking a Little bit better I haven’t added the Padding in properly so let me do left 40 pixels padding right 40 pixels and what was a GitHub co-pilot Doing to me before by not providing me The right design for that So that looks better I will also add Some padding here to the text message Itself And finally I’ll remove the me from here We’ll add in an avatar later but we’ve Got a bit more of an interface happening Now Now there is a few ways we could do this This is one way of all the padding the Other way we could do this is by having Just a little bit of padding something Like say 24 pixels and then doing a Max Width here and having that something Like 480 pixels margin left is Otto And then margin right is Otto if we save That it should be sent it which it is Now that looks much better but this is Because it’s happening on the entire div Element here on that chat message so if We go console here elements we can see The chat message happening we’ve got the Avatar and the message but if we were to Add a background color like we have here It wouldn’t look good so we actually Have to Nest this so what I’m going to Do is I’m going to call this the uh chat Message center

Close enough and Nest this all inside of That so here I’m going to do chat Message oh I’ve gone one layer too deep Let’s actually do it up here div class Name equals chat Message center Great And paste that in So we’ve got our Avatar in hello world If we jump back in now it essentially Should work the same way we’ll need to Update the display Flex to exist inside Of that instead of inside of the chat Message and even the padding so let’s Actually move all of that below here Hit save on that refresh and now it Exists here if for example we wanted it To be a lighter color say background Color let’s copy paste it here in the Center message I’ve lost it Where did it go Here it is Hit save on that we can see it’s only Applying just over here like that so if We actually now move it one element up To the parent it’s essentially taking Shape and applying to the whole side so Now we could even remove the padding That we’re having on the parent above That which is just over here the chat Log hit save on that if we go back we Can see now it’s utilizing the entire Space which is much better at least for

When we get to the chat gbt interfaces So the other thing I’m going to do now Here is utilize the same message design But I’m going to add in one more class Here called chat GPT And I’m going to copy paste this and Remove that class now and then this guy Here will be i m n a i hit save on that So now we should have two messages Both of them have well that background Color But they shouldn’t because we’re going To update the CSS here to only add this Background color if for example we have The class chat GPT on here Hit save on that refresh and we’re Getting closer to that sort of interface Look there is more width Happening Here I think it’s like 640 Maybe So let’s update that to 640 . Hit save on that refresh And yeah that looks much better hello World Great uh so with that done there is a Slight different background color on This element here so if we go color Red Grab this color value that we have here It’s a 444 color and I’m going to apply It to be the color that we want to use For charge ept’s replies because we want It to be more or less the same so now We’re getting closer uh we’ve got this

Chat gbt image here this is actually Like an SVG image inside of a green icon So I’m going to copy that over too so For the SVG I could probably just have It here as an SVG I think This is it but because this is a react Code that might not work but at least For this chat GPT interface for Avatar So where is Avatar Here it is I’m gonna Pass in one more value here uh chat GPT We’re gonna grab that nice green color That we’re utilizing for the chat GPT Interface That if we did an inspect on it let’s See what color it is color red Select it just over here that’s a nice Green color And let’s apply that for ourselves here So I’m going to add the class here Chat GPT we’ll head back and now we’ve Got a white and a green circle we Probably need to add some Well Avatars into there next This here is using the open AI logo so There’s a little playground here where You can simply copy paste an SVG and out Comes a react component so I’m gonna Copy paste that and paste it straight Into here hit save on that and if we go Back to our design here it has not Defined prop what’s that that’s missing

Something props so we can remove that And we’ve got a nice little chat GPT Interface Circle here I personally Prefer a circle for an avatar then a Square I think that looks better with This done I think we can move on to the Back end now and building out the back End to essentially interact with open Ai’s our latest API and start plugging Messages in and getting responses right Back so let me head over here to the Main folder and create a new file called Index.js we’re going to include a few Things here but the main ones will start Off with Express because that’s how We’re going to be calling in well Essentially API requests so let me see The backup folder here I want to do npm Install Express Course and body parser I’m I think I’ll Also get Morgan I think that should kick us off and open AI let’s hit save on that and that’ll Start installing while that’s happening In the background let’s log into the Open AI website then we want to head Over to our account assuming you have an Account if you don’t just create one I’m Gonna head over to Adrian and view API Keys and I’m going to create a new API Key which I’m going to use for this Project and then delete later Here I’m going to paste it into my vs Code instance which is just over here

And I’m going to set that a little bit Later Next up I want to jump into open ai’s Documentation and head over to the API We’re going to head over to introduction And here we’re going to install openai Which we just did And we’re going to start adding it to Our node.js project by copying this code Just over here So this code essentially is doing a few Things it’s requiring the configuration From openai it’s setting the Configuration with the organization and Here where we have the API key I’m going To paste it in you’d want to do this With an environmental key but for the Time being this is just for testing Purposes I’ll remove this list engine’s Response we can have a look at this Later but I’ll comment it out for the Time being and hit save on that Then we’re going to prep up a completion And now we’re going to use a node.js Here with DaVinci and I’m just going to Copy this text over here to complete That and paste it here in below so What’s happening here is uh we’re Essentially resetting open AI so we Don’t need to reset that configuration Since we’ve already done that and we can Get rid of most of this other stuff that We have here the only difference here is It’s using a require instead of an

Import so I’m actually going to use the Require because I’m not sure if I’ve set Imports just yet on this So let’s hit save on that we can close This off and we have most of our Configuration now done Now for creating the API here on the Back end Let’s test this out I’m gonna Do an async function here called call Api and I’m going to just paste this Piece of code in uh what we’re doing Here is an await so what we can now do Is a console log and we want to console Log out well the data that comes back I Think then finally we just need to call This function as the last thing that we Do here before we test everything is Working so let me do a node index call And here we’re calling indexed we’ve Called say this is a test and then open AI has come back this is indeed a test Which means that we’re talking to the API here from openai all right with that Done we can now create an API so what I’m going to do is say create a simple Express API that calls the function so We’re going to require Express we’re Going to create the app we’re going to To set a port then we’re going to do an App get send hello world we’re going to Do a listen and we’re going to do a Console log which I don’t think it is So what’s happening here is well GitHub Copilot hasn’t done exactly what I

Wanted to do but that’s okay so I’m Going to move this import for Express Here at the very top Then I’m going to move this function Here get rid of the function And just paste it into the get request I’m going to change the get request to a Post request here and I’m also going to Make sure that it’s async Then I’m going to have a response that Will be a Json response and I suppose The data that comes back will be the Response data from open AI I think that is pretty much it let’s hit Save on that and do in node index we’re Now listening to app listen here on this Port which it should be working and we Should now allow the front end to query This data and pull this in so it’s time To jump back into react to create an API Layer to start off with we’ll change the Port here to 3080 for the server because Port 3000 is usually where we use a React then here over react I’m gonna Turn this into an input just to make Submitting a little bit easier I’m going To add a form to be wrapped around it Which will have an on submit and the on Submit can handle submit Let’s save that and scroll up here and Make a function here Called oh On submit or handle submit sorry and We’ll make this as an async function

So this will e prevent default How do I do the E I think we just pass In an e over here And then we’ll do e Dot Prevent default which I’m pretty sure is How we do that so that’ll just prevent The default behavior of it I suppose Doing a um Submit when you do a submit it usually Does a page reload so let’s refresh that Hit enter open up the debugging tools And here we have a submit in console Which is perfect that’s what we want Uh with that done we want to have some State so let’s actually import a set State And that should be just import Set state from react and then here we’re Gonna add state for input and chat log And GitHub copilot should just create That for us which it has then for the Input I’m gonna scroll down here to the Input I’m going to set the value here to Be the input on change Can be a function That basically sets the state so of Input to equal input but we’re going to Call set input to equal input And it’s not actually going to equal Input it’s going to equal e dot Target Dot value So that way we’ve got our input here Being set now we’ve just got our chat Log

So what I want to happen here is when we Do do a submission we want the input to Be set to nothing So we’ll do set input here to be nothing We also want to grab the input and add It to a chat log so what I’m going to do Is I’m going to do set chat log to equal Chat log plus input but For that input I actually want this to Have uh the I suppose user to be Me Fair enough and then the message to have That chat log in here well the message That we’re sending So we’ll reset that and I think that Should be good so let’s hit save on that Then for the chat log here I’m gonna Essentially turn this into a component I Think let’s see how we would do that so Here we’ve got a chat message we’re Going to call this a chat message as a Component And then we’ll do message can equal Message which will pass to it very Shortly Here at the bottom I’m going to do a Const message or chat message I can pass in message it’ll have a Return I’m going to paste this guy back In here and close this all off Uh then message Dot message can be that And then message dot user could be later In here but I suppose I’m just gonna Apply it in here as a check so what I’m

Going to do is pass an avatar and then If message dot user is equal to Gbt then We also pass in chat GPT into the Avatar We could probably do something similar Here for the message itself because if We have a What was it If we have that background color Happening then we can pass in this class Gbt which makes it have that background Color Beautiful so with that done I think That’s one example of it We are missing this one here the SVG That we had earlier So I’m going to close that off and put It in here As a check so if message dot user is Equal to GPT And we pass in this SVG wonderful Hit save on that we still have a bit of A problem set input is equal to input is Coming up with a compile error Shouldn’t be left hand assignment So let’s scroll down here and have a Look what’s happening So here is a set input but this is a Value that is here set input so it Should just Work One change set input Ah Yeah I think because we’re putting input

In there let’s close that off Hit save that should fix it up So message is not defined and E is not Defined interesting interesting so Handle submit It’s fine E dot prevent default e is here Should work Um and what was the other message here That we had a message is not defined on Line 28. Well yeah of course it’s not I haven’t Done that yet Uh okay okay so here I’m gonna do I Suppose a few things first I’ll create a Draft message User can be GPT And message can be how can I help you Today question mark So now I’ve got message I’m pretty sure Because we also need a two Loop through That so here where we have our first Message Chat message we’re gonna do this oh we Don’t need to do this we just do chat Log we Loop through it and we close that Off We probably also need a key so I’m going To do the key to be the index for the Time being We’ll refresh that so now we only have The e as not defined on line 50. uh so Where’s line 50.

Ah yeah e has to be in here okay I think That should cover it so we’ve got our First message how can we help you today We can remove the rest of this last chat Message that we had And we could even set up an another Example here just to make sure that These messages are showing up properly Here it’s going to be me I wanted to use chat GPD today Hit save and we’ve got our first Functioning message happening from our Array inside of react which is great now We just populate this array with the API So what I’m going to do is a fetch Request Two To the API Um combining The Chat log array of messages and sending It as a message To localhost 3000 as a post So here we’re going to do an await fetch As a post With the headers Content type Json we’re going to Stringify that We’re going to pass in our chat log Looping through our messages And that is pretty much it then we’re Going to go response back and we’ll Console log that response for the time Being at least

Uh now this all looks correct Uh this stuff here is the main thing the Message that we’re sending over to the API is what I really want to test out so I’m going to save that And then over here on the API we should Get a const And this will be the message from the Body I’m actually going to sort of Comment everything else out here And for the data I’m just gonna pass Back the message that we currently get Just as a test and this console log here I actually want to console out The message So let’s do that Uh we’re gonna open up the console here Go to react go Oh actually we need to reboot the server First of all So let’s jump back into the server which I don’t know if is even running let’s do Node Index this actually has to Be coming up alright so it’s listening On Port 3080. For the API we didn’t add a port 80 here 3080 so let’s hit save on that We’ll go testing here enter we do get Our new message here instead of chat GPT Or the one that we’re building anyway But if we go back here uh in our client We’re not getting a console log Happening So let’s see why that is

So we definitely did a app post request But if we go here we can see that cores Is probably not enabled so I need to Enable cores which allows us to send Messages to and from different ports and Domains So to do that I’m just going to ask uh Chat can you please add cores to express And we’re just gonna do that over here Is that adding it and body parser So I’m gonna just paste this in add a Body parser and pores to express So here’s body parser we’re going to Import it we’re going to import cores And then here under app We’re going to add body parser Json and Coors and that should pretty much cover That which is really cool because uh GitHub co-pilot you can see the benefit Of how it works here where it just does A lot of the things you’re asking for Where you could normally type it out if You know what you’re doing So let’s do a test hit enter this time In console we’ve got back a message Which is the data how can I help you Today Which is actually the combination of our Messages and here we have that all in One big message which is perfect it’s What we want So this means our messages are getting Over to the API we’ve created And now we can start using them so here

We have chat GPT we’ve got the prompt That we created but I’m going to pass in Our message and this is the message that We want here for Max tokens I’m going to Do something like 100 and temperature Can be 0.5 We’re going to get a response back here And this will be the text response and I’m going to paste this straight into The data but rather than calling this Data I’m going to call this message and Hit save on that Here on the app now we’re going to get a Response that’ll be called Data and Data.message will be our message so Realistically all we have to do now is Add it to our chat log so let’s go down Here to our chat log Let’s do a set chat log we’re going to Set it to be the chat log but the user Now will be GPT the message will be the Data.message that we’ll get back and That’s it I believe now it should just Be working so let me restart the server Here I’m just restarting it Manually node index.js and I will Refresh here uh what can you do for me Today hit enter And we should get a response back chat GPT is an AI powered chatbot Wow that is working now with that done Let’s actually create the clear button So clear uh chats I suppose or chat logs We can do a function clear

Chat and then in here we’ll do set state Of chat log to be well nothing and then Let’s jump down here to the side menu That we have I think it’s just where did We put the side menu here it is we’ll do An on click and we’ll just pass in that Function so now if we go new chat it Empties everything out which is perfect Then on top of that we want to do a Couple of things here for these messages We’re doing quite a few set States Um so I’m going to do a weight on each One of them simply because if you do Them out of order it might actually have Some complications I’ve noticed so I’m Just gonna save that so now we’re gonna Refresh and then say This is a test reply success if it Worked hit enter Let’s see if chat GPD comes back with a Success So it has come back with some weird Stuff uh let’s actually have a look at What’s happening on the back end here so If we go to the console here it actually Does say how can I help you today I want Chat GPT today index we have no more Console logs so what I’m thinking is That something has gone Haywire during This process So I’m gonna console log out the message Once more And call this message And then on top of that I’m also going

To console log out in here what this is Uh so these are const messages is equal To Well essentially this chat log And it will pass that back in here as Messages So essentially We’re looping through The messages after we’ve set them we’re Joining them together I think I’m gonna Do a dash n here so that it does a line Break Uh and then we’re going to send them Across Save on that go to the client here Restart of the client for node.js And go refresh so are you working here’s Our first one so we’ve got a response Back but it’s overwritten our other chat But let’s have a look at what’s Happening Here on our server so I had a Bit of an issue here where these things Are happening out of order so I’m going To fix this up a little bit first what I’m gonna do is over here I’m going to Set the chat log here as a variable cons Chat log new and I’m actually going to Do that as a let and that can equal and I’ll do this as an array uh and that can Be the chat log itself plus this extra One that we’re essentially creating now I’m going to set the input to be nothing And then after that I’m going to use This chat log here to create the new Messages

So messages I can just have as a word Messages Uh beautiful and then that will be based On the new chat log that’ll pass in here And then finally we’ll get our data and Our data can be based on our original Chat log new which is just over here Plus the new message that we get back From the server and then we’re going to Set that all let’s hit save on that and Refresh Let’s go back here chat log is not Defined so I am not calling or Referencing the proper one here it Should be called with a capital l so That is my bad let’s hit save on that We’ll go back and go Testing enter So that is now waiting for chat GPT to Respond and then it’s updating in here As you can see So with that being a better structure we Can actually go back in here Go to set state We could probably just paste it in here Like that Um So that can be the new chat log and then Let’s jump back in here refresh test we Get test popping up immediately and then We get our message here from chatgpt Perfect all right so let’s do a new chat This time I want you to pretend to be Steve Jobs enter

So let’s see what comes back this should Be a completely blank plain thing hello There my name is Steve Jobs uh what are Your tips to help me start a new Business So I assume it’ll reply as Steve Jobs Here but uh have a clear vision and Message know what you want yeah so this Is now a completely vanilla version of Well almost like Chad GPD and almost Like an interface for open ai’s Playground but in a chat like interface So let’s see how we can now customize This and add features and some of the Things that you might not normally be Able to do inside of here so the very First one is a let’s actually jump into Uh I suppose the interface here on our Backend server and previously we had This thing here uh where openai gave us A list of engines we could use I’m gonna Create an actual API route here called Get and then I suppose engines or maybe Models models might be better And what I want to do here is grab what Models are being sent over from openai And then send them back to the front end As models we can start using for talking To chat GPT So if we go to open ai’s options over Here if we go to I think the Introduction and we have a look or was It Was it in introduction under API yep

There it is uh here is that first one to Grab the list of engines I’m going to grab that piece of text Over here and I’m going to throw this in Here and then I’m gonna do a uh Json or A response as a Json And we’re going to pass that response in Here which I assume will be the list of Engines But I see assume that’ll be data so uh Engines or sorry models Response dot data So let’s hit save on that We’ll restart node and this is forward Slash models so here in our app what We’re going to do is create a new Function Get engines And this will just be a simple API Request which apparently is already Filled out that’s very impressive uh Even with the right port and the right Data I’m kind of scared how chat GPD Just did that or at least good Hub Co-pilot we need a button to call this But realistically I just want this to Call as soon as we launch so what I’m Going to do is I’m going to do uh let’s Do a Uh use effect run once when app loads So we’ll need to import Use effect And then in here Let’s place it in

Use effect List engines stop Fair enough hit save on that And then we’ve got a huge Object thing that we’ve come back here From the server anyway this is under Data data data okay so maybe data dot Data is what we need Refresh But anyway we’ll jump back in here we’ll Open up the Tools and let’s see what objects we get Back with so we’ve got our models back Here and there’s quite a few different Models to choose from but it’s called Models.data So what I’m gonna do is I’m gonna create A new item in here as a set State a new Variable that we’re going to save And these will be called models Set models And then for our models we want that to Be an array And here when we get the engines and the Data and I think what were they called They were called models data so we’re Going to call models data from there Models data And we’re going to set them in here Great then I want to Loop them out I want to loot them out just here in the Sidebar as divs so let’s do a div class Name equals models Then I’m going to do a select

And then option is models I think GitHub copilot is already predicting What I want to do here and it’s even Filled it out let’s see if this actually Even works Uh so yes it has worked but But it doesn’t list them properly in Terms of their values I’m going to Scroll back up here I’m gonna console Log these out as well so I can see what They look like Let’s put that here in curly braces so We can run more than one command console Log models Uh this is what our model looks like we Have an engine an object an ID I think The ID is the name of it So I’m going to use that to list it out So here in our select the key can be the ID and the model Oh Models model model ID Model name Ah that’s where it went wrong All right so model ID can be here too so Let’s refresh now we’ve got all our Models here on the left hand side in a Nice select so we can select what kind Of model we want to use And this is just a list of models right Now I believe we’re probably using DaVinci but we could probably use say Code and then we can chat with the code Version of chat GPT which would be way Better than just the regular version so

Let’s see how we can do that So what we’re going to do here is we’re Gonna also create one more uh Set Current model And then we’ll do current model here And we’ll set this as a text of say Adder or something like that Um Oh Ada I think it’s properly pronounced Then Set current model will be changing when We do a change on the select so let’s go To select on change Let’s do E And we’ll pass in set model to equal E-target value And this will have the value of current Model updated then here under the Request that we’re doing where we’re Sending in a message I’m going to pass In current model as well For current model I’m going to pull that Out of the post request Here under request body and I’m going to Place it here in the models So instead of text DaVinci 003 Let’s comment that out And instead we’re going to pass in Current model Hit save on that And now let’s jump back into here And the other thing we need to do is Probably set the current model but let’s

Do say Um What model should we do a code model Code DaVinci edit fix their Log equal test let’s see what comes back So that’s come back with not exactly What I was looking for but uh in terms Of What it should be doing I think we need To clear out at the chat Then go what are you and let’s have a Look I’m doing A project I’m working on a project all Right well um Okay I think we’ll have to jump into the Server here and check what we’re Applying to and what the current model Is so I’ll do a console.log I’ll do Current model is current model hit save On that And then after that I’m going to doing Your request but first I have to refresh This ah it’s because we didn’t reboot Node I think But let’s let’s try this out so we’ll do A new chat we’ll use uh Coding of prompt so the coding probed Code crushman fix the code VAR VAR Equals testing Let’s see what comes back So now we’ve got Pure code coming back From crushman so this is what we got Back but now let’s do a new chat and

This time we’ll do Adda Paste this in and we’ll probably get Some nonsense yep because it’s just not A coding example so now we’ve got a new Chat and we’ve also had an option here For changing the engine that we’re using For chat GPT which is very cool this Should give you enough of an idea of how To build your own version of chat gbt on Top of that I’ve continued to build this Out and I’ve added it in the link in the Description you can buy it for fifty Dollars if you don’t want to have to put It yourself together this supports the Channel and it supports me I hope you Guys enjoyed this video If You did leave A like hit subscribe and I’ll see you in The next one thank you

You May Also Like

About the Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *