How to Integrate ChatGPT with Node.js App using the OpenAI API | JSON Formatted Responses

  Рет қаралды 40,430

Tech Deep Dive

Tech Deep Dive

Жыл бұрын

#chatgpt #openai #nodejs
Hello Everyone and Welcome Back to Code Deep Dive Channel.
In this video, we will be focusing on using the OpenAI API to generate text in response to a prompt, and also retrieving the AI's response in JSON format in a Node.js application. We will show you how to set up the OpenAI API and authenticate your requests, as well as how to send a prompt to the API and retrieve the generated text in JSON format.
The source code written during the video is available on GitHub at
github.com/Brady-Agranoff/cha...
you can use this code as a starting point for your own projects and refer to it as you follow along with the video.
For further information on using the OpenAI API, please refer to the official documentation at
platform.openai.com/docs/intr...
it provides detailed information on how to use the API, including authentication, usage limits, and more.
👉 𝐈𝐟 𝐲𝐨𝐮 𝐥𝐢𝐤𝐞 𝐭𝐡𝐢𝐬 𝐯𝐢𝐝𝐞𝐨, 𝐩𝐥𝐞𝐚𝐬𝐞 𝐥𝐢𝐤𝐞 𝐢𝐭 𝐚𝐧𝐝 𝐬𝐡𝐚𝐫𝐞 𝐢𝐭.
👉 𝐃𝐨𝐧'𝐭 𝐟𝐨𝐫𝐠𝐞𝐭 𝐭𝐨 𝐬𝐮𝐛𝐬𝐜𝐫𝐢𝐛𝐞 𝐭𝐨 𝐦𝐲 𝐜𝐡𝐚𝐧𝐧𝐞𝐥 𝐟𝐨𝐫 𝐦𝐨𝐫𝐞 𝐮𝐩𝐝𝐚𝐭𝐞𝐬.
/ @codedeepdive
Suggested videos for you:
1. Easily Generate Images in Node JS Using OpenAI (Dalle-2) Generation API : A Simple & Easy Guide • How To Generate Images...
2. Create a RichText Input in React (With Customized Toolbar Template) | ReactJS • Create a RichText Inpu...
3. Easily Add Slider Input in ReactJS using PrimeReact | User Input Tutorial • Easily Add Slider Inpu...
🔎 Related Keywords:
chatgpt,openai,chat gpt,chatgpt api,chatgpt tutorial,openai api,open ai,ai,artificial intelligence,nodejs,integrate chatgpt,chatgpt explained,chatbot,coding,programming,learn to code,programmer,code,javascript,javascript for beginners,javascript tutorial,learn javascript,javascript tutorial for beginners,javascript course,javascript basics,javascript crash course,javascript tutorials,javascript project,chatgpt examples,how to use chatgpt
🔎 Hashtags:
#howtousechatgpt
#chatgptexplained
#javascript
#learnjavascript
#coding
#javascripttutorial

Пікірлер: 76
@spanishlarc31
@spanishlarc31 Жыл бұрын
Thank you for saving me time by creating short video and to the point. 😁
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
No problem! I’m glad the video helped!
@user-tb8pv7qm4o
@user-tb8pv7qm4o Жыл бұрын
You earned a new sub, keep it up 💪
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Super glad it helped!!
@97pixels
@97pixels Жыл бұрын
Thanks, CDD. I am working on a project and the response json from Openai was a big problem. thanks for showing the way to get the result in the expected format! 👍
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
No problem!! I was having the same issue, it's a huge pain. Something I think I mentioned in the video, but never implemented was error handling. I would advise checking for an error when parsing the json, and if there is one, then run the prompt again. I usually do a 3 retry limit. Even with the best prompts I've come up with, I only get proper json back about 90% of the time. By trying 3 times, I can get it right pretty much every time! Good luck!
@chetansaini6698
@chetansaini6698 Жыл бұрын
I'm getting "Unexpected Token in JSON at position X" from time to time in the JSON sent by CHATGPT. Do you how to fix this by modifying the prompt?
@swarnendubanerjee502
@swarnendubanerjee502 Жыл бұрын
My teeth were almost dropping out of the jaw in pressure of code, but Then I found your video. Thank you Sir. You helped a lot!!
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
So glad it helped, keep those teeth in!
@swarnendubanerjee502
@swarnendubanerjee502 Жыл бұрын
@@TheTechDeepDive Yes, I am busy Repacking 📦📦😅
@MatichekYoutube
@MatichekYoutube Жыл бұрын
that is the typical gtp response haha
@sagarnanera
@sagarnanera Жыл бұрын
Great video 👍
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Glad it helped!
@originalbinaryhustler3876
@originalbinaryhustler3876 Жыл бұрын
I see a great KZbin career ahead of you 💪
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
It sounds like the video helped! Glad to hear it!
@originalbinaryhustler3876
@originalbinaryhustler3876 Жыл бұрын
@@TheTechDeepDive Definitely, I like the way you explained man. Respect from South London 🤝
@souvikpatra1939
@souvikpatra1939 11 ай бұрын
Why did I get the request failed with status code 429.? 🙃🙃🙃🙃🙃🙃
@SssS-li8qn
@SssS-li8qn Жыл бұрын
tranks bro
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Glad it helped!
@tribecasterTV
@tribecasterTV 10 ай бұрын
Dude how can you fix the import not recognized on the web browser in node it don't have error but on browser import not recognized how you fix this
@computerskills9492
@computerskills9492 Жыл бұрын
I really want to know about the command i will use to install the packages
@peitho4757
@peitho4757 11 ай бұрын
THANK YOU SO MUCH OH MY GOD MY DAY WAS RUINED AND YOU SAVED IT
@TheTechDeepDive
@TheTechDeepDive 10 ай бұрын
Glad your day was saved! :)
@CoBER-nc3el
@CoBER-nc3el Жыл бұрын
Man I've managed to do this, but using the gpt 3.5 turbo model, so the structure of the createCompletion method is slightly different. I've gotten it to work, like in this video, in the server environment but I've been having trouble getting to use the api on the client side, for example done through an html web page. Do you know where I could get more info on how to implement this on the client side? Would appreciate any input. And thanks for the vid!
@yvoderooij6340
@yvoderooij6340 Жыл бұрын
Looking for the same solution!
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
I'm not exactly sure what you're looking for here. Since your API keys for openai should be private (to avoid costs being run up by someone stealing your keys), I would always call it from a backend. I would advise creating a backend, and using an endpoint with proper validation to communicate to your backend. I hope you found the solution you were looking for.
@jukiflow
@jukiflow Жыл бұрын
Hello, that is a fantastic explanation. How can I send an array of data in json format to chatgpt and get from chatgpt indicators of this data in json format? thank you
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Jose, I’m very glad it helped. The way I would suggest doing this is to specify in the prompt exactly the format and content of the response you would like to receive. I would take the response and attempt to parse the string to JSON to get your results (as I did in the video). If the parsing fails, I would attempt the call to chat GPT again. If you work on optimizing your prompt (changing it until you get more consistent results), you can make it so the data received back is in the correct format almost every time. Since the AI tries to take some risks in the response, it will still sometimes return you an improper response. That is the case that you rerun the request and you will more than likely get a proper response the next time. Hope this helps!
@LegendD112
@LegendD112 Жыл бұрын
I would like to ask you something, is it possible to create an application, for example, "a job recruitment simulator" with chatgtp? is chagtp already stable? or is it better to wait for an interface or something? (I'm just starting to study programming)
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
It is absolutely possible to create something like this, and I see no reason not to. It is stable in some sense. The API is stable and will not go away. However, the AI can be quite unpredictable, but I find it to generally be quite good, and it is continually improving. If you structure the prompt correctly, I suspect you'll get fairly good results. Best of luck on your programming journey! It's difficult, rewarding, and fun. All the best!
@szabolcslajosvarga232
@szabolcslajosvarga232 Жыл бұрын
why createAnswear is crossed out for me ?
@MenVibe365
@MenVibe365 Жыл бұрын
Hey man! Awesome video, learn too much. Do you know how to create a fine tune from a JSONL file? and import it to join the "davinci-003" model? I'm breaking my head with this, but I couldn't get tutorials on NodeJs
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Not yet! I’ve tried before but the problem is you need a ton of example data to create an effective model.
@MenVibe365
@MenVibe365 Жыл бұрын
@@TheTechDeepDive Thanks for your prompt response man!
@ibrahimdoba6143
@ibrahimdoba6143 7 ай бұрын
amazing video, if i may ask what vscode extension are you using that give auto complete suggestions?
@TheTechDeepDive
@TheTechDeepDive 7 ай бұрын
Glad it helped! GitHub copilot was the extension!
@MyEnglishIsPoor
@MyEnglishIsPoor Жыл бұрын
Hi, thank you for your video which taught me to call openai. I know a little javascript. I want to use openai to make an app to help me learn English, and I have done it. It is a pity that the content cannot be output a little bit like chatgpt. When I set the stream to true, I don't know how to receive the data. I'm using typescript + vue3 + node.js. If you see, I'd like a finished example if you want, thanks.
@MyEnglishIsPoor
@MyEnglishIsPoor Жыл бұрын
I found a lot of code snippets on the Internet, But I couldn't get it to work.
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Hey, I hope you've gotten this working. I haven't messed around too much with the data stream before. However, I've set it to true before, and seen the stream logged. It should be possible to do what you're looking to do. I would suggest looking at a websocket communication between the front and backend, and display the data live as it is fed through. Good luck!
@VK-hs8qr
@VK-hs8qr Жыл бұрын
What is the name of the extension you are using on vscode which predicts the incoming commands? It's really cool.
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
GitHub Copilot!! It costs $10 a month or $100 a year. 100% worth it. It took me a couple weeks to adjust, but I’m much much more efficient now. Will never go back
@MatichekYoutube
@MatichekYoutube Жыл бұрын
@@TheTechDeepDive ya, best money I ever spent
@amaan8617
@amaan8617 11 ай бұрын
This is showing this error message: 'You exceeded your current quota, please check your plan and billing details.', I have never used this API before still it is showing that you have exceeded your quota. How can i resolve it.
@TheTechDeepDive
@TheTechDeepDive 10 ай бұрын
The openAI API doesn’t have many free credits if any at all. Just log into your account where you found the api keys, and head to billing details. There should be more info there! Good luck!
@jini611
@jini611 Жыл бұрын
do you know how do I stop chatgpt API not to give answer other then the training that I gave to it? I am using 3.5-turbo api model
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
You have to be super specific with the prompt, and reiterate multiple times you don’t want anything but the response structure you gave it. I usually parse the response, and if it gives and error, I paese again. I give it 3 retries. It usually works 90% of the time, so with 3 tries it works 99.9% of the time
@Ali-r-h-flights
@Ali-r-h-flights 11 ай бұрын
Good vidoe, if I have a website, can I do this with only JS?
@TheTechDeepDive
@TheTechDeepDive 10 ай бұрын
Yes, you could. I’d advise against it however as the end users could access your API key and use it to charge your account.
@worldoptics
@worldoptics 9 ай бұрын
Why I am getting Configuration is not a constructor error , when i run the node js server in this code ?
@ogabrieljunqueira
@ogabrieljunqueira 9 ай бұрын
Got the same error here, could you solve it?
@avamovies7791
@avamovies7791 9 ай бұрын
got the same errror here@@ogabrieljunqueira
@chetansaini6698
@chetansaini6698 Жыл бұрын
I'm getting "Unexpected Token in JSON at position X" from time to time in the JSON sent by CHATGPT. Anybody knows how to fix this by modifying the prompt?
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
I mentioned it briefly in the video but didn't go into detail: By adjusting the prompt, I was only able to get about 90% of the time to return me the proper format. I would get that same error. My way of getting around this would be to do a try-catch on the json parsing. If it gave me an error, I would go ahead and rerun the same prompt. I would give it a total of 3 tries (for me that got to about 99.9% of the time it works -- but you could obviously add more retries if you need). I hope that helps!
@chetansaini6698
@chetansaini6698 Жыл бұрын
@@TheTechDeepDive thanks a lot for a solution. 🤘
@egeozel80
@egeozel80 7 ай бұрын
Yo, very cool thanks but i am getting TypeError: Configuration is not a constructor error over and over again, what might be the problem? 😬😬
@woahmax
@woahmax 5 ай бұрын
Hi, I was wondering if you ever resolved this issue? I can't figure this out either.
@egeozel80
@egeozel80 5 ай бұрын
@@woahmax hi, I opened a new account which gives you an API quota like 5$. Maybe this solved the problem but maybe I corrected implementation too, not sure about that but be sure you have some money on your OpenAI account.
@woahmax
@woahmax 5 ай бұрын
@@egeozel80 thanks for getting back to me! I'll try that later today. Was there any changes to your code before getting it to work? Or was it literally just need to pay?
@egeozel80
@egeozel80 5 ай бұрын
@@woahmax you are welcome and not sure unfortunately and I can't check that because I am close to my projects due, you can just ask ChatGPT for implementation of its own API, that was what I did lately.
@woahmax
@woahmax 4 ай бұрын
@@egeozel80 I GOT IT TO WORK!!! Ok so turns out it wasn't because I didn't have enough money in my balance. I downloaded CDD's source code of the video and it works (as of writing this, I had to change the model to "gpt-3.5-turbo-instruct"). Then I compared to my own code and files on what the difference is. Following instructions from this video, all of my code is correct. Turns out the main difference is my axios and openai files in node_modules are different from CDD's. I replaced my axios and openai folders with Brady's source files and BAM it works. I'm not sure why the files are different when I use "yarn add openai" are different. Hopefully this is helps for others running into this problem. Also hopefully someone can explain this happened to me.
@MatichekYoutube
@MatichekYoutube Жыл бұрын
Is there a reason you would need a "custom json" response from the api? Why not just take the original response and make a custom object in the code? I am asking cause, if you NEED 100% stable response, I would not risk that gpt is creating json object for me. Maybe you burn less tokens if gpt prepares you a json structure? @Code Deep Dive
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Good point, you don't really need a json response. In the case I was using it for, I wanted 5 examples with 2 different fields each. I could've called each individually, but it wouldve taken much longer and used a few more tokens. It's up to you how you do it, but I found this seemed to work better for my use case!
@gokulaindira9617
@gokulaindira9617 Жыл бұрын
How to make it customized for my own application ,this actually is responding only to one questions how can, i make it for my own applications so that it satisfy the user need can you please reply?
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Can you give a little more context? To get it to respond in the exact way you would like it to, you may need to play with the prompt a bit and adjust it until you find one that consistently returns the results you need. It is likely it will still return incorrect responses from time to time. What I have done to get around that (in the case of needing a json response) is to attempt to parse the json, and if it gives an error during parsing, I then try the request again. I give it 3 total tries, and if it doesn’t work, there is likely a different issue occurring, so I don’t have it try again. Is that what you mean?
@gokulaindira9617
@gokulaindira9617 Жыл бұрын
@@TheTechDeepDive Thank you for your response ,the thing i needed is i need to create a custom support chat for my application which answers every questions for users (like checking the status of the order)is this possible with this code or else can you give me a tutorial regarding it if possible sir
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
@Gokula Indira, This is absolutely possible, but it takes quite a bit more work to do. I would suggest looking into fine-tuning a model (you give openai 1000+ examples of prompts and answers, and it gives you a model that tries to respond according to those examples -- the more examples the better it will be). You can find some documentation on it here: platform.openai.com/docs/guides/fine-tuning In the documentation, they actually have your specific use case as an example, so that is quite helpful. It's quite a bit more difficult than text generation, but I've played with it before, and it seems to work well. It is on my list to make a tutorial about, however it is quite a bit more complex so the video will be more difficult to make, and thus take longer. But I'm hoping to get a video out about it somewhat soon. I wish you the best of luck!
@gokulaindira9617
@gokulaindira9617 Жыл бұрын
@@TheTechDeepDive Thank you for your time
@jeyapragashj4500
@jeyapragashj4500 Ай бұрын
I downloaded your code and got the same error when i did on my own const configuration = new Configuration({ ^ TypeError: Configuration is not a constructor GUide me
@MuhammadIrfan-cj1cq
@MuhammadIrfan-cj1cq Ай бұрын
same issue did u find the sol?
@jt71955
@jt71955 Ай бұрын
doesnt work for some reason 6.48
@love_fun_bgm7218
@love_fun_bgm7218 11 ай бұрын
hi bro, I got this error "you exceeded your current quota please check your plan and billing details"
@arbourgray
@arbourgray 9 ай бұрын
you gotta buy more tokens
@TheTechDeepDive
@TheTechDeepDive 9 ай бұрын
yep @arbourgray is right. You've used up your free tokens.
@developerpranav
@developerpranav Жыл бұрын
I do the same, I just catch the error in JSON parser, and then run the function again :D
@TheTechDeepDive
@TheTechDeepDive Жыл бұрын
Awesome! It’s not perfect, but it works well enough.
@chetansaini6698
@chetansaini6698 Жыл бұрын
I'm getting "Unexpected Token in JSON at position X" from time to time in the JSON sent by CHATGPT. Do you how to fix this by modifying the prompt?
How to Create Custom GPT | OpenAI Tutorial
20:26
Kevin Stratvert
Рет қаралды 67 М.
ReactJS  setState()(React Tutorial #8)
8:49
The Code By Abhi
Рет қаралды 13
Китайка и Пчелка 4 серия😂😆
00:19
KITAYKA
Рет қаралды 3,4 МЛН
Каха инструкция по шашлыку
01:00
К-Media
Рет қаралды 7 МЛН
когда достали одноклассники!
00:49
БРУНО
Рет қаралды 4,3 МЛН
How to Create Custom VS Code Snippets | Visual Studio Code
14:21
Tech Deep Dive
Рет қаралды 217
How to Blur Edges of Image in Photopea | Free tool
4:37
CanvaMania
Рет қаралды 406
How to use OpenAI ChatGPT API in JavaScript and Node Js
13:37
Mitter - Your Tech Mate
Рет қаралды 609
Stream OpenAI Chat Completions Like ChatGPT in JavaScript
17:17
Codevolution
Рет қаралды 24 М.
Let's build GPT: from scratch, in code, spelled out.
1:56:20
Andrej Karpathy
Рет қаралды 4,3 МЛН
OpenAI Embeddings and Vector Databases Crash Course
18:41
Adrian Twarog
Рет қаралды 391 М.