How to use ChatGPT API Python for Beginners - Full ChatBOT Tutorial

Sdílet
Vložit
  • čas přidán 28. 02. 2023
  • In this video, we'll learn to build a ChatBOT using Python with ChatGPT API from OpenAI
    1. Learn how to get OpenAI Key Token
    2. Two different methods of using ChatGPT API in Python
    3. Building a Python ChatGPT ChatBOT with openai Python package
    4. Using ChatGPT API Completions End point
    5. How to change ChatGPT API Parameters like temperature
    6. Summary
    Code and Demo - github.com/amrrs/chatgpt-api-...
    ❤️ If you want to support the channel ❤️
    Support here:
    Patreon - / 1littlecoder
    Ko-Fi - ko-fi.com/1littlecoder

Komentáře • 156

  • @1littlecoder
    @1littlecoder  Před 5 měsíci

    🚨BUY with 34% Discount on my new Generative AI Course - bit.ly/3HQXsQd 🎉Coupon Code - LETSGO 🎉

  • @focusedonpost
    @focusedonpost Před rokem +3

    You always put out some of the best content out on CZcams. Thanks for sharing your knowledge of AI with the community!

  • @anshuman6623
    @anshuman6623 Před 4 měsíci

    Great video! Covered all the points it sought out to cover. Thumbs up!

  • @outsidemix3626
    @outsidemix3626 Před rokem

    Thank you! Incredibly detailed and clear.

  • @stevefox7469
    @stevefox7469 Před rokem +1

    Excellent tutorial as usual...super up to date content.

  • @jamges
    @jamges Před rokem +5

    This is great! Would love to know how to chain API calls for Whisper and GPT together:
    For example:
    A Ui where a user speaks, whisper transcribers what they say , then their transcription is summarized/interpreted with a pre-made GPT prompt, and the user can see the summarized/remixed output?

  • @neofuturist
    @neofuturist Před rokem +2

    Commenting before even watching the video because I want to thank you for all your effort!!

  • @arashputata
    @arashputata Před rokem +1

    Thanks bro for being so fast in announcing ai news. Already last night after ur video about chatgpt i jumped on it and made a quick chatbot

  • @HelenJackson-pq4nm
    @HelenJackson-pq4nm Před rokem

    Really clear explanation, thanks a lot

  • @user-bo2zl5il5d
    @user-bo2zl5il5d Před rokem +3

    Great tutorial for ChatGPT api. I really enjoy watching for your kind and clear teaching:)

  • @raidedcluster
    @raidedcluster Před rokem +3

    Man I love your work. Thank you.

    • @1littlecoder
      @1littlecoder  Před rokem +1

      I really appreciate that :) Thanks for commenting!

  • @iangouvea9671
    @iangouvea9671 Před 4 měsíci +3

    Nem todo Indiano, mas sempre um Indiano. Obrigado amigo, você é um amigo.

  • @tyler8902
    @tyler8902 Před rokem

    Fantastic tutorial!

  • @MN-yz7bp
    @MN-yz7bp Před měsícem +1

    Great teacher. This is the best explanation for newbies that I've seen.

  • @F.D.S
    @F.D.S Před rokem

    Great!! Thank you!

  • @sameerzahid3544
    @sameerzahid3544 Před rokem

    Great work! Waiting for the tutorial about Gradio and ChatGPT.

  • @Travestyalpha
    @Travestyalpha Před rokem +1

    Thank you. Very clear explanation.

  • @highsobriety3491
    @highsobriety3491 Před rokem

    Great teacher brother.

  • @yogaday4835
    @yogaday4835 Před rokem

    thanks for the tutorial !!!

  • @CARLOSFROMNY
    @CARLOSFROMNY Před rokem +1

    thanks for your contribution, you the best!!

  • @mariasueabiera8684
    @mariasueabiera8684 Před 5 měsíci +1

    Awesome tutorial especially for beginners

  • @DjDiversant
    @DjDiversant Před rokem

    Thank you!

  • @stevezing9341
    @stevezing9341 Před rokem +1

    Thank you so much, your tutorials are so helpful. Can you pls make a tutorial on how to fine tune this model. Let's say i want to provide the model with several documents. I want it to learn from it so that i can do QA on it.

  • @spicer41282
    @spicer41282 Před rokem

    You are Always on the tip of this spear! 👌 👍 Look forward to your next gangbuster vid?
    How about a Mashup between this newAPI and ControlNet!
    Thoughts?

  • @rodo2220
    @rodo2220 Před měsícem

    great video

  • @TimothyCarney-kk7kw
    @TimothyCarney-kk7kw Před rokem

    Thanks!

  • @roguephilosopher2465
    @roguephilosopher2465 Před 7 měsíci

    Very helpful!

  • @Kalease54
    @Kalease54 Před rokem +7

    Excellent video as always. A few things I’m curious about though, using the API endpoint how would you retain chat history like you did using the While True loop? Also if building an application for multiple users how would you do it in such a way that the ChatGPTs memory is specific to a certain user?

    • @carlosprieto2554
      @carlosprieto2554 Před rokem

      Same question

    • @1mrnewton
      @1mrnewton Před rokem

      You’d need to always append your previous message and gpt response to the new request json body
      He explained in the video.

  • @ahmadzaimhilmi
    @ahmadzaimhilmi Před rokem

    Using requests module, how do you reference a particular chat. Say the conversation about Gary Kasparov vs about something else? I saw there's a chat ID in the json response. How do you reference that?

  • @SONUKOL1
    @SONUKOL1 Před rokem +1

    Very knowledgeable content

  • @machinesmakemusic
    @machinesmakemusic Před rokem

    Please make a video with method 1, but with more settings like temperature ! I would be so happy.

  • @sharanbabu2001
    @sharanbabu2001 Před rokem

    Cool!

  • @markfrancisbeltran4619
    @markfrancisbeltran4619 Před 8 měsíci

    Great video. You got me hook there and didn't even notice the time! I like how you well explained the topic. Hey you talked about building a chat interface... but I can't find your video. Can you link it here for me please.

  • @pratyushbhatt1712
    @pratyushbhatt1712 Před 7 měsíci

    How does the second method maintains the context like the first method was maintaining?

  • @Brandon-uf4dt
    @Brandon-uf4dt Před 2 měsíci

    Is there a way I can access public data from law books and add it to a personal chat gbt library?

  • @rahasyabharat4894
    @rahasyabharat4894 Před 5 měsíci +1

    Will you please help me where I put this code in which application i understand the whole method how to translate key from open AI and other but I am not able to understand in which application I have to put this all

  • @maftar5
    @maftar5 Před měsícem

    How do you add context with the api endpoint?

  • @lyricsdepicted5628
    @lyricsdepicted5628 Před rokem

    Now with control over temperature, you could repeat your hullicination querries with temperature of 0 and compare :)

  • @priyankjetani1508
    @priyankjetani1508 Před rokem

    In the second method can we ask for a related question? likewise, if we ask the first Q. "who is the best chess player?" and the second Q. "he was lost any matches?

  • @DrR0bot
    @DrR0bot Před rokem +1

    This is really good. Thanks so much for the thorough explanation. A question that perhaps you have already answered.
    Is there a way to fine tuned CHAT gpt let's say from content or text you have created? Like your thesis or something?
    Thanks

    • @1littlecoder
      @1littlecoder  Před rokem

      Not yet, but you can use embedding from a different model and use ChatGPT model for inference

  • @Leyverse
    @Leyverse Před rokem +1

    Thank you so much, can you teach us how to integrate with whatsapp and telegram?

  • @ashishbhateja
    @ashishbhateja Před rokem +9

    Very well timed and nicely explained. Wishlist : please share how to add langchain/gpt index/pinecone 🤞

  • @jnealeuk
    @jnealeuk Před rokem

    How easy/hard (!) is it to embed these chatbots into a website? Thank you for your work!!

  • @Investwithwisdome
    @Investwithwisdome Před 10 měsíci

    what should be my system requirements if i want to train openai to create a new Application.
    Can i do it in 8GB Ram & I5 10Generation Laptop ?

  • @MuhammadYasir-uc9xt
    @MuhammadYasir-uc9xt Před 2 měsíci

    I have a project in python language which is a Plan text editor. I want to integrate it with open AI using API for the some purposes which are content suggetions, vocabulary suggetions, spell checker, grammar checker. kindly help me with it.

  • @mohammadawwad7832
    @mohammadawwad7832 Před rokem +2

    Hello, very interesting and thanks for being extremely clear.
    A question regarding the Data privacy, using these API's will not register any of our data for training purposes right ?

  • @95249192
    @95249192 Před rokem +1

    If possible, how to set up with gradio ?

  • @OrchidMacro
    @OrchidMacro Před rokem

    That would be nice to add a functionality where you can insert a PDF.

  • @ahmimo2918
    @ahmimo2918 Před rokem +1

    Thank you so much for putting this together! -- Very helpful!
    One noob question: is it possible at this point of time to train chatGPT on your own data using their API?

    • @1littlecoder
      @1littlecoder  Před rokem +2

      Right now, Finetuning with ChatGPT model is not available

  • @jurgenihlau4052
    @jurgenihlau4052 Před 13 dny

    Hello, very nicely explained. I have a small problem, maybe you can help me.
    I run a Linux Mint support forum (Linuxmintusers - LMU GER) with SMF software. In the first post of a support request, users often forget to include their system details so that we can help. How can I use the ChatGPT API, ChatGTP to check the first post to see if the information matches the question or not? Is that possible? Maybe you have an idea for us!
    Thank you!

  • @lyricsdepicted5628
    @lyricsdepicted5628 Před rokem

    Looks like for fine-tuning you can't make use of the 10x cheaper endpoint even though the model is the same.

  • @shreyashavaldar2076
    @shreyashavaldar2076 Před 4 měsíci

    Here is some more info:
    INFERENCE PARAMETERS:
    Temperature: Control randomness in Output, High temperature high randomness.
    Top_p: How many possibilities does the model considers when its giving its output.

  • @alintambunaloko
    @alintambunaloko Před rokem

    How to using the model in webApp like using flask

  • @SurajSharma-bh9gf
    @SurajSharma-bh9gf Před rokem +6

    The error is message": "You exceeded your current quota, please check your plan and billing details." not working please suggest

    • @alexisrioslopez5423
      @alexisrioslopez5423 Před 8 měsíci

      you have some credit to do your works, now you need to recharge.

    • @billythebiest_9404
      @billythebiest_9404 Před 5 měsíci

      i have the same error but when i look into my openai account
      I still have credits.

    • @ujjwalsrivastava4581
      @ujjwalsrivastava4581 Před 3 měsíci

      Same error guys if anyone got the solution please tell me

    • @lazycoder112
      @lazycoder112 Před 2 měsíci

      If you still have credits prob because the request needs more credit then you have especially doing request with gpt 4

  • @tomtomfh3639
    @tomtomfh3639 Před rokem

    yes

  • @dalisongwira1424
    @dalisongwira1424 Před rokem +1

    wow you know how to explain

  • @PatnaikUC
    @PatnaikUC Před rokem

    Excellent! Please make a Python code with ChatGPT API for robotic applications (Using Raspberry Pi) where the if the user input is any word out of 10 specific words saved, the response generated should be that word only which is then linked to the output. Example- "go left" input by the user. The robot moves left as the response it receives "go left" from ChatGPT through the API key

    • @tylermichaelbell
      @tylermichaelbell Před rokem

      you may want to look at arduinos for that, but honestly, you could ask chatgpt to write this code and it'll get you 80 percent there. i dont know exactly what your application is for though, seems like chatgpt is an extra step that isnt needed. you could have chatgpt write a simple console application that moves per input.

  • @Sergedable
    @Sergedable Před rokem +1

    Great video. I'd be grateful if you made one. How can we fine-tune ChatGPT for our own data?

    • @arashputata
      @arashputata Před rokem +1

      It's not possible to fine tune chatgpt.. also mentioned in the fine tuning section of the openai documentation

    • @spicer41282
      @spicer41282 Před rokem

      You can do so by feeding your data via the message box! Limited as far as i know directly from ChatGPT itself.
      It can ingest your text data @ 4070 characters including spaces at a time.
      You want make sure your Prompts contains the file streams so ChatGPT knows its part of a larger text file greater than 4070 characters. Hope that helps.

  • @syedbabarali1
    @syedbabarali1 Před rokem

    Thank you very nice way to guide! Could you assist me in creating a knowledge base and consuming the API in the C# language?

    • @1littlecoder
      @1littlecoder  Před rokem

      I think you should try this - czcams.com/video/hYcKPzXh4D8/video.html

  • @PANDURANG99
    @PANDURANG99 Před 6 měsíci

    how to deploy for users?

  • @CoBER-nc3el
    @CoBER-nc3el Před rokem

    Hi there! Thanks for the video, its been very helpful, currently using it in a project im working on. I was wondering if you could tell me if paying for the api key gives faster response times... for chatgpt api? Would appreciate your response. At the moment im using the free trial.

    • @mihawk1096
      @mihawk1096 Před rokem

      Can i ask how you got the free trail bcs im not able to use my api at all even though its my first time

    • @danieladam4719
      @danieladam4719 Před 10 měsíci

      ​@@mihawk1096 OpenAI grants you an amount of 5 dollars when you first sign-up but it seems to expire after a few months. Found out today that my trial expired one month ago.

  • @ompathak3384
    @ompathak3384 Před 5 měsíci +1

    it shows error that my model quota limits exceeds😮‍💨

  • @sambokhetwal
    @sambokhetwal Před 5 měsíci

    Can we link chat got api with facebook graph api?

  • @ujjalbaniya
    @ujjalbaniya Před rokem

    simply adding a bool instead of infinite loop will make code more efficient.

    • @ujjalbaniya
      @ujjalbaniya Před rokem

      x = True
      print("If you want to end the chat Please type END")
      while x:
      message = input("User : ")
      if "end" in message.lower():

  • @zappy9880
    @zappy9880 Před rokem +1

    Isn't the API paid? I can't get it without entering card info. how'd you get it?

  • @bhaidar
    @bhaidar Před rokem

    Another question, where would you store the "messages" if you were doing a Web App?

  • @ColabPro-ho9sx
    @ColabPro-ho9sx Před 3 měsíci

    my code doesn't work can you help me i copied your code but doesn’t work it

  • @harpreetchouhan1200
    @harpreetchouhan1200 Před rokem +1

    Never used the api still showing this error "RateLimitError: You exceeded your current quota, please check your plan and billing details" any solution

    • @1littlecoder
      @1littlecoder  Před rokem

      I think you would have exceeded 3 months since your account creation.

  • @Sensergaming
    @Sensergaming Před rokem

    I want to know about youtube where we connect through API in Data studio

  • @TechTips_KishuNeelavara
    @TechTips_KishuNeelavara Před 11 měsíci

    API key in freetrail is not working

  • @rildodemarqui
    @rildodemarqui Před rokem +2

    I've never used this API before, but even so I'm getting the message :"You exceeded your current quota, please check your plan and billing details."
    Somebody had this issue?

  • @ninasirsi2340
    @ninasirsi2340 Před 5 měsíci

    Where is next video

  • @theresilientpianist7114
    @theresilientpianist7114 Před 11 měsíci

    Showing me rate limit error

  • @ashishmalhotra2230
    @ashishmalhotra2230 Před 3 měsíci

    Even with a new signup I am getting this message: "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs". What to do?

    • @1littlecoder
      @1littlecoder  Před 3 měsíci

      I think you need to try with a new phone and a new email, probably the previous one's credits expired

    • @ashishmalhotra2230
      @ashishmalhotra2230 Před 3 měsíci

      @@1littlecoder Still doesnt work. New email, new phone, still doesnt

    • @ujjwalsrivastava4581
      @ujjwalsrivastava4581 Před 3 měsíci

      ​@@1littlecoderit is still not working please tell the solution

  • @aniketkajania610
    @aniketkajania610 Před rokem +4

    its the first time im using their api and im getting RateLimitError: saying that i have exceeded my quota

  • @bhaidar
    @bhaidar Před rokem

    Thanks for the excellent video. However, I was able to install openai on Google Colab, but when I try to set the key, it gives me errors.
    NameError Traceback (most recent call last)
    in
    ----> 1 openai.api_key = 'sk-...'
    NameError: name 'openai' is not defined

    • @1littlecoder
      @1littlecoder  Před rokem

      I think you didn't do pip install openai properly. If you had done that then you didn't import openai

    • @bhaidar
      @bhaidar Před rokem

      @@1littlecoder I followed the sample code you provided. I installed openai, then added the key. I should import openai first to add the key?

  • @premprasad3511
    @premprasad3511 Před rokem

    I just get this error : "You exceeded your current quota, please check your plan and billing details"
    This is the first time I am using it
    Can I know what should I do
    ?

    • @1littlecoder
      @1littlecoder  Před rokem

      It's possible you don't have any credits left. YOu might have to buy it

  • @debalinaghosh6404
    @debalinaghosh6404 Před 10 měsíci

    can you help doing it in java?

    • @1littlecoder
      @1littlecoder  Před 10 měsíci

      Why so ?

    • @debalinaghosh6404
      @debalinaghosh6404 Před 9 měsíci

      Hi, actually I have to do everything in java as my supervisors advised and I did in java. I have a question, can we give image inputs (like question in images) using API key of OpenAI@@1littlecoder

    • @1littlecoder
      @1littlecoder  Před 9 měsíci

      Hey, You can't give image as an input but there are certain ways you can take image and get a caption. / text out of it and then share it with this

  • @jdcrunchman999
    @jdcrunchman999 Před měsícem

    Your video is blocking the code

  • @athirashibu6089
    @athirashibu6089 Před rokem

    reply = response["choices"][0]["message"]["content"]
    TypeError: 'NoneType' object is not subscriptable

  • @hitarthdesai0882
    @hitarthdesai0882 Před 11 měsíci

    i have the error ssaying "You exceeded your current quota, please check your plan and billing details." and i haven't used it till now??
    please let me know

    • @hitarthdesai0882
      @hitarthdesai0882 Před 11 měsíci

      i tried creating a new API key too but gives the same erroe

    • @SatSTAR0
      @SatSTAR0 Před 11 měsíci

      same issue

  • @himadridas8221
    @himadridas8221 Před rokem

    I just hate the word...for beginners

    • @QWERTY-gp8fd
      @QWERTY-gp8fd Před rokem

      why. everybody has to start somewhere. Perfection doesn't happen right away

  • @ibrahimnadeem1064
    @ibrahimnadeem1064 Před 5 měsíci

    I've tried numerous times this code each n every thing, but still showing an error

  • @Webdev7211
    @Webdev7211 Před rokem

    when i am writng the method one code
    that you have mentioned in your reop Method 1 - using OpenAI Python Package afte writng what is your name I am getting htis error
    User : What is your name?
    ---------------------------------------------------------------------------
    RateLimitError Traceback (most recent call last)
    Cell In[77], line 7
    3 if message:
    4 messages.append(
    5 {"role": "user", "content": message},
    6 )
    ----> 7 chat = openai.ChatCompletion.create(
    8 model="gpt-3.5-turbo", messages=messages
    9 )
    11 reply = chat.choices[0].message.content
    12 print(f"ChatGPT: {reply}")
    File ~\AppData\Roaming\Python\Python39\site-packages\openai\api_resources\chat_completion.py:25, in ChatCompletion.create(cls, *args, **kwargs)
    23 while True:
    24 try:
    ---> 25 return super().create(*args, **kwargs)
    26 except TryAgain as e:
    27 if timeout is not None and time.time() > start + timeout:
    File ~\AppData\Roaming\Python\Python39\site-packages\openai\api_resources\abstract\engine_api_resource.py:153, in EngineAPIResource.create(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)
    127 @classmethod
    128 def create(
    129 cls,
    (...)
    136 **params,
    137 ):
    138 (
    139 deployment_id,
    140 engine,
    (...)
    150 api_key, api_base, api_type, api_version, organization, **params
    151 )
    --> 153 response, _, api_key = requestor.request(
    154 "post",
    155 url,
    156 params=params,
    157 headers=headers,
    158 stream=stream,
    159 request_id=request_id,
    160 request_timeout=request_timeout,
    161 )
    163 if stream:
    164 # must be an iterator
    165 assert not isinstance(response, OpenAIResponse)
    File ~\AppData\Roaming\Python\Python39\site-packages\openai\api_requestor.py:298, in APIRequestor.request(self, method, url, params, headers, files, stream, request_id, request_timeout)
    277 def request(
    278 self,
    279 method,
    (...)
    286 request_timeout: Optional[Union[float, Tuple[float, float]]] = None,
    287 ) -> Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], bool, str]:
    288 result = self.request_raw(
    289 method.lower(),
    290 url,
    (...)
    296 request_timeout=request_timeout,
    297 )
    --> 298 resp, got_stream = self._interpret_response(result, stream)
    299 return resp, got_stream, self.api_key
    File ~\AppData\Roaming\Python\Python39\site-packages\openai\api_requestor.py:700, in APIRequestor._interpret_response(self, result, stream)
    692 return (
    693 self._interpret_response_line(
    694 line, result.status_code, result.headers, stream=True
    695 )
    696 for line in parse_stream(result.iter_lines())
    697 ), True
    698 else:
    699 return (
    --> 700 self._interpret_response_line(
    701 result.content.decode("utf-8"),
    702 result.status_code,
    703 result.headers,
    704 stream=False,
    705 ),
    706 False,
    707 )
    File ~\AppData\Roaming\Python\Python39\site-packages\openai\api_requestor.py:763, in APIRequestor._interpret_response_line(self, rbody, rcode, rheaders, stream)
    761 stream_error = stream and "error" in resp.data
    762 if stream_error or not 200 763 raise self.handle_error_response(
    764 rbody, rcode, resp.data, rheaders, stream_error=stream_error
    765 )
    766 return resp
    RateLimitError: You exceeded your current quota, please check your plan and billing details.

    • @1littlecoder
      @1littlecoder  Před rokem

      Check if you have OpenAI credits in your account

    • @Webdev7211
      @Webdev7211 Před rokem

      @@1littlecoder but i haven't used any API before it's my first try and I haven't set any payment plan

    • @Webdev7211
      @Webdev7211 Před rokem

      @@1littlecoderI have no open ai credits in my account