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

Поділитися
Вставка
  • Опубліковано 22 гру 2024

КОМЕНТАРІ •

  • @swarnendubanerjee502
    @swarnendubanerjee502 Рік тому +6

    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!!

  • @spanishlarc31
    @spanishlarc31 Рік тому +2

    Thank you for saving me time by creating short video and to the point. 😁

  • @originalbinaryhustler3876
    @originalbinaryhustler3876 Рік тому +6

    I see a great UA-cam career ahead of you 💪

    • @TheTechDeepDive
      @TheTechDeepDive  Рік тому +2

      It sounds like the video helped! Glad to hear it!

    • @originalbinaryhustler3876
      @originalbinaryhustler3876 Рік тому +1

      @@TheTechDeepDive Definitely, I like the way you explained man. Respect from South London 🤝

  • @97pixels
    @97pixels Рік тому +4

    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  Рік тому +1

      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?

  • @FsFs3mk-u9n
    @FsFs3mk-u9n Рік тому +2

    You earned a new sub, keep it up 💪

  • @sagarnanera
    @sagarnanera Рік тому +6

    Great video 👍

  • @souvikpatra1939
    @souvikpatra1939 Рік тому +6

    Why did I get the request failed with status code 429.?
    🙃🙃🙃🙃🙃🙃

    • @moomenazzam-ps
      @moomenazzam-ps Місяць тому

      +1
      and i don't use the limets
      at 25/10/2024

  • @PiyaliMukherjee-be2ir
    @PiyaliMukherjee-be2ir 5 місяців тому +1

    since the text-davinci-003 model is now deprecated can you show it with another model that would be very helpful ,thank you

  • @peitho4757
    @peitho4757 Рік тому +2

    THANK YOU SO MUCH OH MY GOD MY DAY WAS RUINED AND YOU SAVED IT

  • @worldoptics
    @worldoptics Рік тому +3

    Why I am getting Configuration is not a constructor error , when i run the node js server in this code ?

  • @tribecasterTV
    @tribecasterTV Рік тому +1

    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

  • @jini611
    @jini611 Рік тому +2

    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

  • @szabolcslajosvarga232
    @szabolcslajosvarga232 Рік тому +1

    why createAnswear is crossed out for me ?

  • @saluna11
    @saluna11 Рік тому +1

    I really want to know about the command i will use to install the packages

  • @LegendD112
    @LegendD112 Рік тому +4

    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  Рік тому +3

      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!

  • @MyEnglishIsPoor
    @MyEnglishIsPoor Рік тому +2

    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 Рік тому +1

      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!

  • @HarishSharma-cy7gm
    @HarishSharma-cy7gm 3 місяці тому

    I have a task to make a custom chatbot using openai api using html,css and js and node.js express.js and building own chatbot I'm stuck to get the response from the api

  • @SssS-li8qn
    @SssS-li8qn Рік тому +2

    tranks bro

  • @VK-hs8qr
    @VK-hs8qr Рік тому +2

    What is the name of the extension you are using on vscode which predicts the incoming commands? It's really cool.

    • @TheTechDeepDive
      @TheTechDeepDive  Рік тому +1

      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

  • @egeozel80
    @egeozel80 Рік тому +2

    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 11 місяців тому

      Hi, I was wondering if you ever resolved this issue? I can't figure this out either.

    • @egeozel80
      @egeozel80 11 місяців тому

      @@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 11 місяців тому

      @@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 11 місяців тому +1

      @@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 11 місяців тому

      @@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.

  • @Smirk_Station
    @Smirk_Station 26 днів тому

    Thanks!!

  • @CoBER-nc3el
    @CoBER-nc3el Рік тому +4

    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 Рік тому +1

      Looking for the same solution!

    • @TheTechDeepDive
      @TheTechDeepDive  Рік тому +1

      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 Рік тому +4

    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  Рік тому +1

      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!

  • @ibrahimdoba6143
    @ibrahimdoba6143 Рік тому +2

    amazing video, if i may ask what vscode extension are you using that give auto complete suggestions?

    • @TheTechDeepDive
      @TheTechDeepDive  Рік тому +1

      Glad it helped! GitHub copilot was the extension!

  • @chetansaini6698
    @chetansaini6698 Рік тому +1

    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 Рік тому +1

      @@TheTechDeepDive thanks a lot for a solution. 🤘

  • @Ali-r-h-flights
    @Ali-r-h-flights Рік тому +2

    Good vidoe, if I have a website, can I do this with only JS?

    • @TheTechDeepDive
      @TheTechDeepDive  Рік тому

      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.

  • @Spider-Man_67
    @Spider-Man_67 2 місяці тому

    Configuration is not a constructor
    at Object.
    Getting this error, again & again, anyone has any solution to this?

  • @gokulaindira9617
    @gokulaindira9617 Рік тому +2

    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 8 місяців тому +1

    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

  • @love_fun_bgm7218
    @love_fun_bgm7218 Рік тому +1

    hi bro,
    I got this error "you exceeded your current quota please check your plan and billing details"

    • @arbourgray
      @arbourgray Рік тому +1

      you gotta buy more tokens

    • @TheTechDeepDive
      @TheTechDeepDive  Рік тому

      yep @arbourgray is right. You've used up your free tokens.

  • @MenVibe365
    @MenVibe365 Рік тому +2

    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  Рік тому +1

      Not yet! I’ve tried before but the problem is you need a ton of example data to create an effective model.

    • @MenVibe365
      @MenVibe365 Рік тому +1

      @@TheTechDeepDive Thanks for your prompt response man!

  • @tradingtips_za
    @tradingtips_za 7 місяців тому

    doesnt work for some reason 6.48

  • @MatichekYoutube
    @MatichekYoutube Рік тому +2

    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  Рік тому +1

      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!

  • @developerpranav
    @developerpranav Рік тому +1

    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?

  • @amaan8617
    @amaan8617 Рік тому +2

    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  Рік тому

      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!