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

Поділитися
Вставка
  • Опубліковано 28 лют 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

КОМЕНТАРІ • 155

  • @1littlecoder
    @1littlecoder  4 місяці тому

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

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

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

  • @anshuman6623
    @anshuman6623 3 місяці тому

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

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

    Thank you! Incredibly detailed and clear.

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

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

  • @jamges
    @jamges Рік тому +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 Рік тому +2

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

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

  • @iangouvea9671
    @iangouvea9671 4 місяці тому +3

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

  • @HelenJackson-pq4nm
    @HelenJackson-pq4nm Рік тому

    Really clear explanation, thanks a lot

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

    Man I love your work. Thank you.

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

      I really appreciate that :) Thanks for commenting!

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

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

  • @user-bo2zl5il5d
    @user-bo2zl5il5d Рік тому +3

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

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

    Fantastic tutorial!

  • @MN-yz7bp
    @MN-yz7bp 24 дні тому +1

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

  • @F.D.S
    @F.D.S Рік тому

    Great!! Thank you!

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

    Thank you. Very clear explanation.

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

    thanks for the tutorial !!!

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

    Great teacher brother.

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

    thanks for your contribution, you the best!!

  • @mariasueabiera8684
    @mariasueabiera8684 4 місяці тому +1

    Awesome tutorial especially for beginners

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

    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?

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

    Thank you!

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

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

  • @rodo2220
    @rodo2220 Місяць тому

    great video

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

      Same question

    • @1mrnewton
      @1mrnewton Рік тому

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

  • @roguephilosopher2465
    @roguephilosopher2465 6 місяців тому

    Very helpful!

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

    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.

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

    Very knowledgeable content

  • @TimothyCarney-kk7kw
    @TimothyCarney-kk7kw Рік тому

    Thanks!

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

    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?

  • @ashishbhateja
    @ashishbhateja Рік тому +9

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

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

    Cool!

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

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

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

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

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

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

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

    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?

  • @rahasyabharat4894
    @rahasyabharat4894 4 місяці тому +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

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

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

  • @ahmimo2918
    @ahmimo2918 Рік тому +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  Рік тому +2

      Right now, Finetuning with ChatGPT model is not available

  • @mohammadawwad7832
    @mohammadawwad7832 Рік тому +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 ?

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

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

  • @Investwithwisdome
    @Investwithwisdome 9 місяців тому

    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 ?

  • @Brandon-uf4dt
    @Brandon-uf4dt 2 місяці тому

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

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

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

      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.

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

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

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

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

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

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

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

      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.

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

    wow you know how to explain

  • @shreyashavaldar2076
    @shreyashavaldar2076 3 місяці тому

    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.

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

    If possible, how to set up with gradio ?

  • @maftar5
    @maftar5 20 днів тому

    How do you add context with the api endpoint?

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

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

  • @MuhammadYasir-uc9xt
    @MuhammadYasir-uc9xt Місяць тому

    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.

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

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

      I think you should try this - ua-cam.com/video/hYcKPzXh4D8/v-deo.html

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

    How to using the model in webApp like using flask

  • @SurajSharma-bh9gf
    @SurajSharma-bh9gf 11 місяців тому +6

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

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

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

    • @billythebiest_9404
      @billythebiest_9404 4 місяці тому

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

    • @ujjwalsrivastava4581
      @ujjwalsrivastava4581 2 місяці тому

      Same error guys if anyone got the solution please tell me

    • @lazycoder112
      @lazycoder112 Місяць тому

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

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

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

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

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

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

    yes

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

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

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

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

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

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

  • @ompathak3384
    @ompathak3384 4 місяці тому +1

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

  • @PANDURANG99
    @PANDURANG99 5 місяців тому

    how to deploy for users?

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

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

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

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

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

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

  • @ColabPro-ho9sx
    @ColabPro-ho9sx 2 місяці тому

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

  • @sambokhetwal
    @sambokhetwal 4 місяці тому

    Can we link chat got api with facebook graph api?

  • @rildodemarqui
    @rildodemarqui Рік тому +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?

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

    API key in freetrail is not working

  • @ashishmalhotra2230
    @ashishmalhotra2230 3 місяці тому

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

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

    • @ashishmalhotra2230
      @ashishmalhotra2230 3 місяці тому

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

    • @ujjwalsrivastava4581
      @ujjwalsrivastava4581 2 місяці тому

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

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

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

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

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

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

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

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

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

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

  • @ninasirsi2340
    @ninasirsi2340 4 місяці тому

    Where is next video

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

    Showing me rate limit error

  • @debalinaghosh6404
    @debalinaghosh6404 10 місяців тому

    can you help doing it in java?

    • @1littlecoder
      @1littlecoder  10 місяців тому

      Why so ?

    • @debalinaghosh6404
      @debalinaghosh6404 9 місяців тому

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

      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

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

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

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

    • @SatSTAR0
      @SatSTAR0 10 місяців тому

      same issue

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

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

  • @jdcrunchman999
    @jdcrunchman999 Місяць тому

    Your video is blocking the code

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

    I just hate the word...for beginners

    • @QWERTY-gp8fd
      @QWERTY-gp8fd Рік тому

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

  • @ibrahimnadeem1064
    @ibrahimnadeem1064 5 місяців тому

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

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

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

      Check if you have OpenAI credits in your account

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

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

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

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