Learniverse

Automatisierung von Aufgaben mit Python und ChatGPT

00:00

In this video, we're going to learn how to use Python to automate things for us, so we don't

00:06

have to do them manually. We're going to do something super cool and interesting. We're going to

00:11

automate two use cases. First, we'll write a Python program that takes any blog article or a

00:18

webpage and it extracts all the headers from that page or article. And then it translates all

00:25

those headers to Spanish and saves it into its own HTML file. So you can open it in the browser

00:33

and basically see all the headers of that specific blog article translated in Spanish.

00:39

And the second use case will be that we're going to write a Python program that goes through

00:44

all the files in our downloads folder. It then checks if we have any files that are older than

00:50

Thursdays or were last used more than 30 days ago. And it takes all these files and puts that

00:57

into a new folder called to delete, which we can then review and basically delete if needed.

01:05

So basically it helps us clean up our messy downloads folder with a bunch of old downloaded files

01:12

in there. But here's even more interesting thing we will do. We will use an artificial intelligence

01:19

that you probably have already heard of a million times called chat GPT. And we will tell Python

01:26

to use chat GPT's API or the underlying API that chat GPT is also using to generate the Python

01:35

scripts for those two use cases that I mentioned. Now, if you haven't heard about chat GPT by now,

01:41

also not a problem because I have a full video on that, which I made recently,

01:46

which I will link in this video. So basically we are going to write a Python program

01:52

that will accept an input from us about the automation use case. And then go to chat GPT and say,

02:00

hey, give me a Python script for this automation use case. And then we'll save it into a separate

02:06

Python file. I think it's a really cool thing to try out. And I hope you find it just a school

02:11

and exciting as I do. So let's get into it. But before we start, if you have watched our videos

02:17

and they were helpful for you, please subscribe to support us as we keep on creating more free

02:25

valuable content for you. So if you're getting value from the channel, just take this second and

02:30

click the subscribe button. If you don't want to miss any new videos that we post, then you can also

02:36

activate the notification bell. Before we start, many of you may be asking, why does everyone

02:42

use Python for automation? There are so many other programming languages out there and they all

02:47

seem to be doing pretty much the same thing. So what is it with Python that gives it a monopoly

02:53

on automation? Well, the magic is in the ecosystem of Python libraries for automation. So Python

03:00

is a very simple language. And it just happened that most low-level automation tools were written

03:07

in Python. So now you have this huge ecosystem of Python libraries that can talk to the server

03:14

operating system to cloud platforms, allow configuring infrastructure, networking, accessing various

03:20

APIs. And this may be very small standalone libraries or a complex automation tool like Ansible,

03:26

which also happens to be written with Python. So basically a lot of work and effort got concentrated

03:32

into that, which means if you want to automate something, you have a specific use case in mind,

03:38

you can be sure that there will be a great Python library for that specific automation use case.

03:45

And if it doesn't exist yet, probably someone will create it very soon. Whereas for other programming

03:50

languages, you won't be able to find library for every automation task or the library won't be as

03:58

powerful or user friendly as the Python library. So because of that, Python just ended up being

04:05

the language when it comes to automation. And when you think about this and compare the different

04:09

programming languages, every language is kind of good at one specific thing, right? So even though

04:15

they're all programming languages and at its core, they're pretty similar, every programming

04:20

language has its strengths in one particular area that differentiates it that makes it the best

04:26

language for that area. So for example, Java is robust, mature, and a good choice for enterprise

04:33

software. JavaScript is used to write web applications and Python is the language for automation.

04:40

So let's get into the demo part. Let's first write a Python program that connects to the API.

04:47

I said chat GPT API, but technically it's an open AI API, which is what chat GPT uses under the hood.

04:55

So open AI's API is the application interface that lets us connect to it and interact with the

05:01

artificial intelligence that drives and powers chat GPT, for example, and many startups and developers

05:07

actually use this API to build some cool new tools. So how do we connect to the open AI's

05:15

API in general, regardless of what programming language we're using? Well, first of all, you need to

05:21

quickly sign up to create an account on open AI platform. This way you are kind of creating your own

05:27

space on open AI for your user. And one of the reasons that you have to sign up is that the

05:33

compute resources needed and the processing that takes place by the artificial intelligence in

05:39

the background needs some compute resources and processing power. So obviously they can provide

05:44

these limitless to everyone. So they have some limits per user so that everyone can equally access

05:52

and use these for free to certain point. So the first step is to sign up and create a user

05:58

account on open AI's platform. And once you have your user account, the second step will be to

06:04

create what's called an API key, which is random generated stream, which is a unique key that is

06:11

associated with your user account, which means when we use that API key in our Python program to make

06:17

call and connect to the API, the API will know that it's associated with our user account. And by

06:24

the way, this concept of creating an account on platform and using an API key to identify your

06:30

user by making a request to it is a very general concept of using an API, nothing specific or

06:37

unique for open AI. It's that simple. So we need those two simple steps to prepare everything and

06:43

get started using this API. So let's go ahead and do that. Either open this link directly or you can

06:51

even Google open AI API. And it shows you exactly the same page, right? So right here on the open

07:00

AI page, you basically do sign up, create your account, just providing your email address and

07:06

some information, actually already created one and just log into your account. And that is your

07:15

personal space. And now let's create the API key, which we will use in our Python program to

07:21

connect to the API. So clicking on your user account icon here, view API keys. So it's pretty

07:29

simple actually. And you will probably have zero keys at the beginning for a fresh new account.

07:34

So go ahead and create a new secret key. Click on it. Obviously, I'm going to remove this later,

07:41

but before you click, okay, make sure to copy this secret key somewhere safe and accessible

07:48

because we're going to need that, you know, Python program. So I'm going to copy that. Okay. And

07:54

after that, you won't be actually able to see that or access it. So make sure to paste it somewhere.

08:01

And that's how easy it is. So we have the account and we have the API key to connect to the API.

08:06

Two things I want to mention. First of all, if Python syntax and Python generally is completely new

08:15

to you, then you can check out my Python tutorial, where I go through all the basics, including the

08:22

variables, if else statements, functions, syntax, and all these basic concepts. So you can learn

08:30

how to work with Python. And the second thing is we need to have Python actually installed,

08:36

locally so that we can run Python program. If you don't have Python installed yet, for example,

08:42

if you're on Mac, you will probably already have Python. If not, you would have to install it.

08:48

So you're going to have to have Python three. So that's the new version of Python. And you execute

08:54

with Python three command actually like this. And you also need to have Python package manager

09:02

installed, which is called PIP also with three. So if you go through my Python course,

09:08

you will have all these tools installed and you will know basics of Python syntax. So you should

09:13

be able to easily follow this specific demo. So let's start writing this Python script. And we

09:19

will see what we need and how to put together this code step by step. So first of all, I'm going

09:25

to create a separate folder for all the Python scripts that we're going to produce in this demo.

09:31

So in YouTube tutorial series folder, and I'm going to create a new folder. And let's call this

09:37

Python, Chet's GPT. And I'm going to change into that folder. And now I'm going to open these

09:47

inside Visual Studio code. And there you go. You can also just open Visual Studio code and then

09:57

open the folder from this UI. I just used a shortcut. So this is a folder where I'm going to put

10:01

the Python script. So let's create it. And I'm actually going to also call this Python script Python

10:09

Chet's GPT dot py. And we can just start writing our script. So first of all, whenever we connect to

10:20

an external API, we're making a request. So we're going to need a library, a Python library in this case,

10:28

that will allow us to send requests to external endpoints like API endpoints. Now how do we make a request

10:36

to open AI? Well, we actually have two options. We have a generic request library, which is great

10:44

because you can use it for whatever API or whatever tool you want, not just open AI. So it's generic. And

10:52

when you learn how to use it, you will be able to make a request to any API. But usually,

10:57

the tools that provide the APIs will also provide a library that hides the underlying complexity

11:04

making a request, sending all the parameters, et cetera, or setting the API key and lets you interact

11:10

with the API with a more high-level code. So in that library, that will give you objects and methods

11:16

and so on that make the whole process easier. And generally, that's the purpose of a library, right?

11:22

To make writing the code easier for us. So we don't have to write everything from scratch.

11:27

And open AI has a library for Python and Node.js, for example. And you can see the usage of

11:34

the library for each language and you see that it's called open AI. So that's the library name.

11:40

So you can install open AI library and import it in your code and use it like the example you see

11:46

right here. You can see the syntax and how to use the library in the official documentation

11:52

of that specific tool, like what methods or objects you have available and so on.

11:57

And this will be very useful if you're doing more complex things and making more complex queries

12:03

to the API and you want to use the library to do those things without overcomplicating your code.

12:09

But open AI is pretty recent and its library may change, like they may change methods and syntax

12:16

and so on because they're still adding and developing a lot of stuff on top of that.

12:21

So things may change. So if you're going to watch this video maybe a year later it may look

12:26

very different. And because of that I'm going to stick to the generic request library because

12:31

we just want to make a request which is a pretty simple use case. So the code between using the

12:37

request library and opening a library will not be very different. And also I think it's better to

12:43

learn the things that you can use for many other things as well. Maybe it's just my personal preference

12:49

but in any case for this example I'm going to use the request library. As I said it should make

12:54

that much difference if you want to. You can actually go with the opening a library and use it instead

12:59

not a problem at all. So you see here it's a module for making HTTP requests and in Visual

13:05

Studio Code you can see a cheat sheet of how to actually use the library which is pretty cool.

13:12

So now we have a library that helps us make requests to external endpoints. Now we have to find out

13:19

what is the endpoint of open AI API that we want to connect to. And remember we're writing a

13:26

Python script that takes our input which is going to be any automation use case. It will then go to

13:32

the API and say for this specific use case that user entered here I want to have a Python script.

13:39

Just like you would type into chat chip T please write a Python script for this specific use case.

13:46

So we're doing that but programmatically. So now we have to find out the endpoint that allows us

13:51

to do that. Whether we find endpoints of an API well in the API documentation. So right here

13:59

in open AI platform you're going to click on documentation and this is basically a description of how

14:06

to use this documentation and what does this API provide. And again each whatever API you're using

14:12

it will always come with that documentation because obviously you need to know how to use that

14:16

API and on which endpoints you should send what request right. So if we scroll a little bit down

14:23

here you see the section prompts and completions which is the core of this API as they are stating

14:30

here and this is exactly what chat chip it uses. You input some text as a prompt and the model

14:36

will generate a text completion that attempts to match whatever you asked from it. And there

14:43

bunch of other stuff the completions is exactly what we need. So either you click here

14:49

and it takes you directly to that completion section or if you scroll down in the API reference

14:55

you also have these completions section which is basically the same right. So we have our endpoint

15:02

I'm actually going to copy that and add that into my code and save it into a variable and I'm going

15:07

to call this API endpoint. We also have our API key that's actually also add this right here and

15:16

you should have copied that somewhere and now you can just paste it in. And by the way your API

15:22

key is a secret key so it's actually sensitive piece of information. You shouldn't be sharing that

15:28

with anyone and you shouldn't have that directly in your code. So later when you have the school

15:33

ready we're going to remove this API key from here and we're going to read that from an environment

15:39

variable so it's not hard coded inside the script but we're going to do that later. So we have

15:44

those two pieces of information we have the endpoint and we have the key that allows us to connect

15:49

to an authenticate with the open AI API in general so that it can actually take our requests

15:57

and answer them. So we're getting there slowly. Now that we have the endpoint and the key

16:01

for authentication and the library to make a request it's now time to actually make the request

16:08

and again we're going to refer the documentation to see how to generate our request. I'm going to

16:15

switch back. First piece of information we have is that we need to do a post request. So instead of

16:21

get requests where we're just getting some data we are making a post request which means we are

16:27

expecting to get some data back. However we need to first send or post our prompt to get that request

16:34

right. So we have to send some information and then we'll get the reply to that and in order to make

16:40

a post request with the request's library we have a simple post method and this post method

16:50

accepts several parameters. The first one is API endpoint because request library needs to know

16:56

where are we posting this data which endpoint are we connecting to and now we need to define what

17:03

information are we sending in that request and there are two pieces of information or two types of

17:09

information we're sending with the request. First one is the metadata about the request and the second

17:14

one is the actual request contents. So switching back again and again this is not specific to this

17:21

API this is how the requests are structured. So the metadata would be things like the token or API

17:28

key for authentication. So it's not the actual content of our request it's not the prompt that we're

17:34

saying hey please give me Python script for this use case but it's more like additional information

17:40

about the request itself which is here is my key to authenticate that I'm allowed to make this

17:46

request. Again it's part of HTTP we send the metadata as headers so we're going to set the headers

17:54

on a request and by the way if you look to your right and let's actually make this larger you have

18:00

the example request which we can use as a reference which you can basically just copy and it will

18:06

make the request with those parameters and as you see this is a curl request which you can execute

18:12

on your terminal using curl command line tool and again very conveniently they also provide

18:19

this same request example in Python and Node.js so Python is what we need and remember I told you

18:27

that we have two ways of making a request to open AI one is using the request library basically

18:34

library that provides us a generic way to make a request to any endpoint and the second one is the

18:39

open AI library itself and this example right here is using the open AI library so this is an

18:47

example code of how to make a request using that library. However I said that we're going to use

18:53

request library because our use case is pretty simple and you can then go back and compare the

18:59

open AI library example with what we write so because I'm going to be using request library I'm

19:06

actually going to switch back to curve and I'm going to take the information from here so we

19:11

have to map that now to Python request and these are HTTP headers where it's setting the API

19:18

key and saying that it will send request in a JSON format so let's set those two headers which is going

19:27

to be the second parameter of the post method so we need our headers equals two and we can

19:34

either directly write those headers inside as an object or we could also save that into a separate

19:41

variable let's call it headers or request headers and set those two headers that we need right here

19:50

so we have the content type I'm actually going to copy those two which basically says that we

19:57

are sending content type of JSON format so that's the format of the request that we are sending to

20:04

the API there you go and we have the header to set the API key now obviously we have to reference

20:15

or substitute the API key so either you can type it directly here like this a string however because

20:22

we want to have a clean code and we are storing things into variables we're going to reference it here

20:30

simply like this this is how string concatenation syntax looks like in Python so we have the string

20:36

and this is just a reference to a variable so we're setting the headers and we can set that value

20:45

as a second parameter so now the post request is made to that endpoint with those headers

20:51

and now we need the actual request what's called the request body so now the contents of the actual

20:58

request come and that's going to be the third parameter post method and again we can have

21:06

an object here like this or we're gonna create another variable we're gonna call it data or request

21:13

let's call it request data we can also call this request header

21:22

like this so we have a little consistency there you go and now let's see what we need inside that

21:29

request data now back we have the example here and these are basically the request data right

21:37

things that we include inside the request and this is an example request and this is the full list

21:43

of parameters so these are things that we can include in our request or request data to basically

21:50

communicate with the API endpoint and tell it exactly what we need right so let's go through this

21:56

parameters and see what options we have here the first important and required attribute is

22:03

what's called a model and this actually refers to the machine learning model of open AI

22:09

that we want to use and as you see as an example value it has text the vinci 003 so what is that what is

22:18

a model well if you watched my chat your video I explain what models are a little bit however we can

22:25

go through this here as well and if I open this link that says model overview we're gonna

22:32

a couple of items here these are basically group of models and if I scroll a little bit down

22:38

right here gpt3 that powers chat gpt that's where the name comes from has a list of various models

22:45

so basically open AI is an organization that works on various different types of AI tools it doesn't

22:55

just work on AI that produces text or visuals it works on different types of AI and because of that

23:03

they have various models that specialize and do different things so gpt3 is actually one of

23:12

this model groups for processing and generating natural language and this is a list of machine learning

23:19

models that open AI has developed and uses in its projects like chat gpt or deli or whatever and

23:28

also the machine learning models that you can connect to and talk to through the API and you see

23:36

the descriptions here so text the vinci 003 is basically the name or ID of that model that's how

23:42

they called it and as it says it is the most capable model it has been trained with massive amounts

23:48

of data and can do very complex things and you also see it has been trained with data up to 2021

23:56

of course this may change if you watch this video one year after I release it obviously you may

24:01

see different stuff in this documentation but currently that's how it looks like so that's what a

24:07

model is and when we connect to the API we can basically select which machine learning model we want

24:14

talk to well in our case we want to generate a Python script which is a little bit maybe a little bit

24:20

more complex task so we're gonna go with the best option that we have text the vinci 003 and that's

24:28

also the example that we have here now before we move on and use the text the vinci model in our

24:34

request I want to mention another model group that is listed in the overview called codex so just

24:41

from the name you know that it's about code and this is basically a set of models for coding

24:46

example specifically now this was actually created on top of gpt3 models so it builds on top of

24:53

the capabilities of gpt3 models but it has been trained with extensive amount from open source code

25:00

on github and it produces code so if I click inside you can see a detailed description how it's been

25:08

and that it's most capable in python plus proficient in other languages and it has these two models

25:15

under its group now here's the thing I actually tested it out to compare it with the gpt3 model

25:23

and it didn't really perform consistently on some occasions it didn't actually produce

25:28

proper results however when it actually gave the proper response it was a nicely written

25:35

well structured code so I think there is a lot of potential there but it didn't work for

25:41

all the use cases you can also see that it's in better version maybe after a couple of months

25:46

or year when you're seeing this video it will not be in better anymore just like the other

25:51

model groups so because of these reasons we're actually going to choose the gpt3 model called

25:58

text the benchy 003 which works perfectly for our use case and it actually generates really good

26:07

code as well with consistent results so that's what we're going to choose however the great thing

26:12

about using this API and our example is that you can literally just replace the model name with

26:18

any other model names that you see here including the two models under codecs group and basically

26:27

just test it out and see for yourself you will not have to adjust or change anything in the code

26:33

you will only replace the model name and basically compare them if you want to so even though

26:39

we're going with this option for the demo you can safely use code da Vinci instead and basically

26:46

just compare the results yourself so choosing the right model here is not a big deal because you

26:50

can replace it later very easily just by changing the name of the model so that's the model I'm

26:56

going to choose to make our requests so again when you use an API you can choose between those models

27:02

and that's the model we're going to choose so that's going to be our first parameter there you go

27:08

the second most important parameter in our request is obviously the prompt because prompt is the

27:14

main part of the request that tells what we are asking for exactly and again for comparison prompt

27:19

is what you type in when you're chatting with chat tpt for example in this case we're sending that

27:25

prompt programmatically inside the request and let's change this prompt and we're going to tell

27:32

the text da Vinci model to write python script for hello world super simple right because we just

27:42

want to test that we make a request successfully and we get a response so prompt is done and we have

27:48

a couple of other options here but from those options these two are probably the most important

27:54

so what are these very simple max tokens basically limits the response that you get in tokens

28:02

so with these parameters generally we are controlling the behavior of the API model when generating

28:09

the text so this specifies the maximum number of tokens such as words or punctuation marks that the

28:16

API model should generate in its response and i'm going to set this max tokens to let's do 100 for start

28:26

the hello word script obviously is going to be very small so it's not going to need 100 tokens

28:30

but we can set it to maximum 100 tokens so it's not going to exceed that amount and we have a

28:36

one more parameter which is called temperature it's also very simple it basically defines or tells

28:43

machine learning model hey when you're generating this response make sure to be super creative

28:49

like go crazy with your creativity and that will be a temperature of one or we can say

28:55

hey machine learning model please be as precise and predictable as possible and that will be

29:01

temperature of zero so in zero and one you can control that but obviously you have everything in the

29:06

middle so with zero point five temperature we can ask the API engine to generate response

29:14

that is half creative half predictable so i'm going to copy that and we're going to set it to

29:22

zero point five and we're actually going to ignore the rest of the parameters which are the most

29:27

important ones and once we have our request data we're going to set that as value for

29:35

this JSON parameter here so we have pieced together our request so this is actually

29:40

ready to connect to the API and get a response so again to walk through this what we're doing

29:46

is using the requests library we are connecting to the API endpoint of open AI and completions

29:55

we are including the API key that is associated with our user account so that open AI can say

30:03

okay i know this API key and it's associated with this account so you are authorized to make requests

30:10

and once we have that authorization it will then take our request data and see what we are actually

30:17

requesting and it will see we want to talk to text the binchy 0003 model and we want to ask it to

30:25

create Python script for hello world please do not exceed 100 tokens in your response and be

30:32

somewhat creative but also more predictable and then we will get a response and we can then

30:38

save this response into a variable called response and of course we want to see the result of

30:46

our hard work which means we want to print out the response and see what we actually got so I'm

30:51

going to do print response dot JSON so here we're getting a response and the response is also

30:58

in JSON format just like the request that we sent so with this header content type we define that

31:04

we're sending JSON and we're also receiving JSON response and this is how we can grab that JSON

31:11

response using dot JSON method now of course when we make requests when we run programs

31:18

programs sometimes have errors so some issue may happen so what we can do is we can first check

31:24

was our response actually successful or maybe head and error if it had an error then we won't have

31:30

a JSON response we're not going to have any contents or any normal response contents is JSON

31:36

so we can print out the error message in that case so what we can do is we can say if response

31:44

status code so we have status code for success which is 200 which means everything was

31:51

fine the model got our request our request was valid we didn't make any mistakes when creating it

31:58

and it was able to come up with a response which means status code 200 and in that case we print

32:04

that response if not which is else we're going to print request failed maybe we sent a wrong request

32:15

or maybe the API server is down or whatever reason request failed and we want to also know the

32:24

reason why it failed so we're going to print out the status code and this will be a reference to

32:31

response dot status code and in python this is actually python syntax if you want to use a reference

32:43

to a variable inside a string we have this really nice shortcut or syntax where we add f before

32:51

that string starts you see the syntax highlighting also changed like this so now python knows

32:59

this is a string and whatever is within this curly braces is actually not a string but variable

33:06

reference and this is going to be a number and in python we can turn the numbers into strings

33:14

using this very simple SCR or string built in function and this is our super simple python script

33:24

for connecting to open AI API so now it's time to execute this python script

33:33

so we have python 3 which we need to execute the python script and we have p3 python package

33:40

manager to install any libraries that we're using in our python script so you need to install

33:47

requests because we're using a library called request which is actually external library that

33:53

isn't included in the python package which means you will have to install that using p3

33:58

package manager so it's a python package that needs to be installed I have already installed that

34:04

and because of that first of all my visual studio code shows this quick prompt with the

34:10

examples etc however and let me demonstrate this if I go back and if I uninstall so p3

34:18

uninstall requests and let's remove that and if I go back you will see what happens

34:26

and that's going to be your case or how you see the code in your visual studio code editor you will

34:32

have this yellow line underneath and if I mouse over you will say import requests could not be

34:39

result because we don't have that library installed locally so even before running the script

34:46

python says I don't know where to find this library I can import anything called request

34:51

and that will be your state if you don't have that installed which means either globally on the

34:56

terminal or right here in the project folder you are going to do p3 install requests there you go

35:07

and now we have installed requests and it shows that documentation reference again no squiggly lines

35:14

here anymore and it will work and now then we have library installed have python3 installed

35:24

let's execute our script you see python3 and the name of our script which is python

35:31

chat gpt.py let's execute and I have actually made a small syntax error here which is

35:41

this part just like here it has to be a valid JSON object like this or for consistency we can actually

35:50

use double quotes and there you go so that should fix our attribute error since we now set the

35:58

attributes with valid syntax so let's execute our script again

36:04

and there you go we have a response output so right here where we're printing the JSON response

36:15

that's what we have right here and as you see the response is a JSON object and we have a

36:22

couple of things that we received as a response in addition to the actual python script that we

36:27

requested right here so just like we have metadata on request we have metadata on

36:33

response as well says that it's a text completion object which model was used and so on

36:40

and inside these choices attribute we have text attribute that actually contains the python

36:46

script that we asked for so right here this statement is the python print function to print

36:56

hello work which is the response to our prompt that we said right here and let's say we don't

37:04

care about all these metadata about the response we only care about the text that we're getting

37:12

so we can ignore all these other stuff only print out the response text so on the JSON object

37:19

we're gonna grab the value of choices and this is python syntax we're gonna say give me

37:26

the value of choices which is an array as you see and we're gonna grab the first element of

37:33

that array again I teach the syntax basics in my python course so if you want to know what arrays

37:40

are what objects are how to use them you can learn all of that there and then from the first

37:46

element of that array we get this JSON object and we want to get the value of the text attribute

37:53

so again give me the value of text and now this should print the value right here and let's

38:01

see that actually let's execute again and there we have it by the way when we're executing this

38:07

python script we're making a new request just like when you enter a new prompt into chat

38:12

Jupyte so this time it gave us a new response with very slight differences like edit a comment

38:19

here on the top and this line here for you know python executable so we have actually created a

38:26

program that connects to the vinci text model of open AI and now we can send whatever prompt we want

38:36

programmatically and we're gonna get a response back from that API that we're connecting to which is

38:42

pretty cool so let's try one more example and let's ask the API to write python script for let's

38:52

say printing out two days date and let's see what we get and looks at the code it imports date time

39:04

library and prints out today's date now if you have used chat Jupyte already you know that it usually

39:11

gives you additional explanations in the text form on top of the code and you might get that here

39:17

as well again it's the same API so you might get the same results when you access it programmatically

39:23

and the text can be helpful but usually if you want to quickly generate python script you don't want

39:29

to have those explanations and text you're only interested in code so in that case just to make sure

39:37

the API returns only the script and no additional text we can actually adjust our prompt and tell

39:46

API to only send us the code so right here I'm gonna say provide only code no text so we're just

39:57

telling API what we want in my case it shouldn't be much different because it already gave me

40:02

just code but it may be different in your case it's executed that again and in my case it just

40:09

removed the comments which are kind of unnecessary because the code itself is pretty self-explanatory

40:14

so we can leave it at that going back to our main goal is we want this python script to take our

40:25

input whenever we start the script of what use case we want to automate with python right

40:33

so basically this prompt here it shouldn't be hard coding here but rather it should just take

40:38

input from us and then execute that as a prompt so basically write python script for blank

40:46

so this is going to be our input for whatever use case we provide as an input and then the rest

40:53

of them will stay the same the things that will always apply such as we always want the python

40:59

script and we always want the code and not the text so this one needs to be parameterized and

41:05

taken from user input how do we get user input from python it's actually pretty easy we have a library

41:13

called arg parse or argument parser import arg parse there you go and different from the request

41:23

library which we had to install using pip3 we don't need to install arg parse because it is actually

41:30

a built-in module so it is already part of the python installation and again you see the description

41:37

here it basically lets us parse the command line arguments that we provide to the python

41:43

application when we run it so it will look like this that's the python script execution right here

41:51

after space we're gonna provide our use case as an argument and the argument will be provided

41:58

like this so write python script let's change this to to print today's date so that's going to

42:09

be the argument that we're gonna parse inside the python script and then use it here and this is

42:17

a code to read the user input we're gonna use the art parse argument parser object let's save it

42:27

into parser variable so this is an object that has a method that allows us to read the parameters

42:37

or arguments that we provide here so this basically this part here is an argument that we pass

42:44

to the application so an argument method takes two parameters the first one is the name of the

42:53

argument so it's kind of like assigning the whole value here to a variable so let's call this prompt

43:00

because that's what we're providing and then optionally we can add description of what that prompt

43:07

and that's a help attribute and let me say this is a prompt to send to the open AI API and finally

43:21

using this parser object we're gonna call a method called parsearts which is gonna go through

43:28

whatever arguments we have edit here and it's gonna read the first argument and say this is a prompt

43:35

if we had second argument and we edit here it will assign it there so it basically parse any input

43:42

we provide here and we can save it into the variable called arguments argument the word in this case

43:49

means the input that we provide to our script and now we can access this value using arts dot prompt

44:00

because we call this value prompt kind of like assigning to a variable and we're gonna use that

44:06

right here again the Python syntax for using a variable within a string so we have arts dot prompt

44:15

and of course we have to use f to tell Python this is a variable reference and not a string

44:23

so again now when we execute our script we have to provide an argument because

44:30

we are expecting it now in the application so we can't just leave it otherwise we'll get an error

44:36

and when we provide that with this three lines of code the argument parser will basically register

44:44

that input or argument with the name of prompt and then when we parse the arguments we can

44:51

access it using arguments variable dot prompt so now let's actually execute this and see how it works

44:58

so executing the Python script with this input let's see what it comes out and there we go

45:05

as I said every time we execute this script it actually makes a new request to the API

45:10

and we're getting a different response that's why it looks different than the previous ones

45:15

let's try another example like print hello world

45:21

and there you go so now without having to modify the prompt here in the code we can just easily

45:30

pass on whatever use case we want to have here right let's do some other simple example let's say

45:41

write Python script to calculate number of days from I don't know let's say one million

45:52

minutes and let's say what we get and there we go so these are obviously super simple examples

45:59

when we have the script ready we're gonna actually execute or two use cases of extracting the

46:05

headers from block article and translating to Spanish and then cleaning up your downloads folder

46:12

with all the files that are older than 30 days so we have parameterized our script so we're passing

46:20

in the prompt as an input we have two more things to do before we're done with this specific script

46:29

the first one is we want to save the script whatever we get here right here as a result

46:35

we want to save it into a separate Python script file right so instead of having that in a console

46:42

and having to copy that and create a new Python file we want that to have them automatically

46:48

and as I said at the beginning having an API key directly here since it's a sensitive data is

46:56

actually not a good thing to do so we're gonna extract that into an environment variable

47:01

both of these things are very easy to do so let's quickly add them here so first of all let's

47:08

write a code that instead of printing it out to the console it just saves it into a file so

47:14

let's remove the print here and instead let's save this into a variable and let's call it

47:20

response text so this is the attribute that contains our code and then we're gonna create a file

47:30

and we're gonna write whatever the response text is into that file very easy to do with Python

47:36

so have a keyword with open so this will basically open or create a new file and we need to provide

47:46

a file name for now let's call this output dot py so it's a Python file and the open method

47:55

takes a second attribute which is either we can write the contents to this file or if the file already

48:04

exists and there is some content we can instead append to the previous content in our case we always

48:10

want to write it from scratch so we're gonna use w so that's basically the mode in which we want

48:18

to open this file in right mode append mode and so on and we're gonna say open as file so this line

48:25

basically goes and tries to find a file called output dot py if it doesn't find one it creates one

48:33

and it opens it in the mode that we specified right here so in this case it will create a new file

48:40

and open it in right mode now that we are in a right mode we're gonna write to that file using

48:48

file dot write super easy as you see and just providing the contents we want to write to that file

48:54

that's it these two lines basically allow us to save this response text into a separate Python file

49:02

so let's execute and see that it works and there you go we have an output Python file

49:11

if I open this we have the script that API returned inside and as I said when we have the right mode

49:20

open if we change the use case let's say print hello world it will overwrite whatever is inside

49:29

output script let's see there you go instead of appending it will just overwrite or replace

49:35

whatever was in there there you go now if you want to use this Python script to generate

49:42

files for multiple use cases we want to save those use cases in separate files right we don't want to

49:49

keep overwriting in this single output file right which means we want to create a new file every time

49:57

we generate a new Python script so instead of hard coding this value or filing here we're gonna

50:05

also pass that as an input so we're gonna tell Python please send a request to generate

50:12

Python script for this use case and then please save it into a file with this name so we can

50:18

provide that as an input as well it means this will be a user input also and we'll look like this

50:25

so this is the use case or prompt and the second parameter will be the file name

50:31

like hello world dot pi for example and the same way as we did before we need to first register

50:39

this argument and then give it a name so we can use it right here so going up I'm just gonna copy

50:47

this line let's call this file name which it is file name name of the file to save Python script

51:01

there you go so we have the second argument and we can access it using rx.file name very easy

51:09

so rx.file name and now if I execute this we should get a new file with this file name

51:19

and the response text inside let's do that and we have this hello world dot pi with

51:27

print hello world inside awesome so that's one thing we wanted to optimize the second one is to

51:35

extract that into environment variable which is even easier it's gonna copy that

51:42

and instead of hard coding it directly here we're gonna export an environment variable

51:46

let's call it open AI API key you can call it whatever you want let's remove those quotes

51:54

so this will create register environment variable in this terminal session

52:00

so you have to do this in the same terminal session where you execute the script

52:04

so let's execute this one but now we have to read that environment variable open

52:10

AI key inside Python script and we do that using a module called OS and then we execute OS

52:20

get environment and the name of the environment variable is a parameter that's it so this line

52:28

will read value of this environment variable and assign it to a Python variable here and again

52:36

you have to export this environment variable before you execute the script in the same terminal

52:43

so that was our final optimization let's actually delete those and execute our script again

52:53

and there we go we have our result and we're not exposing our API key in the code and with this

53:03

our Python chat GPT script is done and ready to produce other Python automation scripts

53:13

now let's go ahead and use our script to generate Python code for our first use case which is going

53:21

to be going through a blog post and I have an example blog post that we're gonna use which is

53:28

this one right here and it has different levels of headers you probably know headers from each

53:34

email so we have larger ones and then we have some sub headers like this and so on so basically

53:42

the script will go through the whole blog post it will extract all those headers it will translate

53:48

those headers into Spanish and then save that into an html file so we open it we basically will

53:58

this blog post but basically compressed in just the list of headers translated into Spanish

54:04

so let's go back to our script and let's ask it to generate Python code for this use case

54:12

and usually when interacting with API it's important to formulate our prompts properly so it

54:19

understands exactly what we need so let's write we want a Python script to extract all headers

54:27

or let's say HTML headers from a web page translate to Spanish and save the result into an

54:46

html file and whatever Python script this provides we want to save it into a Python file let's

54:56

call it extract and translate headers dot p y so let's execute this and let's see what we get as a

55:10

and also to know that your result may be very different to what i'm getting because again it will

55:16

generate a different response every time we make a request so the file was created let's look inside

55:25

first of all we have this dot here let's remove that and let's look at our code and this is an

55:33

interesting part is you see it basically gave us a code which is not finished right so we have a syntax

55:40

error here because it hasn't finished with the result and the reason for that is if we go back to

55:46

our chat GPT Python program you remember when we were creating a request we set this parameter

55:53

called max tokens which basically limits the number of tokens or characters that you get back

56:00

as a response and because we have set a limit of 100 we basically got those 100 tokens here

56:07

so we didn't get the complete result which means we want to increase that so we have enough

56:14

tokens to get the full response so you know what i'm gonna set it to 500 just to give us enough

56:21

amount and let's try again the file has changed let's go back

56:28

and let's look through our code just one glance it actually looks pretty good we can definitely

56:36

work with this so let's go through the code that we got as a response from the API let's see if

56:42

there any adjustments needed and then we're gonna test this program with our example log article

56:50

so first of all we're using the same request a library that we used here because this is a

56:57

generic library that you can use basically to make requests to any URL this will be the URL of our

57:04

blog post so let's change that right way i'm just gonna copy that and paste it in here instead of

57:12

example and then using the request library we're just requesting that page and on the page we

57:20

kind of access the content or the text of that page and this is a library called beautiful

57:27

soup which is a very popular Python library for extracting crawling and basically working with

57:34

websites so anytime you want to extract some information from web pages this is a library that

57:40

you're gonna use it is very powerful and it is very popular and it was also suggested for this

57:45

specific use case by the API and that's a library name bs4 beautiful soup for if i hover over it

57:53

you see the description that basically parses the whole HTML into a tree representation so you can

58:00

then access individual elements of that HTML page so that's what we're doing here parsing the page

58:06

contents the whole HTML using an HTML parser it also works with XML we're specifying that this is

58:14

an HTML page and we're saving that result here and this is a line where it goes through

58:20

that tree representation of the HTML page and it basically finds and grabs all the headers

58:28

on that page so these are HTML header attributes and we're saving that array of headers and

58:35

their values of course into headers variable so this is a part where the headers are being extracted

58:42

and this is a part where they are being translated as you see also very easy code it's using

58:48

google translate library and again we have a description so google provides this translated API

58:55

for free which is amazing and you can use that in your python scripts to translate whatever you want

59:02

so this is initiating the translator and this is the code section that basically takes the header

59:08

text and translates it into Spanish so that's a destination language to be translated into

59:14

and it then collects back those translated headers into these Spanish headers array and this is a

59:21

basic for loop you learn about for loop in my python course but it's super simple actually just

59:27

goes through the headers or the header elements and it says for every header give me the text it will

59:34

translate it into Spanish and then add that into Spanish headers array so now this array will have

59:43

list of all the header texts in Spanish and the final step is where it's creating an

59:51

HTML file with HTML opening and closing text you already know this because we used it right here

59:57

basically opens the file once it creates this Spanish headers.html file which is amazing

01:00:04

also came up with a pretty good name and then between those HTML text it basically goes through

01:00:09

these Spanish headers array and for each header it adds this h1 with a header text now overall

01:00:18

the script looks pretty good actually it's surprisingly good for the very first request and we don't

01:00:26

need almost any adjustment except for this last part because since we're extracting headers of

01:00:32

all levels we don't want to then save them as h1 right we want to keep that here a key of headers

01:00:39

and titles and subtitles so we want to also reuse them right here so that's the only part we're

01:00:46

going to adjust and it's also pretty easy so what we're going to do is instead of hard coding these

01:00:51

h1s here we're going to take that information from the header element itself so we're going to

01:00:58

need to do a little bit of adjustment so first of all going back here this only saves the header

01:01:06

text right the actual values of those headers like this one for example and it discards

01:01:13

the rest of the element information including what element that is right whether it's h1 or h2

01:01:20

whatever so we want to keep all that information including the text so we're going to collect

01:01:27

not only the text but the whole elements so now this individual header items will not be just the

01:01:35

text right not just this text value but the whole HTML element which has the type which is

01:01:43

h1, h2, h whatever the text and so on this means the actual value would be header dot text

01:01:53

we have used it here as well and we will have a value called header dot name which represents

01:02:00

exactly what type of header that is so we're going to copy that here as well and that should

01:02:07

preserve the hierarchy of headers in the final HTML file as well now we can actually go ahead

01:02:12

ahead and pass this and see if we got everything right or if something else needs adjustment

01:02:20

so let's go ahead and do that however before we execute the script we need to install all those

01:02:26

libraries and if you haven't installed them yet you will also see these yellow lines underneath

01:02:33

and I can show you actually so if I uninstall them because I have them already locally

01:02:39

let's confirm yes give it a little bit of time this will be your state so before you execute

01:02:48

the script you will simply need to do pip3 install ps4 so let's do that and you also have to install

01:03:00

google translate library but in my case it didn't work with the latest installation so I had to

01:03:07

use a specific version so we're going to provide a version here as well so it's going to be

01:03:12

3.1.080 that's installed that as well and that should fix that underlining again there you go

01:03:24

and now with all the libraries all the dependencies installed we can go ahead and execute our script

01:03:33

extract translate headers let's see so we got an error that says no attribute name so it seems like

01:03:44

whatever this one of this translate result is giving back does not have a name attribute it only has

01:03:53

text so to debug that let's actually see what is inside let's do translated or translate result

01:04:04

like this and let's print this out and if we look at anyone of those items like this one for

01:04:13

example we see that it has those attributes like source destination text which is translated into

01:04:21

Spanish which is great and it doesn't have the header name attribute which is fine we can fix that

01:04:28

also very easily by grabbing that information from the header so in the Spanish headers array we

01:04:36

can basically save an object that has the header text the translated header text and the header name

01:04:43

so we're gonna prepare that object let's call it translate result so this is gonna be an object

01:04:49

and it is going to have a text and the value of the text will be the translation result

01:04:57

the text attribute right because we saw that this part here gives us the whole translate object

01:05:05

back this one and then we have to basically grab the text from it so that's gonna be our translated

01:05:11

text and then we have the header name right and we're gonna grab that directly from here

01:05:18

header name and that's it and finally we're gonna add that translate result we can also call these

01:05:28

translated header and add that to the Spanish headers array so now in that array we don't only have

01:05:36

just a list of text so this will create a Python dictionary with text and name attributes

01:05:41

with the translated text and header name attributes so the header name will be a value of h1 till

01:05:48

h6 and we're appending or adding that dictionary into Spanish headers array and here as we're

01:05:57

iterating through that list of dictionary we're gonna grab the name attribute of the dictionary

01:06:03

and text attribute and we learned the syntax of accessing the dictionary attributes is square brackets

01:06:11

and the name of the attribute which in this case is also the name also notice that because we're

01:06:18

using single quotes here for the whole string we have to use double quotes inside because otherwise

01:06:26

we're gonna get an error because it's gonna think that this basically ends the string expression

01:06:31

right so just watch out for that and again let's grab the text attribute of the dictionary

01:06:41

and the name attribute again and let's execute the script and see if it works so the script

01:06:49

completed we didn't get any errors which is a good sign and we have our Spanish headers dot

01:06:54

HTML file which should now contain all headers translated in Spanish and it looks pretty good actually

01:07:03

now the last thing we want to do is go ahead and open this in a browser and i can actually just

01:07:12

drag and drop it into the browser window like this and there you go looks pretty Spanish

01:07:19

i personally don't know Spanish so i can't tell how precise and correct the translations are

01:07:25

but that's up to the google translate library the rest of the stuff looks pretty good actually we

01:07:31

have our header hierarchy so we have the larger headers and the sub headers we can even

01:07:37

expect that in the browser and let's see there you go so we have h2 h4 all levels of headers

01:07:45

in our HTML file awesome so that gave us the first script for our first use case and i think

01:07:52

the code that we got from the API was actually pretty good as a starting point because we only

01:07:58

needed to do a couple of changes and it worked pretty well now let's go ahead and generate python

01:08:04

automation code for our second use case so i'm going to close this one and we are going to ask our

01:08:12

python script to give us python code to go through files in downloads folder check their dates

01:08:25

and if they are older than 30 days move them to folder called to delete so that's our use case

01:08:40

let's say i have a very very messy downloads folder where i never delete stuff from i just

01:08:47

leave it in there so it kind of gets pretty messy and crowded and i'm going to ask a python

01:08:52

script to basically just go through all the files and make sure that it leaves all the recent

01:08:58

downloads in the downloads folder but everything older than 30 days should be moved to a separate file

01:09:05

called to delete which i can then manually just go through and move to trash if i want to and we're

01:09:12

going to save it into a file called clean downloads dot python let's go and there you go we have

01:09:23

our clean downloads python and again it added some weird line at the beginning i'm assuming this is

01:09:30

a kind of leftover of text explanation that API is returning let's remove that and let's see what

01:09:39

we got here so we have three libraries that we're using the OS module that we already saw

01:09:45

then we have another module that is basically used to copy archive files and folders on our file

01:09:55

system and finally we have date time that we're going to need to calculate whether files are older

01:10:02

than 30 days so let's say what this auto generated script does first it sets path to downloads

01:10:09

folder in users home directory which is good if i don't want to basically provide the whole path like

01:10:16

users my username slash downloads basically just expands or uses the the users home directory

01:10:25

shortcut then it provides another path for the new directory called to delete and this is really

01:10:32

good because it checks whether the two delete folder already exists if not it creates one using this

01:10:40

OS module so OS path exists basically just checks whether file or folder exists and make

01:10:48

yours creates a directory pretty straightforward then it's going through the list of files inside

01:10:56

the downloads folder and saves them in the files variable we're getting the current date

01:11:02

and then for every file in this list of files in downloads folder it gets the files modification date

01:11:09

then it checks the time difference from now and the last modified so if it's a recent file like

01:11:16

it was modified yesterday the time difference will be one day if it's an old file it hasn't been used

01:11:22

longer than the time difference will be higher so here it checks if the time difference is higher

01:11:29

than 30 days then using the shutil module it moves the file from downloads folder the file name

01:11:38

to the to delete folder this actually looks pretty good it used the right libraries the code is

01:11:46

pretty simple it even added those comments on top the code is also nicely structured actually

01:11:52

thought that i would have to adjust way more in the final result but it seems pretty good so let's

01:11:59

actually execute this i do have lots of files in my downloads folder which a lot of them are probably

01:12:08

way older than 30 days so let's execute python3 clean downloads dot py i'm really interested to see

01:12:16

this works first time and it seems like my downloads folder was cleaned up so right now i have

01:12:24

those five files left and if i click inside those you see that they have been all modified recently

01:12:31

so this one is where today this is modified like 17 days ago and in my whole folder it created

01:12:41

two delete directory and as you see here in date modified all the files and folders inside have

01:12:49

modified date which is more than 30 days ago so logic worked moving the files worked and we got

01:12:56

exactly the result that we needed i am genuinely impressed that we didn't have to modify anything

01:13:03

at all to make this code work amazing and you even have the comments on top of those sections that

01:13:11

say exactly what it's doing really really good so yeah we have generated a couple of python scripts

01:13:19

that automates some things and we also have the python program that we can feed any automation

01:13:26

use case that we want and it will generate python script for us i'm really happy with the results

01:13:32

i hope i was able to teach you some valuable skills and things in this video please comment in the

01:13:39

how this will them award for you or whether you had any issues and what results you get or how

01:13:46

quality that even how good the results where that you got from the API and finally just share

01:13:51

some other valuable and really practical use cases where you think you can use this python automation

01:13:58

and maybe some more examples that i should cover and with that again thank you for watching

01:14:03

and see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video. And see you in the next video

00:00

Einführung in die Python-Automatisierung

00:10

Anwendungsfall 1: Extrahieren von Überschriften

00:39

Anwendungsfall 2: Downloads bereinigen

02:42

Warum Python für Automatisierung?

04:46

Verbindung zur OpenAI API herstellen

11:16

Python-Skripte mit ChatGPT generieren

12:21

Übersetzung von Überschriften ins Spanische

13:45

Verstehen von API-Endpunkten

14:10

HTML-Datei-Erstellung

16:08

POST-Anfragen in Python erstellen

16:12

Best Practices für das Dateimanagement

18:31

Einrichtung der Download-Automatisierung

20:24

Fehlerbehandlung in der Python-Automatisierung

22:20

Die richtige KI-Modell auswählen

22:26

Python-Skripte testen

25:00

Best Practices für die Arbeit mit APIs

28:00

Integration von ChatGPT in lokale Projekte

31:55

Automatisierung der Dateiorganisation

35:37

Eigene Skripte erstellen

36:38

Skripte aus Benutzereingaben erstellen

38:10

Überprüfung von Dateien vor der Löschung

40:34

ChatGPT für Automatisierung nutzen

00:10

Was sind die zwei coolen Anwendungsfälle, die wir mit Python automatisieren werden?

02:42

Warum ist Python die erste Wahl für Automatisierungsaufgaben?

05:20

Wie meldet man sich für den Zugriff auf die OpenAI-API an?

11:16

Warum sind Bibliotheken wie OpenAI in Python so wichtig?

11:16

Wie kann dir ChatGPT helfen, ganz easy eigene Python-Skripte zu erstellen?

12:21

Welche Schritte machst du, um Überschriften in eine andere Sprache zu übersetzen?

16:12

Warum ist es wichtig, deine Downloads zu organisieren, um produktiv zu sein?

20:24

Wie kannst du Fehler in Python-Automatisierungsaufgaben richtig angehen?

22:26

Was sind die wichtigsten Schritte, um deine Python-Skripte zu testen?

25:00

Wie verbessern Best Practices deine API-Interaktionen?

31:55

Wie kann Automatisierung dir Stunden bei der Dateiorganisation sparen?

35:37

Was sind die wichtigsten Schritte, um effektive Skripte zu erstellen?

38:10

Warum solltest du die Dateien überprüfen, bevor du sie löschst?

13:51

Wie findest du die Dokumentation einer API für die Nutzungsrichtlinien?

16:20

Welche Parameter brauchst du für eine POST-Anfrage in Python?

22:48

Warum ist es wichtig, das richtige KI-Modell für die Code-Generierung auszuwählen?

40:38

Wie kann man die Eingaben von Nutzern nutzen, um die Skripterstellung anzupassen?


HTMLJSONSkriptspracheAPISoftware-EntwicklungKünstliche IntelligenzPython (Programmiersprache)AutomatisierungAnfragen (Software)DateimanagerWeb-ScrapingBewährte KodierungsverfahrenDatenextraktion

Beschreibung

In diesem Video werden wir erkunden, wie man Python für Automatisierung nutzt, indem wir die API von ChatGPT verwenden. Wir fangen damit an, ein Python-Programm zu schreiben, das eine beliebige Webseite oder einen Artikel nimmt und alle Überschriften daraus extrahiert. Dann übersetzen wir diese Überschriften ins Spanische und speichern sie in einer eigenen HTML-Datei. Danach kümmern wir uns darum, unseren Downloads-Ordner aufzuräumen, indem wir Dateien identifizieren, die älter als Donnerstag sind oder seit mehr als 30 Tagen nicht genutzt wurden, und sie in einen 'Löschen'-Ordner für die Überprüfung verschieben. Das Beste daran ist, dass wir die API von ChatGPT nutzen werden, um Python-Skripte für diese beiden Anwendungsfälle zu generieren. Wir zeigen dir, wie du Eingaben akzeptierst, ChatGPT nach einem Skript fragst und es in einer separaten Datei speicherst. Am Ende dieses Videos wirst du ein besseres Verständnis dafür haben, wie man Python für Automatisierung nutzt und die API von ChatGPT in deinen Workflow integriert.