Build Anything With ChatGPT API, Here’s How

David Ondrej
20 Feb 202412:11

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

00:00

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

05:01

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

10:02

🤖 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

An API key is a unique identifier used to authenticate a user, developer, or calling program to an API. In the context of the video, it's the first step to access the GPT API, allowing the user to build AI applications. The script mentions obtaining an API key from 'platform.open.com' and emphasizes its secrecy, indicating its importance in the authentication process.

💡GPT (Generative Pre-trained Transformer)

GPT stands for Generative Pre-trained Transformer, which is a type of AI language model capable of generating human-like text based on the input it receives. The video discusses using GPT 4 to create a custom book summarizer, highlighting the model's ability to process large amounts of text and generate summaries, which is central to the video's theme of building AI apps.

💡Python

Python is a high-level programming language used for a wide range of applications, including building AI apps. Although the video suggests that one can build an AI app without knowing Python, it is implied that some knowledge of Python is necessary for more advanced app development, as the script later discusses importing Python packages.

💡Environment Variable

Environment variables are a set of dynamic values in the operating system that can affect the way running processes behave. In the video, the API key is stored as an environment variable to keep it secure and accessible within the application, as demonstrated when the script mentions creating an '.env' file to store the Open AI API key.

💡PDF2TXT

PDF2TXT refers to the process or software that converts Portable Document Format (PDF) files into plain text. The script mentions using 'pdf2txt' to process PDF files, which is essential for the app's functionality since it needs to extract text from a PDF to summarize its content.

💡Prompt Engineering

Prompt engineering is the art of designing input prompts for AI models to elicit desired responses. The video discusses creating a system message and a main prompt to convince the GPT model to summarize copyrighted material by treating it as the user's own text, which is a critical part of the app's functionality.

💡Token

In the context of AI language models, a token refers to the basic units of text, such as words or characters, that the model processes. The script mentions a 'token window' of GPT 4, which is the maximum number of tokens the model can process at once, and the conversion of words to tokens for processing.

💡Custom Book Summarizer

A custom book summarizer is an AI application that can generate summaries of books based on specific topics or instructions. The video's theme revolves around building such an app using GPT 4, where the user can input a topic, and the app provides a summary of that topic from a book.

💡Temperature

In AI, temperature refers to a parameter that controls the randomness of the model's output. A lower temperature makes the model more deterministic, while a higher temperature increases randomness. The script sets the temperature to 0.3 to make the book summarizer's output more predictable.

💡Max Tokens

Max tokens is a parameter that specifies the maximum number of tokens the AI model will generate in its response. The script sets this to 500, indicating the model will not produce more than 500 tokens in the summary, which is a way to control the length of the output.

💡AI Revolution

The AI Revolution refers to the significant shift in technology, business, and society due to advancements in artificial intelligence. The video mentions this term to emphasize the importance of understanding and utilizing AI technologies, like APIs, to stay ahead in this transformative era.

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

play00:00

with the cad GPT API you can build your

play00:02

own AI app in a matter of minutes even

play00:05

if you know nothing about python or

play00:07

programming the first thing you need is

play00:08

an API key you have to go to platform.

play00:12

open.com and use the same exact login as

play00:14

you would on chbd and boom we're inside

play00:17

now go on to the left and click on API

play00:19

keys if you've never been here before

play00:21

you might need to verify your phone

play00:22

number now after you verifi the phone

play00:24

number it should look something like

play00:25

this now as you can see I already have

play00:26

some API Keys over here and I also have

play00:29

an organization David Andre you will

play00:31

probably have this empty and that's fine

play00:33

all we have to do is create a new secret

play00:35

key and as the name suggests it's secret

play00:36

so do not share this with anybody so

play00:38

let's do tutorial and create secret key

play00:40

now as it says you won't be able to view

play00:42

it again so make sure to copy it I'm

play00:44

going to go into vs code and put it as a

play00:46

comment which is actually not a good

play00:47

practice so instead what I'm going to do

play00:49

is I'm going to create the environment

play00:51

uh file right away open AI API key and

play00:54

assign this now you might be thinking

play00:57

but David what are you going to build

play00:59

well I want to make an app like blinkist

play01:01

you know it gives you book summaries now

play01:03

obviously we won't have fancy UI like

play01:04

this but we will use GPD 4 to create

play01:06

custom book summarizer where we can give

play01:08

it a topic and it gives us all di

play01:10

mentions of that topic in a 200 Page

play01:12

book now the first thing I'm going to do

play01:14

is I'm going to import some packages OS

play01:15

we'll be using this to access the

play01:17

environment variable Pi PDF 2 will be

play01:20

you know processing the PDF files

play01:21

through that open AI obviously this is

play01:23

for accessing the GPD for API VSS code

play01:26

is not recognizing these packages and

play01:28

that's because I have not in sold them

play01:30

now actually open AI if you go to

play01:32

documentation quick start they have an

play01:34

excellent guide on getting started right

play01:36

by the way you can always ask Che gbts

play01:38

to install these packages what you would

play01:40

normally do is go into terminal and

play01:41

create a new terminal and do you know

play01:43

pip install open AI but actually I'm

play01:46

using K here pip install open AI so as

play01:51

you can see it's installing the all the

play01:52

packages pip install P PDF 2 and we also

play01:56

need n now this one is a little

play01:59

different

play02:00

this one is uh pip install python Das

play02:04

donf okay and as you can see it's no

play02:06

longer highlighted which is good the

play02:08

next thing is we need to load the

play02:09

environment variable because right now

play02:11

we have it saved but it's not actually

play02:13

accessible in the main.py file so I'm

play02:15

going to paste this line of code all

play02:17

right so let's set up the key variables

play02:20

we will need for this the first one is

play02:21

the model you know the language model if

play02:23

we go into documentation and go into

play02:25

models you'll see like all the different

play02:27

models open air offers obviously we

play02:29

going to go for GPT 4 but yeah as you

play02:32

can see it's 128,000 token window which

play02:35

is four times bigger than CH GPT and

play02:38

this is like only one of the main

play02:39

reasons why apis are awesome like apis

play02:42

have made building AI apps 100 times

play02:44

easier imagine if there were no apis

play02:46

like from the one from open AI or Google

play02:48

Deep Mind like imagine if there wasn't

play02:50

an any API available we would have to

play02:52

build those language models from scratch

play02:54

or use open source ones and run like

play02:56

inference locally that's much more

play02:58

complicated than just using open a API

play03:00

so this has made building AI apps 100

play03:03

times easier in fact people are building

play03:05

entire companies with this exact method

play03:07

let's look at perplexity valuation this

play03:09

AI startup is valued at $520 million

play03:13

that's half a billion dollars and it was

play03:15

built on top of the gp4 API like knowing

play03:19

how to use API will give you a massive

play03:21

advantage in the AI Revolution once AGI

play03:23

is created it won't matter what your

play03:25

income is or what college degree you

play03:27

have the thing that will matter by far

play03:29

the most is what you know and who you

play03:32

know this is precisely why I created the

play03:35

new Society a community of people at The

play03:37

Cutting Edge of AI so if you want to be

play03:40

among the people who are building the

play03:42

future make sure to join first link in

play03:44

the description now let's continue

play03:46

setting up the key variables we have the

play03:48

model but we also need the temperature

play03:51

which 0.7 is the default one inside of

play03:54

jgpt I'm going to use 0.3 to make the

play03:56

model a little more deterministic little

play03:59

less r random we also need uh Max tokens

play04:02

let's do like 500 that's pretty standard

play04:04

I think and I'm going to also set the

play04:05

topic which is going to be what the AI

play04:08

makes the summary on so we can leave

play04:10

this empty for now now we have the key

play04:12

variables actually I'm going to create

play04:13

one more file and that's going to be

play04:15

prom. py and this is going to be where

play04:18

we store the proms so these are the

play04:20

proms I'm working with and there are two

play04:22

proms right so it's intimidating but

play04:23

it's kind of simple at the same time

play04:25

there's a system message which you know

play04:26

has the custom instructions system

play04:28

prompt whatever you want to call it and

play04:30

then we have a function that creates a

play04:32

prompt the reason why we have this is

play04:34

that I can reference the book from the

play04:36

main python file and I can also change

play04:37

the topic so this is a variable and it

play04:40

can change the reason I have to do such

play04:41

prompt engineering is because if you

play04:43

don't do this the AI will actually

play04:45

refuse to give you book summaries

play04:47

because it's copyrighted material so you

play04:48

have to go try hard and like convince it

play04:50

that it's your own text as you can see

play04:52

like I've over the past 3 years I have

play04:54

dedicated myself to this work like you

play04:55

literally have to create a story that

play04:57

this is your book now the book I've

play04:58

chosen to summarize is the almanak of

play05:01

Naval ravikant by Eric Jorgenson this

play05:04

one you know has a free pdf online 242

play05:07

pages and it's honestly one of the best

play05:09

books I've ever read okay so now we have

play05:12

the PDF right here there's a lot of

play05:13

garbage in here and that's why we

play05:16

installed the PDF package is because

play05:18

we're going to use that to actually read

play05:21

the PDF because it's not as simple as

play05:22

reading a txt file okay yeah I read the

play05:25

PDF file so let's do an empty book

play05:30

variable file path equals and then we do

play05:34

naval PDF you know what I'm going to put

play05:37

this on hold and I'm going to do a test

play05:39

API call and in here we need to do

play05:41

system message and we we need to

play05:44

reference this system message to do that

play05:46

we have to import prompts so let's go in

play05:49

here and import

play05:52

prompts and then we can do prompt.

play05:55

system message beautiful obviously we

play05:58

also need the main prompt prompt.

play06:00

generate prompt now actually in here I'm

play06:02

going to pass the book which I've

play06:05

deleted so let's put it back in empty

play06:08

variable for now and topic for a

play06:10

reference of the of the topic that's I

play06:12

mean I spent a good hour on this just

play06:14

trying to convince gbd4 that it's fine

play06:17

to summarize the book it's good to

play06:19

create a helper function and make it a

play06:20

bit simpler also it's smart to go into

play06:22

the documentation because every few

play06:24

months this gets changed quite a bit we

play06:26

have the two first two lines and we can

play06:28

copy the rest paste it here and I'm

play06:30

going to comment it out boom now we can

play06:33

name the function like I don't know get

play06:35

summary right so let's follow the

play06:37

official documentation completion equals

play06:41

client. chat. completions doc create and

play06:45

actually in here we could do it like

play06:48

this you know but I think I'm going to

play06:51

simplify it that way it's like much

play06:53

easier to see what's actually going on

play06:55

so let's go back to the function

play06:56

messages equals messages we also do

play06:59

temperature equals temperature and Max

play07:01

tokens equals Max tokens and now we have

play07:03

to return the completion return

play07:06

completion choices message and this is

play07:08

not everything because we only need the

play07:10

content because if we go into API and

play07:12

actually go into chat you can see how it

play07:16

looks like this is how the response

play07:17

looks so this is how it looks right and

play07:20

what we really need is we need choices

play07:22

the First Choice index zero so we have

play07:25

that you know completion. choices zero

play07:28

and then we need the message

play07:29

message and specifically the content we

play07:31

don't need the roll we need the content

play07:33

so this is how we access exactly you

play07:35

know the good part and this should be

play07:37

the main part done so we can actually

play07:38

delete this and you know we need to

play07:41

print summary to test it out let's do

play07:44

something simple right so this is just a

play07:45

string we can do you are a helpful

play07:49

assistant this is classic and for here

play07:51

you know you can say like list out 10

play07:54

facts about AI whatever and if we do

play07:57

this we should get an API response

play07:59

hopefully oh there it is we've gotten a

play08:02

response from gbd4 Turbo and actually

play08:05

what's fun let's go

play08:07

into um API keys and let's go into what

play08:10

is it usage okay usage this is my

play08:12

current spend for today so we will see

play08:14

how much it costs at the end hopefully

play08:17

all of this is simple by the way what

play08:18

you can do if like anything doesn't make

play08:20

sense just go into CH GPT and say

play08:22

explain the following code as if I'm a

play08:28

beginner boom paste it in here and it

play08:31

will explain it you don't even have to

play08:33

copy paste it you can just screenshot it

play08:35

boom explain every line of code and then

play08:39

yeah you can just paste a screenshot

play08:40

from any video you watch like GPD vision

play08:42

is so amazing now the topic actually

play08:44

let's set it now so I don't forget let's

play08:46

do money because I know that's mentioned

play08:48

in the book like you can consume an

play08:50

entire 242 page book in a matter of

play08:52

minutes once you have this running we

play08:53

also need the file path as we had it

play08:56

before Naval PDF and now we need to open

play09:00

it this I'm going to delete because we

play09:02

actually need to remove the first like

play09:04

23 pages and the last 30 pages for some

play09:06

reason when the AI sees contents it

play09:09

doesn't like that so I literally had to

play09:11

remove like 53 pages from the book you

play09:13

know unfortunately we can't have it so

play09:14

simple you know this is how we open the

play09:16

file at the file path we save it as a

play09:18

file variable then we do reader which is

play09:20

a new variable and we assign to it PDF

play09:22

reader from the library next we need to

play09:24

do total pages and that equals to length

play09:27

of reader. pages and for starting page

play09:30

we need to start page equals 23 and end

play09:33

page equals total Pages minus 30 now we

play09:37

need a for Loop and as you can see cop

play09:39

palet is already suggesting that for us

play09:42

but let's you know let's write it out

play09:43

why not for for every page number in

play09:46

range and you know again this is range

play09:48

of numbers starting with start page 23

play09:50

and end page with a total Pages minus 30

play09:52

and then for every page we should do

play09:54

page equals reader. Pages page number

play09:58

and then we do simply we append the page

play10:01

to our book with you know we can do a

play10:03

new line character or just a space let's

play10:06

do a space and actually should be book

play10:07

obviously so now this should give us a

play10:11

book variable with the entire text of

play10:13

the PDF print book to test it out now as

play10:17

you can see it clearly worked because we

play10:19

have the entire book printed in here we

play10:22

have to change our messages to system

play10:25

message and to prompt and then we use

play10:28

use this simple function let us change

play10:31

the topic summary on money happiness

play10:34

Fitness like the navel book is about a

play10:36

lot of topics again I definitely

play10:37

recommend you read it it's amazing book

play10:39

shout out Eric Jorgenson we should have

play10:41

everything in order let's do a test run

play10:43

and fingers crossed that the AI doesn't

play10:46

refuse because we're literally pasting

play10:48

in I mean we can just go to

play10:50

wordcounter.net and see how many words

play10:52

this is obviously we removed some pages

play10:54

but still 46,000 words so we removed

play10:56

probably like it's probably like 40,000

play10:58

words which to convert to tokens we have

play11:00

to do this is 53,000 tokens so like half

play11:02

of the context window of gb4 and as you

play11:05

can see we got a response and let's

play11:07

actually see how much money we've spent

play11:09

let's go into billing usage refresh it

play11:13

probably still needs to update but yeah

play11:15

it's going to be like you know1 or $2 at

play11:17

most one thing I want you to understand

play11:18

is that building apps with apis is a

play11:21

massive opportunity there are thousands

play11:23

of small niches that big companies like

play11:25

open AR or deep mind will never go after

play11:28

niches Industries where you actually

play11:30

have an unfair Advantage a lot of

play11:32

experience so you know what the people

play11:34

need like launching a startup has never

play11:36

been easier open air tells you

play11:38

everything and also we have this amazing

play11:39

tool cgbd as you can see it broke down

play11:41

every single line of code and explained

play11:43

it you don't even have to know

play11:44

programming you can just learn while

play11:46

you're building something now I'm going

play11:47

to upload all of this code including the

play11:49

proms in here into this module in my

play11:52

community where I also upload all my

play11:54

custom instructions great custom

play11:56

instructions from others all the code

play11:58

from my past videos the projects I've

play12:00

built in unity my custom gpds as well as

play12:02

a bunch of other stuff if you want to

play12:04

prepare for the AI Revolution and don't

play12:06

want to be left behind like most people

play12:08

will make sure to join for Link in the

play12:10

description

Rate This

5.0 / 5 (0 votes)

Related Tags
AI DevelopmentAPI UtilizationCoding TutorialGPT-4 IntegrationSummarization ToolBook InsightsTech InnovationStartup AdviceCommunity BuildingPython PackagesPDF Processing