OpenAI API Tutorial using Python | How to use OpenAI GPT-3 API - Ada Babbage Curie Davinci | Edureka

edureka! · Intermediate ·🧠 Large Language Models ·2y ago

Key Takeaways

Builds an OpenAI GPT-3 API integration using Python with Ada, Babbage, Curie, and Davinci language models

Full Transcript

hey everyone welcome to this tutorial on how to use open AI API using python this is something I was going through recently and I found it so interesting that I wanted to share it with you now most of you all must have heard of chat CPT super trending AI text generator that generates responses based on user prompts this technology was developed by a company called as open EI and along with chat GPT they released a few apis that are super convenient to use in your code you can find these models if you search for openai.com API pricing once you're in this page if you scroll down a bit you will be able to see a section called as language models now this section has a collection of Base models that you can directly use in your code there are currently four options available which is Ada Babbage Curie and da Vinci now each of these models has slightly better capabilities than the previous one and depending on these capabilities prices can also differ now the Ada model which is the least capable out of these four has the fastest response time and DaVinci is the most capable while being the slowest out of all these options now coming to the pricing you can see that the prices are mentioned per thousand tokens so what is tokens you can think of tokens as words and like it is mentioned over here 1000 tokens is approximately 750 words you will be charged based on how many tokens you use in your program if you want to look at the differences then there is a separate page for that too over here you can see the details capabilities and restrictions of each of these models all these models are developed on the gpt3 models and The DaVinci model which is the most capable has a max request limit of 4000 tokens and the training data was taken up to June of 2021. the query model is slightly less capable than the DaVinci model but it is faster and costs way less than DaVinci it has a max limit of 2048 tokens and you can also see that it was trained only until October of 2019. the Babbage model is another option which is capable of straightforward tasks and is very fast while giving your answers at a fraction of the cost and the Ada model is super fast while being restricted to very simple tasks now just because the capabilities differ doesn't really mean that the error is worse than DaVinci it all depends on your use case if your use case is very simple and straightforward you will be better off using either or package and if you have some complex mathematical tasks then you can use a text generator like DaVinci while using these models in code you will also have to insert some parameters based on this parameter the prices can also heavily differ to use the open AI apis you will first need to head over to openai.com once you are in here you will find an option called as API on the top click on that and then login to your account if you don't have an account yet then I highly recommend that you make one now once you log into openai you will find yourself in a web page similar to this what we need to do right now is head over to your account and then click on view API keys once you're here click on this button that says create new secret key once this key has been generated make sure that you copy this key let's just name this key as openai dot API key now before we execute this code we will need to install a library called as openai so let's just do that by using the PIP command as you can see I have already installed open AI in my system but if you haven't already then this command will install open EA library in your system once that is done you can get rid of that cell and import the openai library into your code now let's run this yes your key needs to be passed as a string now let's run it again and you can see that it has executed successfully now let's Define a simple prompt we'll say variable prompt is equal to and then a message let me just type Hi how are you today now this will be our prompt now that we have access to open Ai and we have defined a prompt the only thing left is to generate a response now to generate the response let's start by typing variable response equal to open AI dot completion dot create now this is the function that you use to generate responses inside the create method we will start defining our parameters the first parameter that we are going to Define is the type of engine that we will use so you can just type engine equal to and then you can specify the model that you will use if you want the details of the models you will find it over here these are the models that you can use in your code let's first start with the Ada model the next parameter that you will need to specify is your prompt this parameter will be passed to your model to generate a response since tokens are expensive it's best practice to set the max limit to your tokens you can do this by typing the max tokens parameter and setting a value for it let me just set it to 50 and one more interesting parameter is the number of responses that you want to generate so we can set it as n equal to 1. this will tell the model to generate only one response another interesting parameter is the temperature parameter this parameter will tell the model how flexible it can be with the response this value can be anywhere between 0 and 1. a temperature of 1 will make the generated response quite formal while value of 0.1 will keep the response extremely creative keep in mind that lesser temperatures can also make your responses factually incorrect and when I say one it will show one when I see 0 it will show zero and then 0.1 for now let's keep the temperature value at 0.5 with this we have generated the response to view this response you will just need to write one more line of code this can be done by using the print function and then typing response.choices now choices is a list of generated response since we have set n as 1 we'll be getting only one output so our responses Choice index is zero we also need to see the text format of the response so we type dot text at the end once we execute this code you can see that our model has generated a response you can also change the model or the number of responses if you don't find the answer satisfactory and now you can see that our response is more friendly so guys this is how we use open AI API and python I hope you found this tutorial useful and if you have any questions do mention them down in the comment section I will make sure to give you more interesting content like this in the future so until then Happy learning

Original Description

This Edureka video on 𝐎𝐩𝐞𝐧𝐀𝐈 𝐀𝐏𝐈 𝐓𝐮𝐭𝐨𝐫𝐢𝐚𝐥 𝐮𝐬𝐢𝐧𝐠 𝐏𝐲𝐭𝐡𝐨𝐧 will show how you can use OpenAI GPT-3 API using Python. You will learn about different OpenAI API language models (Ada, Babbage, Curie, Davinci) including there features and pricing. At the end of this OpenAI ChatGPT API tutorial, you will see a hands-on demo in python. 🔥𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐂𝐡𝐚𝐭𝐆𝐏𝐓 𝐂𝐨𝐮𝐫𝐬𝐞 - 𝐁𝐞𝐠𝐢𝐧𝐧𝐞𝐫𝐬 𝐭𝐨 𝐀𝐝𝐯𝐚𝐧𝐜𝐞𝐝: https://www.edureka.co/openai-chatgpt-training-course ⏩ Edureka Chat GPT Explained Playlist: http://bit.ly/3HGRy3G #ChatGPTAPI #edureka #OpenAIAPI #chatgptexplained #chatgpt #openai #chatgpttutorial #chatgpt3 #ai #nlp #artificialintelligence Subscribe to our channel to get video updates. Hit the subscribe button above: https://goo.gl/6ohpTV 🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐎𝐧𝐥𝐢𝐧𝐞 𝐓𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐚𝐧𝐝 𝐂𝐞𝐫𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬 🔵 DevOps Online Training: http://bit.ly/3VkBRUT 🌕 AWS Online Training: http://bit.ly/3ADYwDY 🔵 React Online Training: http://bit.ly/3Vc4yDw 🌕 Tableau Online Training: http://bit.ly/3guTe6J 🔵 Power BI Online Training: http://bit.ly/3VntjMY 🌕 Selenium Online Training: http://bit.ly/3EVDtis 🔵 PMP Online Training: http://bit.ly/3XugO44 🌕 Salesforce Online Training: http://bit.ly/3OsAXDH 🔵 Data Science Online Training: http://bit.ly/3V3nLrc 🌕 CEHv12 Online Training: http://bit.ly/3Vhq8Hj 🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐑𝐨𝐥𝐞-𝐁𝐚𝐬𝐞𝐝 𝐂𝐨𝐮𝐫𝐬𝐞𝐬 🔵 DevOps Engineer Masters Program: http://bit.ly/3Oud9PC 🌕 Cloud Architect Masters Program: http://bit.ly/3OvueZy 🔵 Data Scientist Masters Program: http://bit.ly/3tUAOiT 🌕 Big Data Architect Masters Program: http://bit.ly/3tTWT0V 🔵 Business Intelligence Masters Program: http://bit.ly/3UZPqJz 🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐔𝐧𝐢𝐯𝐞𝐫𝐬𝐢𝐭𝐲 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐬 🔵 Artificial and Machine Learning PGD with E&ICT Academy NIT Warangal: http://bit.ly/3OuZ3xs 🌕 Professional Certificate Program in DevOps with Purdue University: https://bit.ly/3Ov52lT 🔵 Advanced Certificat
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from edureka! · edureka! · 4 of 60

1 ChatGPT Not Working - 4 Fixes | How To Fix ChatGPT Not Working | Why Is ChatGPT Not Working |Edureka
ChatGPT Not Working - 4 Fixes | How To Fix ChatGPT Not Working | Why Is ChatGPT Not Working |Edureka
edureka!
2 Advanced Java script Tutorial | JavaScript Training | JavaScript Programming | Edureka Rewind
Advanced Java script Tutorial | JavaScript Training | JavaScript Programming | Edureka Rewind
edureka!
3 Java script interview question and answers | Java script training | Edureka Rewind
Java script interview question and answers | Java script training | Edureka Rewind
edureka!
OpenAI API Tutorial using Python | How to use OpenAI GPT-3 API - Ada Babbage Curie Davinci | Edureka
OpenAI API Tutorial using Python | How to use OpenAI GPT-3 API - Ada Babbage Curie Davinci | Edureka
edureka!
5 What is Unsupervised Learning ? | Unsupervised Learning Algorithms| Machine Learning | Edureka
What is Unsupervised Learning ? | Unsupervised Learning Algorithms| Machine Learning | Edureka
edureka!
6 Top 10 Applications of Machine Learning in 2023 | Machine Learning  Training | Edureka Rewind - 7
Top 10 Applications of Machine Learning in 2023 | Machine Learning Training | Edureka Rewind - 7
edureka!
7 Machine Learning Engineer Career Path in 2023  | Machine Learning Tutorial | Edureka Rewind - 6
Machine Learning Engineer Career Path in 2023 | Machine Learning Tutorial | Edureka Rewind - 6
edureka!
8 10 Must Have Machine Learning Engineer Skills That Will Get You Hired   | Edureka Rewind - 7
10 Must Have Machine Learning Engineer Skills That Will Get You Hired | Edureka Rewind - 7
edureka!
9 Data Structures in Python | Data Structures and Algorithms in Python | Edureka | Python Live - 5
Data Structures in Python | Data Structures and Algorithms in Python | Edureka | Python Live - 5
edureka!
10 Python Lists | List in Python | Python Training  | Edureka  Rewind
Python Lists | List in Python | Python Training | Edureka Rewind
edureka!
11 Predictive Analysis Using Python | Learn to Build Predictive Models | Python Training | Edureka
Predictive Analysis Using Python | Learn to Build Predictive Models | Python Training | Edureka
edureka!
12 Machine Learning Tutorial | Machine Learning Algorithm | Machine Learning Engineer Program | Edureka
Machine Learning Tutorial | Machine Learning Algorithm | Machine Learning Engineer Program | Edureka
edureka!
13 How to use Pandas in Python | Python Pandas Tutorial  | Python Tutorial  |  Edureka  Rewind
How to use Pandas in Python | Python Pandas Tutorial | Python Tutorial | Edureka Rewind
edureka!
14 Parameters in Tableau | Tableau Parameters Examples | Tableau Tutorial  | Edureka Rewind
Parameters in Tableau | Tableau Parameters Examples | Tableau Tutorial | Edureka Rewind
edureka!
15 Top 10 Reasons to Learn Tableau in 2023  | Tableau Certification | Tableau | Edureka Rewind
Top 10 Reasons to Learn Tableau in 2023 | Tableau Certification | Tableau | Edureka Rewind
edureka!
16 Tableau Developer Roles & Responsibilities | Become A Tableau Developer | Tableau | Edureka Rewind
Tableau Developer Roles & Responsibilities | Become A Tableau Developer | Tableau | Edureka Rewind
edureka!
17 Deep Learning With Python | Deep Learning Tutorial For Beginners | Edureka  Rewind
Deep Learning With Python | Deep Learning Tutorial For Beginners | Edureka Rewind
edureka!
18 Realtime Object Detection  | Object Detection with TensorFlow | Edureka | Deep Learning Rewind - 2
Realtime Object Detection | Object Detection with TensorFlow | Edureka | Deep Learning Rewind - 2
edureka!
19 Top 20 Tableau Tips and Tricks in 20 Minutes | Tableau Tutorial | Tableau Training  | Edureka Rewind
Top 20 Tableau Tips and Tricks in 20 Minutes | Tableau Tutorial | Tableau Training | Edureka Rewind
edureka!
20 Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind -  5
Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind - 5
edureka!
21 ReactJS Installation Tutorial | ReactJS Installation On Windows | ReactJS Tutorial | Edureka Rewind
ReactJS Installation Tutorial | ReactJS Installation On Windows | ReactJS Tutorial | Edureka Rewind
edureka!
22 Phases in Cybersecurity  | Cybersecurity Training | Edureka | Cybersecurity Rewind - 2
Phases in Cybersecurity | Cybersecurity Training | Edureka | Cybersecurity Rewind - 2
edureka!
23 What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka Rewind
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka Rewind
edureka!
24 Cybersecurity Frameworks Tutorial | Cybersecurity Training | Edureka | Cybersecurity Rewind- 2
Cybersecurity Frameworks Tutorial | Cybersecurity Training | Edureka | Cybersecurity Rewind- 2
edureka!
25 React vs Angular 4  | Angular 2 vs React | React & Angular | ReactJS Training | Edureka Rewind - 5
React vs Angular 4 | Angular 2 vs React | React & Angular | ReactJS Training | Edureka Rewind - 5
edureka!
26 ReactJS Components Life-Cycle Tutorial  | React Tutorial for Beginners  | Edureka Rewind
ReactJS Components Life-Cycle Tutorial | React Tutorial for Beginners | Edureka Rewind
edureka!
27 Ethical Hacking using Kali Linux | Ethical Hacking Tutorial | Edureka | Cybersecurity Rewind - 3
Ethical Hacking using Kali Linux | Ethical Hacking Tutorial | Edureka | Cybersecurity Rewind - 3
edureka!
28 Types Of Artificial Intelligence | Artificial Intelligence Explained | What is AI? | Edureka
Types Of Artificial Intelligence | Artificial Intelligence Explained | What is AI? | Edureka
edureka!
29 Top 10 Applications Of Artificial Intelligence in 2023 | Artificial Intelligence| Edureka Rewind
Top 10 Applications Of Artificial Intelligence in 2023 | Artificial Intelligence| Edureka Rewind
edureka!
30 The Future of AI | How will Artificial Intelligence Change the World in 2023? | Edureka Rewind
The Future of AI | How will Artificial Intelligence Change the World in 2023? | Edureka Rewind
edureka!
31 What is Artificial Intelligence | Artificial Intelligence Tutorial For Beginners | Edureka Rewind
What is Artificial Intelligence | Artificial Intelligence Tutorial For Beginners | Edureka Rewind
edureka!
32 Google Cloud IAM | Identity & Access Management on GCP  | Edureka | GCP Rewind - 5
Google Cloud IAM | Identity & Access Management on GCP | Edureka | GCP Rewind - 5
edureka!
33 Google Cloud AI Platform Tutorial | Google Cloud AI Platform   | GCP Training | Edureka Rewind
Google Cloud AI Platform Tutorial | Google Cloud AI Platform | GCP Training | Edureka Rewind
edureka!
34 Projects in Google Cloud Platform  | GCP Project Structure  | GCP Training | Edureka Rewind
Projects in Google Cloud Platform | GCP Project Structure | GCP Training | Edureka Rewind
edureka!
35 How to Become a Data Scientist | Data Scientist Skills | Data Science Training  | Edureka Rewind - 3
How to Become a Data Scientist | Data Scientist Skills | Data Science Training | Edureka Rewind - 3
edureka!
36 Agglomerative and Divisive Hierarchical Clustering Explained | Data Science Training | Edureka Live
Agglomerative and Divisive Hierarchical Clustering Explained | Data Science Training | Edureka Live
edureka!
37 Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind -  5
Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind - 5
edureka!
38 Data Science Project - Covid-19 Data Analysis | Python Training | Edureka | DS Rewind - 6
Data Science Project - Covid-19 Data Analysis | Python Training | Edureka | DS Rewind - 6
edureka!
39 What is Honeycode? | Introduction to Honeycode | Edureka
What is Honeycode? | Introduction to Honeycode | Edureka
edureka!
40 Difference between Amazon AWS and Google Cloud | GCP Training Google Cloud | Edureka Live
Difference between Amazon AWS and Google Cloud | GCP Training Google Cloud | Edureka Live
edureka!
41 DevOps Lifecycle | Introduction To DevOps | DevOps Tools | What is DevOps? | Edureka Rewind
DevOps Lifecycle | Introduction To DevOps | DevOps Tools | What is DevOps? | Edureka Rewind
edureka!
42 Introduction to DevOps | DevOps Tutorial for Beginners | DevOps Tools | DevOps | Edureka Rewind
Introduction to DevOps | DevOps Tutorial for Beginners | DevOps Tools | DevOps | Edureka Rewind
edureka!
43 How to Create Login System using Python | Python Programming Tutorial | Edureka Rewind
How to Create Login System using Python | Python Programming Tutorial | Edureka Rewind
edureka!
44 Python Developer | How to become Python Developer | Python Tutorial  | Edureka Rewind
Python Developer | How to become Python Developer | Python Tutorial | Edureka Rewind
edureka!
45 How to become a Data Engineer | Complete Roadmap to become a Data Engineer| Data Engineer |  Edureka
How to become a Data Engineer | Complete Roadmap to become a Data Engineer| Data Engineer | Edureka
edureka!
46 Azure Data Engineer Certification [DP 203] | How to Become Azure Data Engineer [2023] | Edureka
Azure Data Engineer Certification [DP 203] | How to Become Azure Data Engineer [2023] | Edureka
edureka!
47 Data Analyst vs Data Engineer vs Data Scientist | Data Analytics Masters Program  | Edureka Rewind
Data Analyst vs Data Engineer vs Data Scientist | Data Analytics Masters Program | Edureka Rewind
edureka!
48 DevOps Engineer day-to-day Activities | DevOps Engineer Responsibilities | Edureka Rewind
DevOps Engineer day-to-day Activities | DevOps Engineer Responsibilities | Edureka Rewind
edureka!
49 How to Become a DevOps Engineer?  | DevOps Engineer Roadmap | Edureka | DevOps Rewind
How to Become a DevOps Engineer? | DevOps Engineer Roadmap | Edureka | DevOps Rewind
edureka!
50 How to Become a Data Engineer? | Data Engineering Training | Edureka
How to Become a Data Engineer? | Data Engineering Training | Edureka
edureka!
51 How To Become A Big Data Engineer? | Big Data Engineer Roadmap | Edureka Rewind
How To Become A Big Data Engineer? | Big Data Engineer Roadmap | Edureka Rewind
edureka!
52 Python Integration for Power BI and Predictive Analytics | Power BI Training | Edureka
Python Integration for Power BI and Predictive Analytics | Power BI Training | Edureka
edureka!
53 Power BI KPI Indicators Tutorial | Custom Visuals In Power BI | Power BI Training  | Edureka Rewind
Power BI KPI Indicators Tutorial | Custom Visuals In Power BI | Power BI Training | Edureka Rewind
edureka!
54 Apache HBase Tutorial For Beginners | What is Apache HBase? | Big Data Training | Edureka Rewind
Apache HBase Tutorial For Beginners | What is Apache HBase? | Big Data Training | Edureka Rewind
edureka!
55 Big Data Hadoop Tutorial For Beginners  | Hadoop Training | Big Data Tutorial  | Edureka  Rewind
Big Data Hadoop Tutorial For Beginners | Hadoop Training | Big Data Tutorial | Edureka Rewind
edureka!
56 Big Data Analytics  | Big Data Analytics Use-Cases | Big Data Tutorial | Edureka Rewind
Big Data Analytics | Big Data Analytics Use-Cases | Big Data Tutorial | Edureka Rewind
edureka!
57 What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training  | Edureka  Rewind
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | Edureka Rewind
edureka!
58 Triggers in Salesforce | Salesforce Apex Triggers | Salesforce  Tutorial  | Edureka Rewind
Triggers in Salesforce | Salesforce Apex Triggers | Salesforce Tutorial | Edureka Rewind
edureka!
59 How To Become A Salesforce Developer | Salesforce For Beginners| Salesforce Training  Edureka Rewind
How To Become A Salesforce Developer | Salesforce For Beginners| Salesforce Training Edureka Rewind
edureka!
60 Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial | Edureka Rewind
Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial | Edureka Rewind
edureka!

Related Reads

Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →