Build Anything With ChatGPT API, Here’s How
Summary
TLDRThis video script guides viewers on creating an AI app using the Cad GPT API, even without programming knowledge. It walks through obtaining an API key from platform.open.com, setting up environment variables, and utilizing Python packages to process PDF files and access the GPT model. The tutorial aims to build a custom book summarizer app, emphasizing the ease of developing AI applications with APIs and the opportunities they present for niche industries. The script also touches on the importance of understanding AI in the upcoming era of AGI and invites viewers to join a community for staying ahead in the AI revolution.
Takeaways
- 😀 Building AI apps with APIs like OpenAI's can be done quickly even without programming knowledge.
- 🔑 The first step is to obtain an API key from the OpenAI platform, which requires a login and possible phone verification.
- 📖 The script demonstrates creating a book summarizer app using GPT-4, which can generate summaries on given topics.
- 🛠️ Essential packages for the project include 'openai', 'PiPDF2', and 'python-dotenv', which need to be installed via pip.
- 💡 It's important to keep the API key secret and to set it up in an environment file for secure access.
- 📚 The app uses a PDF processing library to read and process a book's content, excluding certain pages to avoid unwanted content.
- 📝 The script involves setting up key variables such as the model, temperature, max tokens, and topic for the summarizer.
- 🤖 The use of 'prompt engineering' is crucial to convince the AI to generate summaries without violating copyright laws.
- 📈 The script highlights the advantage of using APIs in building AI apps, making the process significantly easier than building from scratch.
- 💼 The potential for building successful businesses using APIs is underscored by the example of an AI startup valued at $520 million.
- 🌐 The script encourages joining a community at the forefront of AI to gain an advantage in the AI Revolution and prepare for AGI.
Q & A
What is the first step to start building an AI app with the Cad GPT API?
-The first step is to obtain an API key by visiting platform.open.com and using the same login credentials as on chbd.
Why might a new user need to verify their phone number on the platform.open.com?
-A new user might need to verify their phone number as a security measure, which is often required when accessing the API keys section for the first time.
What is the importance of keeping the API key secret?
-The API key should be kept secret to prevent unauthorized access and potential misuse of the API services, as it is tied to the user's account and usage limits.
What is the purpose of creating an environment file for the Open AI API key?
-Creating an environment file helps to securely store sensitive information like the API key, making it accessible within the application without hardcoding it into the source code.
What is the book that the speaker wants to summarize using the GPT 4 model?
-The speaker wants to summarize 'The Almanack of Naval Ravikant' by Eric Jorgensen using the GPT 4 model.
Why is it necessary to remove certain pages from the PDF before processing it with the GPT 4 model?
-Certain pages may contain content that the AI does not like or find useful, such as copyright information or irrelevant sections, which is why they are removed to streamline the summarization process.
What is the significance of the 'temperature' setting in the GPT model?
-The 'temperature' setting affects the randomness of the model's output. A lower temperature makes the model more deterministic, while a higher temperature increases randomness.
What is the role of the 'Max tokens' setting in the GPT model?
-The 'Max tokens' setting determines the maximum number of tokens the model will generate in its response, which helps to control the length of the output.
Why is prompt engineering important when summarizing copyrighted material with AI?
-Prompt engineering is important to convince the AI that it is generating a summary of its own text, rather than copyrighted material, to avoid copyright infringement issues.
How can one utilize the GPT API for building AI apps without prior programming knowledge?
-One can utilize the GPT API for building AI apps by following guides and documentation, using tools like CH GPT to explain code, and learning by building projects step by step.
What is the potential cost implication of using the GPT API for summarizing a large text?
-The cost depends on the number of tokens processed, but for summarizing a large text like a 242-page book, it could be around $1 to $2, assuming efficient use of the API.
Outlines
🔑 Getting Started with the GPT API
The script begins by introducing the ease of creating an AI app using the GPT API, even without programming knowledge. It details the process of obtaining an API key from platform.open.com, emphasizing the importance of keeping it secret. The creator then outlines the initial steps to set up the environment for the app, including installing necessary packages like 'openai', 'PiPDF2', and 'python-dotenv'. The goal is to build a custom book summarizer using GPT-4, which can provide insights on a given topic from a 200-page book. The script also touches on the broader implications of APIs in simplifying AI app development and their role in the AI Revolution.
📚 Building the Custom Book Summarizer
This paragraph delves into the technical aspects of building the book summarizer. It discusses the installation of the PDF package for processing PDF files and the use of the GPT API for text summarization. The script explains how to set up key variables such as the model, temperature, and max tokens for the GPT API. It also introduces the concept of prompt engineering to convince the AI to summarize copyrighted material by treating it as if it's the user's own text. The chosen book for summarization is 'The Almanack of Naval Ravikant' by Eric Jorgensen, which is available online for free.
🤖 Implementing the Summarization Function
The script continues with the implementation of the summarization function, explaining how to interact with the GPT API to get a response. It details the creation of a helper function to simplify the process and the importance of referring to the official documentation for any changes. The function is designed to return the content of the first choice from the API response, which contains the summarized text. The script also includes a test run of the function with a simple prompt to ensure it works correctly. Additionally, it discusses the cost implications of using the API and the potential for building niche apps with APIs, highlighting the opportunities they present in the AI industry.
Mindmap
Keywords
💡API Key
💡GPT (Generative Pre-trained Transformer)
💡Python
💡Environment Variable
💡PDF2TXT
💡Prompt Engineering
💡Token
💡Custom Book Summarizer
💡Temperature
💡Max Tokens
💡AI Revolution
Highlights
Building AI apps using the Cad GPT API is achievable within minutes even without programming knowledge.
An API key is required and can be obtained from platform.open.com using the same login as on Chad.
New users may need to verify their phone number to access API keys.
Creating a new secret key is crucial, and it should remain confidential.
The tutorial aims to build an app like Blinkist, which provides book summaries using GPT 4.
Importing necessary packages such as OS, Pi PDF 2, and open AI is essential for the app development.
Packages need to be installed using pip, and open AI's documentation provides a guide for beginners.
Environment variables must be loaded to access the API key within the main.py file.
The language model GPT 4 is chosen for its large token window and capabilities.
APIs have significantly simplified the process of building AI apps, as highlighted by the speaker.
The potential of AI startups built on top of APIs like GPT 4 is enormous, as exemplified by a $520 million valuation.
Knowledge of APIs and building AI apps is a significant advantage in the AI Revolution.
The speaker introduces the New Society, a community for those at the forefront of AI.
Key variables such as model, temperature, max tokens, and topic are set up for the app.
Prompt engineering is necessary to convince the AI to summarize copyrighted material.
The book 'Almanack of Naval Ravikant' by Eric Jorgenson is chosen for summarization.
PDF files require processing, which is facilitated by the Pi PDF 2 package.
A test API call is made to ensure the setup is correct and to receive a response from GPT 4.
The cost of using the API is monitored, with an expectation of minimal expenditure.
Building apps with APIs presents an opportunity for niche markets that large companies may overlook.
The speaker offers resources and a community for those interested in AI development and startups.
Transcripts
with the cad GPT API you can build your
own AI app in a matter of minutes even
if you know nothing about python or
programming the first thing you need is
an API key you have to go to platform.
open.com and use the same exact login as
you would on chbd and boom we're inside
now go on to the left and click on API
keys if you've never been here before
you might need to verify your phone
number now after you verifi the phone
number it should look something like
this now as you can see I already have
some API Keys over here and I also have
an organization David Andre you will
probably have this empty and that's fine
all we have to do is create a new secret
key and as the name suggests it's secret
so do not share this with anybody so
let's do tutorial and create secret key
now as it says you won't be able to view
it again so make sure to copy it I'm
going to go into vs code and put it as a
comment which is actually not a good
practice so instead what I'm going to do
is I'm going to create the environment
uh file right away open AI API key and
assign this now you might be thinking
but David what are you going to build
well I want to make an app like blinkist
you know it gives you book summaries now
obviously we won't have fancy UI like
this but we will use GPD 4 to create
custom book summarizer where we can give
it a topic and it gives us all di
mentions of that topic in a 200 Page
book now the first thing I'm going to do
is I'm going to import some packages OS
we'll be using this to access the
environment variable Pi PDF 2 will be
you know processing the PDF files
through that open AI obviously this is
for accessing the GPD for API VSS code
is not recognizing these packages and
that's because I have not in sold them
now actually open AI if you go to
documentation quick start they have an
excellent guide on getting started right
by the way you can always ask Che gbts
to install these packages what you would
normally do is go into terminal and
create a new terminal and do you know
pip install open AI but actually I'm
using K here pip install open AI so as
you can see it's installing the all the
packages pip install P PDF 2 and we also
need n now this one is a little
different
this one is uh pip install python Das
donf okay and as you can see it's no
longer highlighted which is good the
next thing is we need to load the
environment variable because right now
we have it saved but it's not actually
accessible in the main.py file so I'm
going to paste this line of code all
right so let's set up the key variables
we will need for this the first one is
the model you know the language model if
we go into documentation and go into
models you'll see like all the different
models open air offers obviously we
going to go for GPT 4 but yeah as you
can see it's 128,000 token window which
is four times bigger than CH GPT and
this is like only one of the main
reasons why apis are awesome like apis
have made building AI apps 100 times
easier imagine if there were no apis
like from the one from open AI or Google
Deep Mind like imagine if there wasn't
an any API available we would have to
build those language models from scratch
or use open source ones and run like
inference locally that's much more
complicated than just using open a API
so this has made building AI apps 100
times easier in fact people are building
entire companies with this exact method
let's look at perplexity valuation this
AI startup is valued at $520 million
that's half a billion dollars and it was
built on top of the gp4 API like knowing
how to use API will give you a massive
advantage in the AI Revolution once AGI
is created it won't matter what your
income is or what college degree you
have the thing that will matter by far
the most is what you know and who you
know this is precisely why I created the
new Society a community of people at The
Cutting Edge of AI so if you want to be
among the people who are building the
future make sure to join first link in
the description now let's continue
setting up the key variables we have the
model but we also need the temperature
which 0.7 is the default one inside of
jgpt I'm going to use 0.3 to make the
model a little more deterministic little
less r random we also need uh Max tokens
let's do like 500 that's pretty standard
I think and I'm going to also set the
topic which is going to be what the AI
makes the summary on so we can leave
this empty for now now we have the key
variables actually I'm going to create
one more file and that's going to be
prom. py and this is going to be where
we store the proms so these are the
proms I'm working with and there are two
proms right so it's intimidating but
it's kind of simple at the same time
there's a system message which you know
has the custom instructions system
prompt whatever you want to call it and
then we have a function that creates a
prompt the reason why we have this is
that I can reference the book from the
main python file and I can also change
the topic so this is a variable and it
can change the reason I have to do such
prompt engineering is because if you
don't do this the AI will actually
refuse to give you book summaries
because it's copyrighted material so you
have to go try hard and like convince it
that it's your own text as you can see
like I've over the past 3 years I have
dedicated myself to this work like you
literally have to create a story that
this is your book now the book I've
chosen to summarize is the almanak of
Naval ravikant by Eric Jorgenson this
one you know has a free pdf online 242
pages and it's honestly one of the best
books I've ever read okay so now we have
the PDF right here there's a lot of
garbage in here and that's why we
installed the PDF package is because
we're going to use that to actually read
the PDF because it's not as simple as
reading a txt file okay yeah I read the
PDF file so let's do an empty book
variable file path equals and then we do
naval PDF you know what I'm going to put
this on hold and I'm going to do a test
API call and in here we need to do
system message and we we need to
reference this system message to do that
we have to import prompts so let's go in
here and import
prompts and then we can do prompt.
system message beautiful obviously we
also need the main prompt prompt.
generate prompt now actually in here I'm
going to pass the book which I've
deleted so let's put it back in empty
variable for now and topic for a
reference of the of the topic that's I
mean I spent a good hour on this just
trying to convince gbd4 that it's fine
to summarize the book it's good to
create a helper function and make it a
bit simpler also it's smart to go into
the documentation because every few
months this gets changed quite a bit we
have the two first two lines and we can
copy the rest paste it here and I'm
going to comment it out boom now we can
name the function like I don't know get
summary right so let's follow the
official documentation completion equals
client. chat. completions doc create and
actually in here we could do it like
this you know but I think I'm going to
simplify it that way it's like much
easier to see what's actually going on
so let's go back to the function
messages equals messages we also do
temperature equals temperature and Max
tokens equals Max tokens and now we have
to return the completion return
completion choices message and this is
not everything because we only need the
content because if we go into API and
actually go into chat you can see how it
looks like this is how the response
looks so this is how it looks right and
what we really need is we need choices
the First Choice index zero so we have
that you know completion. choices zero
and then we need the message
message and specifically the content we
don't need the roll we need the content
so this is how we access exactly you
know the good part and this should be
the main part done so we can actually
delete this and you know we need to
print summary to test it out let's do
something simple right so this is just a
string we can do you are a helpful
assistant this is classic and for here
you know you can say like list out 10
facts about AI whatever and if we do
this we should get an API response
hopefully oh there it is we've gotten a
response from gbd4 Turbo and actually
what's fun let's go
into um API keys and let's go into what
is it usage okay usage this is my
current spend for today so we will see
how much it costs at the end hopefully
all of this is simple by the way what
you can do if like anything doesn't make
sense just go into CH GPT and say
explain the following code as if I'm a
beginner boom paste it in here and it
will explain it you don't even have to
copy paste it you can just screenshot it
boom explain every line of code and then
yeah you can just paste a screenshot
from any video you watch like GPD vision
is so amazing now the topic actually
let's set it now so I don't forget let's
do money because I know that's mentioned
in the book like you can consume an
entire 242 page book in a matter of
minutes once you have this running we
also need the file path as we had it
before Naval PDF and now we need to open
it this I'm going to delete because we
actually need to remove the first like
23 pages and the last 30 pages for some
reason when the AI sees contents it
doesn't like that so I literally had to
remove like 53 pages from the book you
know unfortunately we can't have it so
simple you know this is how we open the
file at the file path we save it as a
file variable then we do reader which is
a new variable and we assign to it PDF
reader from the library next we need to
do total pages and that equals to length
of reader. pages and for starting page
we need to start page equals 23 and end
page equals total Pages minus 30 now we
need a for Loop and as you can see cop
palet is already suggesting that for us
but let's you know let's write it out
why not for for every page number in
range and you know again this is range
of numbers starting with start page 23
and end page with a total Pages minus 30
and then for every page we should do
page equals reader. Pages page number
and then we do simply we append the page
to our book with you know we can do a
new line character or just a space let's
do a space and actually should be book
obviously so now this should give us a
book variable with the entire text of
the PDF print book to test it out now as
you can see it clearly worked because we
have the entire book printed in here we
have to change our messages to system
message and to prompt and then we use
use this simple function let us change
the topic summary on money happiness
Fitness like the navel book is about a
lot of topics again I definitely
recommend you read it it's amazing book
shout out Eric Jorgenson we should have
everything in order let's do a test run
and fingers crossed that the AI doesn't
refuse because we're literally pasting
in I mean we can just go to
wordcounter.net and see how many words
this is obviously we removed some pages
but still 46,000 words so we removed
probably like it's probably like 40,000
words which to convert to tokens we have
to do this is 53,000 tokens so like half
of the context window of gb4 and as you
can see we got a response and let's
actually see how much money we've spent
let's go into billing usage refresh it
probably still needs to update but yeah
it's going to be like you know1 or $2 at
most one thing I want you to understand
is that building apps with apis is a
massive opportunity there are thousands
of small niches that big companies like
open AR or deep mind will never go after
niches Industries where you actually
have an unfair Advantage a lot of
experience so you know what the people
need like launching a startup has never
been easier open air tells you
everything and also we have this amazing
tool cgbd as you can see it broke down
every single line of code and explained
it you don't even have to know
programming you can just learn while
you're building something now I'm going
to upload all of this code including the
proms in here into this module in my
community where I also upload all my
custom instructions great custom
instructions from others all the code
from my past videos the projects I've
built in unity my custom gpds as well as
a bunch of other stuff if you want to
prepare for the AI Revolution and don't
want to be left behind like most people
will make sure to join for Link in the
description
浏览更多相关视频
How To Build Your Own AI With ChatGPT API
3. OpenAI API Python - Earnings Call Summarization
手把手教大家搭建Autogen|微軟的多智能體協作系統|多AI協調|#multi-agent #autogen #openai #chatpgt #gpt4 #gpt #web3
How to Fine Tune GPT3 | Beginner's Guide to Building Businesses w/ GPT-3
Crie dashboards incríveis usando PYTHON, STREAMLIT e CHATGPT
ChatGPT - OpenAI API w Excelu (za darmo)
5.0 / 5 (0 votes)