Build AI Automations with ChatGPT API & Python

AGT Development
18 followers
1 Video View·May 18, 2026
"Unlocking the Power of ChatGPT API: A Comprehensive Guide with Google AppScript Integration" is a video course that teaches you how to use the ChatGPT API in various Google Suite applications using Appscript. The course is designed to help users leverage the power of natural language processing to automate tasks and improve productivity.
🎬 TIMESTAMPS
0:00:00 Introduction to ChatGPT API in Python
0:16:47 Python Library for ChatGPT API & OpenAI Playground
0:25:50 System Message & Google Docs Integration
0:37:36 Google Sheets Integration
0:46:18 Google Slides Integration
0:55:59 End of Course
In this video, we're going to learn about OpenAI chat GPT API in Python.
There are two different methods to access the API at this point, and I'm
going to show you both the methods.
One using OpenAI library, second one using the OpenAI endpoint.
So we're going to cover end to end, starting from how to create your OpenAI
token to actually building a Python code on Google collab, where you
can chat and get a response.
So this entire thing is probably going to take less than 20 minutes.
So I would strongly suggest you to stick around till the end.
Also, a few people had asked me, how do you, you know, change the
parameters, update the parameters of open a chat GPT, OpenAI chat GPT API.
So I'm going to also cover that in this video, where how you can update certain
parameters like temperature and other.
Let's get started with the video.
First thing that you have to do is you have to register for an OpenAI account
and then you need to get a token.
So if you register for an OpenAI account, you need an email ID, you need a phone
number because they don't want you to use multiple accounts.
And after you do that, this is the screen that you would reach.
So you would, uh, okay.
This like you would have the account you could have logged in.
After you have logged in, you would reach a place like this, where I'm going to
show you how you can get your API key.
When you go to the account tab and inside the account tab, you can go to API keys.
I can link this directly in the YouTube description.
It's easier for you to get started.
So go to API keys and here you can create a new secret key.
So when you click new secret key, it's going to actually create a key and you
need to copy this key and paste it somewhere else because you cannot view
this key after it has been created.
So I've created the key.
I'm going to delete it.
And I'm going to show you in this video API key, but that is also something that
I'm going to delete after this video, never ever show your API keys to anybody.
All you have to do is add it as part of an environment variable.
There are a lot of different ways to store an API key like a JSON secret value.
So use any of these values.
If you're going to build an application, do not share your API key.
Please do not.
I've seen a lot of people coming to my GitHub repository and
pasting open API key.
Please never do that.
Never share it anywhere at all.
Now, having said that at this point, you have an open account and you have an API
key.
Now let's jump into the Google collab where I'm going to build this code.
So this code, first thing that you need is you need to install open AI
application, open AI Python library.
So it's quite simple.
PIP install queue is for a silent, quiet installation and then open AI.
Once you have installed, then you can import the open AI library.
So this is for the first method.
So like I said, there are two different methods to access open AI chat GPT.
I'm going to quickly show you that.
Let me show here.
So first method is this method.
So if you see this code, you can use open AI library and you can use the API key.
And then you can use open AI chat, chat completion, this one open AI chat
completion, and then chat with open AI chat GPT.
So to use chat GPT, the first method you use chat GPT in Python.
The first method is to use open AI library and use open AI chat completion.
The second method is to actually use this end point and make a post request.
So I'm going to start with the first method and then we'll jump into the second method.
What is the first method?
The first method, like I said, you need to import open AI library.
So import open AI library.
After you import open AI library, it is very important sometimes to
set a context to this chat GPT API.
So you need to tell the chat bot here that what does this chat bot supposed to do?
So for example, you can say you are a kind, helpful assistant.
So you can say this, you are a kind, helpful assistant.
So this is the context that you are setting with the chat GPT API so that the
API knows how to prevent, how to behave, how to do, how not to do certain things.
For example, you don't want the API to be using, let's say fall words or
something, when you are going to deploy this kind of system with children.
So there are certain nuances that you need to keep in mind.
So that is where you set this context about what this chat bot is ideally
supposed to do, like what is the behavior or what this chat bot represents
and what is the duty of the chat bot.
And I'm going to show you a different aspect as well, but for now, let's stick
to you are a kind, helpful assistant.
That's done.
The next thing is it's, it's, um, it's this, it's a JSON in the JSON.
You can see role is a system and the content is, uh, what the setup that you
did and the next line, if you want to send a message, now you have got two
different roles, one is the system role.
The second one is the user role.
So system in this case is chat GPT.
And user in this case is like, I like whoever is going to chat with, like
we're going to deploy this in public.
Then who are chats with the chat?
GPT API is the user.
So at this point we have set up the message.
Again, you don't have to take notes while you're watching the video, the
entire Google collab notebook, I'll link it in the GitHub repository.
So you can directly copy the code from there and paste it in your own.
VSCode, visual studio, Google collab, wherever you are.
So the next thing is now at this point, we have successfully set up the context.
The next thing we want to do is we want to create an infinite loop so that
we can get, have a chat mechanism.
So create an infinite loop with while true, and then get the user message from input.
This is a naive way.
I'll have a different video, probably like tomorrow, day after tomorrow, where
we will build a Gradio application to have a chat bot in itself.
But for now, this is a very simple chat mechanism where you collect the user
input, it prints out a response, then you collect user input.
So it's going to be very simple.
Now I'm going to quickly show you how it looks so that, you know, it's easier for
you to comprehend when I explain the code.
So I'm the user, I'm going to ask a question.
I'm going to ask who is the famous, most famous chess player.
Okay.
So you can see it says Gary Kasparov of Russia is widely considered to be one of
the most, the most famous chess player in history.
He was ranked number one.
So now one of the things that when you build a chat bot, you would have seen a
lot of my tutorials is that the context or the memory is a problem.
A lot of times chat bots do not know what you're talking about because you sent a
message.
It's going to go look for the information or answer, and then it is going to come
back and give the answer, but it doesn't link.
So to show you that chat GPT in this particular case has context.
I'm going to say, first I asked who is the famous, most famous chess player says
Gary Kasparov, blah, blah, blah.
Now, by definition, if I use a pronoun, human beings would know that that pronoun
is referring to Gary Kasparov.
So I'm going to say, has he lost any match before?
So I'm just trying to ask, has Gary Kasparov lost any match before?
So I'm going to send this message and it says, yes.
Gary Kasparov has lost matches before.
So it says, even though he's considered one of the greatest chess players all
time, he is not unbeatable.
So now the point is one, you can ask question.
Second, it can also hold memory.
So it can have like two things.
That's what you can see.
Like I can even see, how does he compare with Magnus Carlsen?
I mean, spelling correctly.
Yeah.
So it's going to make a call and then it has given me a huge response.
But the point here is that this works absolutely fine.
And I'm going to show you the code now.
So what is the code?
Like I said, we are going to create an infinite loop.
That's why it is continuously running.
The messages we are getting the message from the user using a simple Python
function, like probably the day you started learning Python, you would
have learned input as a function, but that's what we are using.
And if the message is present, we are going to append this
message with existing message.
What are the existing messages that we have got?
We have got a message that says the role system content, and
you are a kind, helpful person.
So now why does it have a context?
That's because we keep on appending the messages as well.
And then the next thing is now, now, if you know your messages, that's
why this does not come inside your infinite loop, it stays outside because
you don't want to overwrite your message.
So that's, that's again, another information.
So now how do you send a message?
It's a simple, like a dictionary, like a JSON.
You have a role who is a user.
What is the content?
Content is a message that you got from the user.
Now you're going to invoke OpenAI.chatCompletion and that is the
chat object and you can say create.
And what is the model that you're going to use in this case?
GPT 3.5 turbo.
You don't have to necessarily stick to only this model.
You can also use, there's a latest version of turbo that we
discussed yesterday in the video.
The 0 3 5 1.
If I remember correctly, you can use that as well.
If you want right now, we're going to use GPT 3.5 turbo.
That is what is powering the actual chat GPT interface.
If you go to chat.openai.com send the messages and get the response
from chat.choices, the first object, get the message, message content, and then
reply when you reply, then you can say, this is an assistant responding, like
this is what is the assistant name in this case is chat GPT and what is the response?
So that message also gets appended to the messages list.
So this way you keep the context as well.
So this is the entire, if you see, this is the entire code.
Like it's not even like five lines of Python code, probably
like 10 lines of Python code.
You have successfully built a chat GPT clone or chat GPT actual chat, GPT chat
bot using Python, using open a package.
It's quite interesting.
You can chat, like I can ask any questions and we can do all these
things with the first method.
So the first method we used open AI package, Python package to create a
chat interface or kind of a chat interface within less than 10 lines of Python code.
Cool.
Now, as, as I told you, we have already added the key as a variable here, but I
would strongly encourage you to add it as an environment variable, not, not
like a variable that is visible.
Now let's get into the second method.
Now, what is the second method?
Now you can ask me first, why do you need the second method?
The first method doesn't give you a lot of flexibility in how you want to do.
But the second method is an API endpoint, which means you have
got a node JS application.
You have got a JavaScript application.
You have got a, let's say Laravel application, a PHP application.
You can use this endpoint anywhere that you want.
You are not restricted by a Python library.
You can literally use this endpoint anywhere you want.
And that is the advantage of having a HTTP endpoint.
So that's one reason why you want to use.
The second reason is you can do streaming data.
What does it mean?
Um, if you, if you know, chat, chat, GPT, when you type something, chat,
GPT gives you a very nice animation.
Um, when the response comes, that is called streaming.
So you can stream with the API endpoint.
Second, the third thing, at least I feel the most important is at least at this
point, it's very easy and straightforward for you to update or change parameters
of chat, GPT, API, using the API endpoint than using the Python library.
So for these three reasons, I would, uh, if you're going to build a production
level application, I would strongly encourage you to use the API endpoint.
So now what is the API endpoint?
The API endpoint is simple.
It's api.openai.com slash V1 slash chat completions.
So this API endpoint, uh, when you are going to send the payload, okay.
If you're not very familiar with APIs, API is like a system that
helps you talk to another system.
It's like a gate.
Now, when you're going to talk to this API, you need to send a payload and the
API is going to respond back with a response.
So a payload goes and the response comes back response.
Now, when you send the payload, there are certain things that you need to send.
Uh, not mandatory, but certain things.
First, what is the model and what is the message?
Like you can see that I've asked the same question, who is the
most successful chess player?
So if you're going to build a chat interface, now this is an F string.
Ideally you can put, um, like a Python object there that will use that.
So you have got the role, you have got user, you've got content.
And this is the question that a lot of people have been asking.
Like, how do you change the temperature?
How do you change, you know, top P?
So these are certain important things because sometimes you
want chat GPT to be very creative.
Let's say you're building an application where, um, you're building an application
where it has to write creative exercise.
There, you might have to keep your temperature very high, where sometimes
you want the hallucination to be very less.
So you are going to do the trade off with a temperature.
I heard that.
Open Microsoft Bing recently also lets user control the temperature.
So it's a good thing if you can do it.
And it's always good thing for you to have this control when you are building
a production level application.
Next is all the simple things.
The most important thing is if you want streaming data, you need to enable stream
true, but right now I don't want streaming because I I'm not processing
streaming data per se.
Um, but when we build a radio chat bot, we'll do streaming.
So at this point we have streaming false, and then this is our payload.
So this is the payload that we are going to go send it to the chat GPT
API endpoint, that is a completion in point.
And what is the header?
So somebody has to authenticate it is actually us.
So the header says like it's an application JSON type, the content
type and the bearer token.
The token is exactly the same token that we were using before.
So you can literally use the same token and this is an F string.
So I'm calling the same Python object.
Which I defined above.
So the next thing is I'm going to make a post request in HTTP request.
Popular ones get and post.
So we're going to make a post request with the API endpoint.
What does the header for authentication and the payload as a JSON and stream is
equal to false because we don't want it to be streamed, get the response back.
And once you get the response back, this is what you get to make it
easier for all of us to read.
I have put it inside a JSON viewer because it's a JSON object.
So you can see first it says, what is the chat ID that is going to be very helpful.
What is the object that we use?
Chat completion.
When does it create a Unix timestamp?
What is the model that has been used here?
We are not using 0, 3, 5, 1.
We are using 0, 3, 0, 1, which is the default chat GPT model.
What number of prompt tokens?
This is quite important.
If you're going to calculate cost, for example, you could be building an
application where you need to charge the user.
So prompt token and prompt completion token.
So total how much tokens that we have got.
So total 95 tokens.
Prompt had 16 token when we got completion, 79 tokens, total 95 tokens.
And what is the message that we sent?
The message of the assistant, one of the assistant replied back.
It says the most successful chess player in history is widely considered
to be Gary Kasparov, blah, blah, blah, blah.
And all the information that you have got.
Now, this is the second method that in which you can access
chat GPT API using Python.
So I'm going to go ask another question here.
So I'm going to say, um, what is the first computer in the world?
And send the message.
I'm going to get the JSON object.
Once I get the JSON object, I mean the response object, the response object,
I'm going to say response.content.
I will copy this JSON and go to the JSON viewer, paste it here, see it here.
So you've got the JSON in the first JSON.
You have got the ID, chat completion, the time, the model, the usage, how
many tokens we sent, how many tokens we received, total number of tokens.
And the message, the assistant says the first computer in the world was an
electronic numerical integrator and computer called ENIAC created in 1945
at the university of Pennsylvania.
So overall, if you see in this video, we learned first how to create an open
AI token, which is quite important for this.
Then we learned the first method to use chat GPT API in
Python using open AI library.
The second method, we learned how to use open AI, chat GPT endpoint, which is
the completions endpoint to use chat GPT in Python.
So now the second method could be applicable for any programming language.
Like I said, anywhere where you can make an HTTP request, like PHP, JavaScript,
any framework, Laravel, Node.js, anywhere you could use it.
So overall we have learned how to build a chat GPT or how to use chat GPT API
inside Python using these two methods.
OpenAI has got where you can play with chat GPT model.
And that is what we're going to see in this video, how you can use the latest
open AI playground to play with chat GPT.
Like if you want to test chat GPT API, first, you need to have the required credits.
If your credits are zero, this will not work, but if you have credits, go click
playground when you log into chat open AI platform, and when you log in there,
you would see a mode here.
So it would say complete chat, insert, edit.
So you can click chat.
And once you click chat, you're going to get the playground.
This playground has two main components.
As you can see, one is a system where you're going to define what that model or
what the chat bot should behave like.
And the second one is the message and within model, you have got two models.
One is the default GPT 3.5 turbo model.
One is the GPT 3.5 turbo 0 3 0 1 model.
And again, you have certain options like you can change parameters.
We'll come to the parameters later.
But for now, let's start with a very simple one.
I can say you are a kind and helpful assistant, assistant, and you can send a
message.
What is the message that you want to send?
I can ask a simple question.
Um, is it enough to be just rich or you have to be famous, some random
rubbish question I'm asking and click submit.
Then let's see what happens.
Okay.
It says it's quite fast.
It's quite fast.
Ultimately it depends upon your personal goals, values, blah, blah, blah.
So it's a, it's a, it's a question.
Is it enough to be just rich?
And you can see the response.
It's important to reflect on what's truly.
So it's, it's a very nice professional response.
Now you can actually change the behavior of chat GPT or the chat GPT
API or the chat bot here.
You can say you are a witty AI assistant.
Make sure you respond everything with sarcasm and submit the message.
Now, okay.
I didn't, I asked the same question.
The question is same.
Now, is it enough to be just rich?
Now you have a different profile of assistant.
Previously you had a kind, helpful assistant.
Now you have got an assistant who is witty and who I said, who not, not, not a
human, which is, which is witty.
It says, but Hey, if being famous is your thing, just go for it.
Just make sure you're prepared for the paparazzi and constant
scrutiny of your every move.
Sounds like a blast, doesn't it?
Now, again, you can change, you can say you are an arrogant.
I think this will not mostly work.
Arrogant AI and make sure to reply everything in anger.
Most likely this will not work, but let's see.
Oh, it says.
Or maybe you could focus on something more important, worthwhile, just
than just being rich and famous.
Like making a positive impact on the world, contributing to
society in a meaningful way.
But what do I know?
I'm just a virtual assistant program to respond to your queries.
So this is very important, which a lot of people wouldn't have done
before that chat GPT API lets you set the system, lets you set the
context, which will help you.
Um, for example, which will help you make the chat bot behave in such a way.
For example, if I'm going to deploy a chat bot, let's say in university or
school, I don't want the chat bot to be like this.
I want the chat bot to be kind and helpful, not use full words,
a lot of these kinds of things.
So those conditions could be set here while you're defining the system.
And then you are going to ask a question as a user, you're going
to get a response as an assistant.
And this is where user and assistant as a role plays in.
So the user is the human who is going to ask the question and assistant
is the chat bot in this case, chat GPT API, that is going to respond.
That's one thing.
So you have got three things totally.
One is system, user and assistant.
This is way, this is how the conversation is simulated.
Like you can, as you, as you have seen so far, you can have the
conversation like this, you can go on adding a new message and then say,
but what if I like being just rich and you can send the message, submit it.
So now it's going to, okay, well, good for you.
It's not like the world needs more people who use their will
for any good causes or anything.
And you can see it, it, it makes this kind of statement.
So this is a, this is a very important thing to keep in mind that now the
system is going to completely set the attributes of the chat bot.
Now, as a thing, you also have to remember that the system can not be just, you
know, be like this and do like this.
You can also specify what you want to do.
For example, I can say you are an AI assistant translator who translates
all my messages to Tamil.
Okay.
So I'm going to say, um, did you watch the latest Tamil movie?
And I'm going to send it.
So it says, okay.
It says it doesn't.
Okay.
And it, it, I can, it says, okay, I can translate.
So I can say translate this and I can say, did you watch the latest Tamil movie and
submit, let's see if it can translate in Tamil.
I'm quite curious to see, or do I have to explicitly say, okay, it does.
So the context that we have given that you are an AI assistant translator who
translates all my messages to Tamil.
And I said, translate this.
Did you watch the latest Tamil movie?
So that means we have set a context that it has to work as a translator.
And then it says, good.
That's quite good.
So why is it important?
It is important that you could be building an application for a legal department.
You could be building an application for a medical department.
So setting this context can make a huge difference in the kind of responses that
your chat bot, like whatever chat bot that you have built on top of chat, GPT
API is going to spit out.
So this is something for you to keep in mind.
The system is something I, I, I at least personally think that that is a place
where it's going to make a huge difference between your chat bot and somebody else's
chat bot.
So that's, that's another important and interesting thing that we can
play with in the playground.
So next, what does, what else you have?
Um, you have got the preset is not available.
All these things are not available.
Now, if you see the parameters, so temperature is one of the important
parameters when it comes to large language models that complete controls
the randomness or I can call it creativity.
So if you have got a lower temperature that, uh, that gives you less random
completions and, um, so if, if your temperature is low, the model is going
to be, um, not very creative.
If your temperature is very high, the model is going to be very creative.
As you make the temperature high, the model is going to hallucinate more as
you make the model temperature lesser and lesser model is not going to hallucinate,
but it doesn't have enough content as well.
So it might become repetitive.
So this is an important trade off that you need to play with.
So for everything that you're going to do, the way the model responds
back is going to change a lot.
For example, I can go here and then say you are a witty chat bot who responds
with sarcasm, okay.
And I can say simulate a conversation between, or I can just go and ask
some random question, write an essay on Elon Musk.
Okay.
Now I'm going to set the temperature high.
So I'm going to set it high to one and then I'm going to submit.
So what I'm expecting is that this I'm expecting this chat bot to give me an
essay on Elon Musk and I want it to be a witty and witty chat bot with sarcasm.
That's good.
But again, another thing that I wanted to do is I wanted it to give
me creative, like good message.
Now, if I do the same thing with zero temperature, let's see what happens.
So it's the same system.
It's the same prompt, but now you can see that it is, it is giving message.
If you read the message, maybe you, you might find it not as creative
as the temperature, high temperature.
So it's something that you need to play with depending upon what your task is.
So overall it's, it's quite good to see chat GPT API available within
playground GUI, like graphical user interface without having to code.
So this is quite interesting.
And that's why I wanted to make this quick video and a topic.
In my case, the topic could be, let's say artificial intelligence.
Okay.
I said artificial.
Oh, this is type of artificial intelligence.
I'm going to go to this button called chat GPT, and I'm
going to click generate prompt.
That's a very bad name.
I just came up with that.
When I click generate prompt, you can see that it is going
to take a couple of seconds.
After it has taken a couple of seconds.
You can see that now I've got a fully, fully written essay on artificial
intelligence using chat GPT API.
This is quite exciting.
And I'm going to show you how to do that.
The first step is you need open AI token.
So how do you create open AI token?
All you have to do is go to your open AI account and then go to your account
settings and inside that you would see a tab called API keys and click API keys
and click create new secret token.
Once you click create new secret token, you are going to be greeted with this
window where you need to copy the token.
Just make sure that you copy it somewhere and keep it.
Otherwise you might lose it.
And again, like if you are using the token, do not share it with anybody.
If you're going to share it with anybody, make sure that you delete.
The tokens are revoked the token after you have used it or shown it so that
nobody can misuse your open AI account.
Having said that at this point, we have learned how to use, how to create
open AI API key or open AI token.
The next thing that we need to do is we need to learn how to create this
tab or the button inside Google docs.
So this is going to be done using something called an app editor.
So I'm going to go to external app script, sorry.
I'm going to go to extensions and I'm going to click app script.
Once I click app script, I'm going to get this particular window.
So this particular window where I'm going to paste the entire code, you
don't have to take notes of the code.
I'm going to explain this code, but also I'm going to share
this code as a gist file.
So it's easier for you to copy and paste.
And I'm also going to tell you where all the places you need to make any change.
First of all, this is a JavaScript code.
So if you know JavaScript, it's quite easy.
I'm not a guy who knows JavaScript.
So it was a little hard for me to understand, but if you know JavaScript,
you are in a much, much better position.
Okay.
First of all, what is this code doing?
This code is helping you do two things.
One, it is going to help you create this button here, and it is going
to help you create this button here.
Second, it is going to help you capture what you're highlighting.
And third, it is going to make a call to the open API in point, which
in this case is chat GPT in point.
And finally, it's going to paste the text as a new paragraph.
This is what this code is doing.
Let's go one by one.
First, we are going to define our API key.
I told you to copy the API key.
If you remember that API key is supposed to be pasted here.
So first paste the API key here.
Once you have the API key here, next, you need to specify
the model that you want to use.
We're going to use the chat GPT model.
So in this case, it's a chat GPT model.
You can have, you can use any model from open AI, but because.
Chat GPT of course is the cheapest one at this point, but like the
best cheapest model is chat GPT model.
So we're going to use the GPT 3.5 turbo.
So GPT 3.5 turbo is what we are using here.
After that, you need to now create a custom menu in Google docs.
How do we create a custom menu?
This function helps us create a custom menu.
This is the main menu level button, and this is the item.
Now, any item that you add corresponds to a function.
So you can see the item that I've added in this menu chat GPT is called generate
prompt, and that corresponds to a function called generate prompt.
Now I can have multiple things.
For example, right now I have one button to generate an essay.
So what if I want a product ideas?
Okay.
So I'm going to add another one here.
So I'm going to add another item here and I'm going to say generate ideas.
And I'm going to call this generate ideas.
This is for you to understand how also you can extend this.
Now I have, I have added a new item and I have added generate ideas.
Now let me save this.
And after I save this, I have to run this.
When I run this, most likely it does not show you error, but when you go here and
click here and click generate ideas, it doesn't do anything.
Why?
Because the script function for generate ideas does not exist.
So now our next duty is to create a new function, just like this.
That can generate ideas.
So I'm going to paste it on top of this.
Now I'm going to call this generate ideas.
The function name should be generate ideas.
Now inside this function, what are we trying to do?
We are first trying to get the selected text.
You are going to get this selected text.
So just the selected text.
I think instead of generate ideas, I should call it generate LinkedIn post.
But I'll keep the function and generate ideas, but the button I'm calling it
generate LinkedIn post.
So first we are collecting the text.
Okay.
The text that we are highlighting.
Next, we know what is the body.
Now, this is where you are going to give the prompt.
One, you have the text that you have already selected.
Next, you need to give the prompt.
So what does the prompt that you want?
Like in my case, I want.
Help me write five LinkedIn posts on.
So this will say, for example, if I say artificial intelligence as title will,
the prompt will look like this.
Help me write five LinkedIn posts on.
Or I can say two tweets, five tweets, whatever, whatever you want to say, you
can say that this is the place where you are updating the prompt.
First, you need to update your API key here.
If you want to add a new item, you can add a new item here, and then you need to add
a new function and inside the function, this is where you need to update the
prompt, then you can play with the parameters like max token, max token, I
think 4,000 something, but I'll just stick to 2016 the temperature, which is again,
it will help you make charge EPT from no creativity to extensive creativity where
it might hallucinate a lot.
So you can play with the temperature.
I'm not focusing on the parameters here.
If you, if you are interested in knowing charge EPT parameters, let me know.
I can make a separate video about it, but this video is supposed to be focusing
primarily on integrating charge EPT API with Google docs.
Now is the main thing where you are going to make a request to body.
So if you have not seen my charge EPT API in Python, I've explained this in detail.
So whenever you have an API, you are going to make, send a request while you're
sending a request, you're going to send a payload and the request is going
to give you a response back.
Now for that, you need to make the request body where you're going to call them.
Refer the model name that you have already defined.
And unlike any previous API charge EPT API requires it to be sent in a particular
format, and that is a format here.
So we're simply saying the role is the user because we are sending the message.
And what is the content that is a prompt.
Here, unlike the charge EPT API Python tutorial, where I said that we have to
set a context like the system here, we are not doing that.
We are just letting it to be by default.
And next is temperature maximum tokens.
That is the request body.
Now, what is the request option is a post request.
Your API key goes here, authorization content type and send the request as a
payload.
Now you're going to fetch using this endpoint.
This endpoint is the charge EPT's latest endpoint and get the response.
Pass the response and get the actual place where the messages.
And this is again, something that we discussed in the previous video.
If you have got a JSON object, you know, inside JSON, it looks like this, your
response inside JSON inside choices, the first one inside that message.
Inside that content.
That's exactly what we're doing inside JSON choices.
The first one message content.
Now get it.
If you want to log it, log it, but you're going to convert into string just in case
if it is a JSON object and then finally up into the paragraph, just below that,
like whatever you do, the paragraph.
So now this function is called generate ideas.
So it's technically supposed to generate LinkedIn post ideas.
So I'm going to save this.
I'm going to click on this first time, very first time when you are saving this,
Google is asking you to Google is going to ask you to approve something.
So it's going to say, you know, this, this application is not secure.
You have to approve it.
Fine.
It's happening only inside your Google environment.
You're not sharing it with anybody.
So it's, it's a default warning for third party applications that
are not signed by Google.
So it's completely fine.
You can save, give all the approvals and click run.
Once you click run, it's going to run the code.
So the code is ready.
I'll go back here.
You don't have to refresh.
You can see that it is already there.
So generate prompt, generate LinkedIn posts.
So I can go and then come down.
What do I want to generate LinkedIn post about?
Um, maybe beautiful morning.
Does it, I don't know if people write about beautiful morning on
LinkedIn, but let's try chat GPT.
Click generate post and wait for a few seconds because it's going to make a
call, get it back, add it here.
So it takes, Oh, it's fast.
It's quite fast.
Good morning.
LinkedIn family waking up to a beautiful morning is a reminder that every day is a
new opportunity to chase our dreams.
Quite amazing.
So you've got this button where you can click.
Let me show it for one more thing.
Just one more thing.
So what do you want?
Um, I want to save one little quarter.
So write a LinkedIn post about why you should subscribe to one little
coder who makes AI videos.
Okay.
Let's see what happens.
Select the text.
You have to select the text because that's where it takes the text for
prompt, go to chat GPT, generate LinkedIn post, and let's see what it is going to say.
So it's going to say, are you interested in learning about the latest
advancements in AI technology?
Look no further than one little quarter.
Nice.
Want to take your AI skills to the next level.
Nice.
Whether you are a seasoned AI professional, just starting out.
Okay.
I'm so, I'm so happy.
I'm so happy that it is, is managed to generate.
And again, this is five.
It's primarily because we have mentioned five here.
So you, these are certain things that you can play with.
So to quickly summarize what we have done in this video, we learned how to
create open a token API key.
Then we learned this code.
This code will be linked to the YouTube description.
Definitely check it out just below the like button if you want to like, and
then add the API key here, and then we have the code.
This is the main menu name.
This is place where you add new items.
You can change anything that you want.
And then for every item that you add, you have to link it with the function.
And this is where we create the function inside the function.
You don't have to change anything here.
You have to change the prompt.
So based on what you want to get, this is something that you can also practice
with chat, GPT, the open and the web version of chat, GPT, the free one.
Chat.openai.com write the right prompt, get what works fine for you, get it.
And then finally you have everything ready.
So at this point you will have successfully created or integrated
chat, GPT inside your, again, we are not using it for chat.
That's something for you to keep in mind, keep in mind that we are leveraging the
low cost of the APIs because it's a $2 for 1 million tokens, something like that.
So we're going to use that so that we can save cost instead of using DaVinci.
And also it is quite good.
Like everybody loves chat, GPT.
So basically we have learned to integrate chat, GPT, API inside Google
docs for us to use artificial intelligence to help us write content inside Google docs.
I hope this video was helpful to you in learning to integrate chat, GPT,
API within Google docs and use chat, GPT within Google sheet.
And a lot of people have been telling me that for SEO search engine optimization
or people who are working in that field, at least Google sheet is the main
thing where they do a lot of stuff.
So I thought, okay, can I take an SEO example and then try to make a video?
So in this video, we're going to see in one particular cell in a Google sheet.
If we have a word, can we use chat, GPT to generate multiple
keywords based on that word?
This is quite important.
Like if you're going to run, let's say Google AdWords campaign, if you want
to write a content article, if you want to reach out to content marketers.
So this is quite important thing in SEO world where you want to detect
keywords from existing paragraph.
Or you want to generate new keywords based on which you can run campaigns.
So this example is going to tell you, this video is going to tell you how
you can integrate chat GPT.
You have to bring your own key.
B Y O K.
Bring your own key.
And I've got multiple videos before where I've shown you how to get the key.
So I'm not going to focus on that in this, but we are going to go through the line
by line of app script that is going to enable us include chat GPT inside Google
sheet.
It's, it's pretty exciting.
I'm going to show you the demo.
First thing all you have to do is go click here first.
Okay.
Let me remove everything.
And I'm going to show you a keyword here.
So the keyword here could be, let's say data science.
Okay.
Data science is my keyword.
I'm going to select this year.
That's quite important because whatever you have selected, that's going to be used.
I'm going to select this, go to chat GPT, click generate keywords.
Once I do that, it is going to run the script and it has given me 10 new.
Keywords that are related to data science.
Now, maybe you know what, this is quite like a common thing.
Let me pick a simple niche.
I'm going to say, I'm going to say options and options and commodities.
Should I say equity, equity and securities, securities.
Okay.
Equity and securities go to chat GPT, click generate keywords, and
then let's see what happens now.
So, okay.
It has done stock stocks and bonds, investment portfolio, financial
assets, capital market, shareholder, equity, security, trading, asset allocation.
I, you can customize this completely based on whatever you want.
And that is the whole point of this video to teach you how
to do this for your own need.
As the cliched statement goes, I'm not here to give you the fish.
I'm here to teach you how to fish.
So let's get started with the code.
So first thing that you need to do is you need to go to the Google
sheet and open a new sheet, go to extensions and click app script.
Once you click, click app script, you would reach this particular place
where you can enter this entire script.
You do not have to take notes.
I'm going to link this entire script in my GitHub repository and link
that in the YouTube description, just below the like button.
So you can directly use it.
You don't have to be worried about it.
I'm going to show you every single section of this particular Google
app script that will help you modify the script in the future.
If you want, the first section is where we are going to define our model
key, open API key, and also the model name.
So this is the chat GPT model.
If you have, if you want to use different model, you can use it.
But I think at this point, it doesn't make any sense to use a different
model, given how cheap it is.
Like probably, um, I don't think anybody would use tech techs.
There are certain advantages of using a GPT 3.5 versus chat GPT model, but at
least I would suggest you to use chat GPT model, this is the place where
you enter the API key, which you are going to get from open a account.
This is where you have specified the model name.
You don't have to change it.
Now, this is the section we are going to actually zoom in.
This is the section.
We are actually creating the UI in itself.
The UI that you see here, this button and this one, this is where we are creating.
So we're creating a new UI in the menu called create chat GPT.
And then we are adding an item saying, okay, generate keywords.
So I'm going to show you how to add another particular function.
So first let's see the entire code, then we'll update the
code for our new menu item.
So it's easier for you to do it whenever you need it.
So this is the place where we have added the menu item, the front end UI.
Now we are going to go to the back end.
So any UI item that you add is going to be tied up with a function.
So in this case, the function name is generate keywords.
As you know, if you're familiar with programming, you cannot have
spaces in the function name.
So that's why you can see in the menu name, which is customer facing.
We have a space in the generate keywords.
We don't have a space.
The next thing is we have the function created generate keywords.
Here, we are going to go to the particular sheet from that particular
sheet, you're going to pick the text from that particular cell where like the
active range, whatever you have selected.
And we are creating a prompt.
We are saying that generate 10 keywords, similar to this keyword.
And this is where the selected text, this text that we have selected
goes in the temperature and token.
I still stuck with 2000 words, 2000 tokens, but chat GPT model can
do approximately around 4,000 ish.
So you can, you can play with that.
If you are going to give a bunch of text.
So now we have got a request body inside the request body.
We are going to create the request that we want to send it to the chat GPT API.
You can see that the model type is there.
The message is where we build the message, like a conversational message.
And then temperature is going to help you with creativity from zero to one.
You can play with that maximum number of tokens that you want to
send currently temperature is zero.
Once the request body is ready.
We need to now set the request header or request options.
Um, the request type is post request and the header contains.
It's a JSON request application, JSON content type, and then we
have got the bearer API key.
So the API key comes from here and then the entire thing goes as a payload.
That's what the entire body.
Now, this is the place where we want to request it from.
This is again, opening a endpoint for chat GPT completions.
The endpoint name is completions.
It's for chat GPT.
Once, once the request is sent, it's going to send a response back.
Now you need to collect the response and go to the particular place where you're
going to get the content and add the content to the last section after the
last rule you're going to add.
This is the existing code.
Now, what I'm going to do is I'm going to create a new menu item.
So it is easier for you to add a new menu item.
So I'm going to go here and then say, first add a new menu item.
Now, what should be this menu item?
This should be a generate.
It's a create one line or I should say, add, copy, add, copy.
Okay.
So generate, add, copy, and now create a new function here.
I want to base this function just above this.
So it's easier to see.
I'm going to call the function, generate, add, copy.
And I'm going to, after I call the function, generate, add, copy.
The next thing that I'm going to do is generate five, add copies, five Google
AdWords copies for this keyword.
Okay.
Done.
And I'm going to save.
So every time you have to save and run.
And every time you open a new Google sheet, you have to do this as well.
Otherwise you have to deploy it.
I'm not getting into the complexity, assuming that this is
going to be used individually.
So then our code is done.
Delete everything.
So let me give artificial intelligence, intelligence, go to the chat,
GPT menu, click, create, add, copy.
So I've clicked create, add, copy.
So I assume it's going to discover the power of artificial intelligence.
Get started today.
I transform your business with AI, unlock the potential of AI, revolutionize
your industry with artificial intelligence, harness the power of AI.
So that's quite good.
That's quite good.
Let's look at one more example.
Before we wrap up the video, I'm going to say subscribe to one
little coder who makes AI videos.
This is not necessarily a keyword, but I still assume that given the
prompt that we have designed, it is going to work fine.
Let's see how it goes.
Get latest AI insights from one little coder.
Subscribe now.
Stay ahead of the game with one little coder's AI video.
Subscribe today.
Unlock the power of AI with one little coder.
Subscribe for exclusive content.
Join the AI revolution.
Don't miss out on one little coder's AI video.
Subscribe now for free.
Good.
I should probably use this to advertise my channel, but for now, I think this is
good enough for anybody to get started with integrating chat GPT inside their
Google sheet for their professional workflow.
We are going to learn how to do the same for Google slides so
that we complete this triology.
So first I would like to show you a quick demo.
Then we are going to go through the code walkthrough.
At the end of this video, we will also do a new menu item where we'll completely.
Um, for example, right now you can see that I've got one item here, but we
will completely do a new item so that you learn how to add it yourself.
If you want to change something.
The first thing is let's say I have a slide and I'm going to, I'm
going to simply write something.
Um, what do I have to write?
Data science versus data engineering.
And after this, I'm going to go, maybe I'll keep it slightly on the top
because it's going to insert the bottom.
Click chat GPT and then click generate prompt.
And then once I click generate prompt, it is going to take some time because
it's going to collect the stakes, send it to open AI, get it back.
And then here it is.
So all I have to do is a little bit of formatting here and there and then move
it down and then we delete the existing one.
That's it.
We have AI generated content right within our Google slide
and let's learn how to do this.
As usual, if you have been seeing the other series, Google docs and Google
spreadsheet, you know that the first thing that you need to do is you
need to have open AI API token.
I've already extensively covered it in the previous video.
So kindly check it out.
So assuming that you have open API token or API key, first go click
extensions and click app script.
Once you click app script, you will get to this particular screen.
This entire JavaScript code will be linked in the YouTube description
from my GitHub repository.
So you can directly copy paste from that.
So you don't have to be worried about it.
So now let me explain what this code contains.
So the first thing is we are going to define the API key and also we're
going to define the chat GPT model.
Next, we are going to create a new menu item called chat GPT.
That is exactly this menu item that you see here and menu first menu, and then
you're going to create an item within that menu that is generate prompt.
So you click this menu, you get to see generate prompt, and then you're going
to do that's that's basically what you have within the slide after that is
where the actual thing starts, where you're going to first look for the
active presentation within that you're going to find what we have selected.
So how does chat GPT know on which topic you want to write something?
So whatever you have selected using the mouse, that is going to be the, that is
the text that is going to be used to create or to give it to chat GPT and
generate AI written content.
So that's something that to keep in mind.
So presentation, get the presentation, get the selected text, and then get the
slide, the slide in itself, then use the selected text, I don't think the slide
is used here in your app.
I use the slide to insert final cool.
So then get the slide.
Okay.
So presentation, selected text, get the slide.
Once you have the slide, then you need to create a prompt.
So how do you create a prompt?
In this case, the prompt here goes like this.
Generate three points on whatever the selected text is.
So if my selected text says Elon Musk, then generate three points on Elon Musk.
If my selected text goes like this, open AI chat GPT, then my prompt goes like
this, generate three points on open AI chat GPT.
So that's how this thing works.
Then set the temperature, play with the maximum tokens.
Like I've said previously, chat GPT's scope, their context is more than 4,000
tokens, but I'm still sticking with 2,000 tokens, then you have
to create the request body.
So anytime you have an API, you have to send the request and get a response back.
So here we are composing the request that has to be gone.
So while we are composing the request, there are two things.
One is the request body in itself.
Second one is the request option.
So request body will contain all the essential information.
Request options will say what type of request it is, what is the
authentication, those kinds of information.
So now what is in the request body?
We have got the model, we have got the messages, we have got the
temperature and we've got max tokens.
So the prompt that we created is now part of the messages, which, which looks like
this and then send to chat GPT.
And then we have got the request options where we are saying that this is a post
method and then we are, we have the authentication here and the entire thing,
which we created as request body is put inside here.
Now, this is the end point where open API is present.
We're going to collect the response, get the response after you get the response.
Now take the response and then pass it as JSON.
Go to the exact place where you have got the content, like the response content,
which is inside choices, the first element message and content and get that.
And if you, if you want, you know, for logging, you can keep it logging.
Otherwise you can comment it.
Finally, take that entire text.
Insert it into a new text box.
So whenever you go here, like for example, and then go to insert
and insert a new text box.
Whatever gets inserted, that is exactly what we are doing there.
So this entire thing, what we just did go here, click this, click this, click
this is what we are automatically doing there using the text that chat GPT returned us.
So we have a text that is here.
That text is now sent to chat GPT to create more text.
That text is now inserted as a text box.
And that's why you saw like a small text box were created.
Now, let me show you the workflow once again, so that you can understand the code.
So I'm going to insert new text, new slide or to make it slightly above.
And then I'm going to say, let's say data engineering is the best.
And I want to say generate prompt.
Now it's going to create a new text box inside this slide with the
three points that chat GPT returned.
So I'm going to delete the existing one.
Move this and slide it down.
That's it.
The old one you don't need and oops, old one you don't need.
And you have got the three points right now, as you can see, I'm not formatting.
I'm not, I'm not splitting into multiple slides.
I'm not doing anything.
I'm doing the bare minimum basic because I wanted to get the video out to you so
that you can customize it as much as you want.
If you know a little bit of Apps Script, even using Google documents,
this document that you have got, you can play with the documents and then
you can play with a lot of options.
But for now, this does the best.
Now I'm going to show you how we can add a new menu item and then add a
different prompt so that you know what to change, where to change.
If you get the code for the first time, like my code, the first thing that
you need to change is you need to change the API key, please never
share your API key with anybody.
I'm going to revoke this API key after this is done.
So you'll not be able to use this API key even if you do screen capture,
but never share your API key.
That's the first thing.
Next, I want to create a new menu item.
So go to this line number eight, create a new menu item.
I'm going to call this menu item, generate tweets, and I'm going
to call this generate tweets.
Every menu item has to be linked with the function.
Otherwise the menu item is not going to work.
So that's why you can see this menu item is linked with this function.
This menu item is this linked with this function.
At this point, we can save and run, but nothing will happen when we click
the menu item, because it will say this function does not exist now.
So now let's create this function to make it easier.
We're going to literally copy this function, paste it just above this.
And then we are going to go say generate tweets.
So this one is basically this.
Okay.
So this one is this.
So we have added a new menu item and then we are calling.
We're asking you to call the function, generate tweets.
And that function is this.
Now inside this, the only change I'm going to make is I'm
going to change the prompt.
So instead of generate three points, I'm going to say generate three tweets on this.
So ChatGPT knows when you ask it to generate tweets, it knows that
it has to generate three tweets.
Now everything else is going to stay the same.
If you want, like instead of text box, if you want to like a, let's say shape
also, you can insert, you can do all those inserting thing here
based on whatever you want.
Like, for example, in a shape you want, like a text, you can do that here.
For now, I'm going to stick to the same, insert a text box with
the text and then save the project.
Once I save the project, you have to run it.
After you run it, go back to your presentation.
Just make sure that this executes fine.
After that, go back to your presentation and click a new slide.
If you, if you want new slide and then just, what do I want to do?
I want to say, let's say data engineering is the best, the same
thing that we just gave and I'm going to probably even delete it.
I don't need this.
Click this ChatGPT generate tweets.
So now at the end of this, this is going to insert a text box here in this
particular slide with whatever we just asked for, which is three tweets, three tweets.
So you've got three tweets.
Data engineering is the backbone of any successful data-driven organization.
You've got hashtags, you've got tweets.
This is exactly what we set out to do at the start of this video, where we have
successfully integrated ChatGPT with Google slide.
Also, we have learned how to customize this code if you want to add a new menu item.
So I hope this video was helpful to you in learning how to integrate ChatGPT
within Google slide to create AI generated content within your Google slide.
