WEBVTT

00:00.240 --> 00:00.640
Okay.

00:00.640 --> 00:04.200
This is the single most important moment of the entire lab.

00:04.680 --> 00:09.320
So it's the chat function, and I've spaced it out a bit to really explain what's going on.

00:09.320 --> 00:14.080
It's a more powerful chat function that includes the calling of a tool.

00:14.560 --> 00:17.120
It starts exactly the same way as it did before.

00:17.240 --> 00:19.120
We create some messages.

00:19.120 --> 00:20.640
Role of system.

00:20.640 --> 00:22.440
The content is the system prompt.

00:22.560 --> 00:24.280
We add in the history from before.

00:24.680 --> 00:25.680
Role of user.

00:25.680 --> 00:27.680
The content is the user's message.

00:28.200 --> 00:35.120
And now do a pretty standard trick of looping again and again and again until a variable called done

00:35.160 --> 00:36.520
gets set to true.

00:36.680 --> 00:39.480
So it's going to keep going until done is true.

00:39.880 --> 00:41.160
What is it going to keep doing?

00:41.600 --> 00:43.360
It's going to call open AI.

00:43.880 --> 00:46.640
And this is the usual thing OpenAI.

00:49.280 --> 00:51.360
Create we're familiar with that.

00:51.400 --> 00:52.680
We pass in the model.

00:52.920 --> 00:56.320
We pass in the messages this set of of messages.

00:56.560 --> 00:59.520
But look we also pass in Tools.

00:59.720 --> 01:06.080
Tools is that JSON blob, that structure of JSON, which is going to be sent to the LM saying, these

01:06.080 --> 01:07.360
are all the things you can do.

01:07.360 --> 01:09.760
This is the description of everything you can do.

01:10.280 --> 01:10.680
All right.

01:10.720 --> 01:12.800
And back it comes into response.

01:12.800 --> 01:18.880
And what comes in response might just be the output to go to the user, or it might be a response that

01:18.880 --> 01:21.600
indicates that tools need to be called.

01:21.600 --> 01:23.520
So that is what we do next.

01:23.560 --> 01:25.880
We look at response choices.

01:28.800 --> 01:35.200
And this tells us whether the LM is finished and it's done or whether it wants to call a tool.

01:35.640 --> 01:40.080
So if the finish reason is tool calls, it wants to call a tool.

01:40.480 --> 01:46.960
Then we we look at the message itself, we pluck out the tool calls from it.

01:47.560 --> 01:53.880
And this this is where we call that function that we just wrote, that clever function, that sneaky

01:53.880 --> 01:54.600
function.

01:54.840 --> 01:55.760
Right here it is.

01:55.760 --> 01:57.560
Remember it handle tool calls.

01:57.650 --> 02:02.810
This is the one that is the glorified if statement, the one that has the fancy if statement.

02:02.810 --> 02:07.970
But there's also this more silly version here that just has an actual if statement.

02:08.210 --> 02:09.850
But it's going to call this.

02:10.210 --> 02:11.490
So back we go.

02:12.170 --> 02:16.850
So again if it wants to call tools then we do that.

02:16.850 --> 02:17.930
We handle the tool calls.

02:17.930 --> 02:19.010
We call the tools.

02:19.170 --> 02:21.570
And then into the set of messages.

02:21.570 --> 02:25.130
We put what it wanted to do and the results of doing it.

02:25.490 --> 02:29.890
And then we will loop back and call a second time.

02:29.890 --> 02:32.810
And we will keep doing this until the finish.

02:32.810 --> 02:34.770
Reason is not tool calls.

02:34.770 --> 02:40.850
It does not want to call tools with whatever, it's just responded, in which case we return the content

02:40.850 --> 02:45.250
because that is going to be the actual response to the user.

02:45.610 --> 02:46.930
I hope that made sense.

02:46.970 --> 02:50.450
If not, go through it slowly, carefully until it does.

02:50.650 --> 02:52.330
This is this is pivotal.

02:52.330 --> 02:54.690
This is how the whole thing hangs together.

02:55.170 --> 02:56.450
Now, I know what you're thinking.

02:56.450 --> 02:58.650
You're thinking it's all very well showing us all this code.

02:58.650 --> 03:00.170
But does it actually work?

03:00.410 --> 03:01.770
Well, let's find out.

03:01.770 --> 03:03.170
Let's run the code.

03:03.210 --> 03:04.370
Here we have it.

03:04.370 --> 03:05.450
Let's say hi there.

03:05.810 --> 03:06.170
Hello.

03:06.170 --> 03:07.370
How can I assist you today?

03:07.370 --> 03:08.250
What's your job?

03:09.490 --> 03:11.650
I'm currently the co-founder and CTO of Nebula.

03:11.690 --> 03:12.570
Very nice.

03:12.730 --> 03:14.050
Uh, do you have a patent?

03:15.490 --> 03:16.850
Yes I do.

03:16.890 --> 03:17.650
Very nice.

03:17.730 --> 03:21.410
Uh, who is your favorite musician?

03:22.210 --> 03:23.210
That's what I want to know.

03:25.090 --> 03:29.370
I hope you, uh, heard that success.

03:29.490 --> 03:30.050
So it says.

03:30.050 --> 03:32.010
I'm not sure about my favorite musician.

03:32.010 --> 03:33.130
I appreciate a variety.

03:33.130 --> 03:35.010
If you have a favorite, I'd love to hear about it.

03:35.050 --> 03:36.370
It called the tool.

03:36.610 --> 03:37.570
You heard my phone.

03:37.570 --> 03:38.010
Go.

03:38.210 --> 03:39.890
We have success.

03:39.970 --> 03:42.810
The agent was able to take that JSON.

03:42.850 --> 03:45.570
It knew that this was a tool that it could call.

03:45.610 --> 03:48.410
It was able to respond with the finish.

03:48.410 --> 03:50.250
Reason was was tool calls.

03:50.250 --> 03:56.420
And that caused us to to interpret that to make the call to R our function handle tool calls, which

03:56.420 --> 04:03.500
had our fancy code that ended up calling this function that ended up calling pushover, that then sent

04:03.540 --> 04:07.820
the push notification to my phone and it all hung together.

04:08.180 --> 04:09.660
All right, let's keep going.

04:09.980 --> 04:11.220
I'd like to get in touch.

04:12.220 --> 04:13.020
That's great to hear.

04:13.020 --> 04:14.260
Please share your email address.

04:14.300 --> 04:19.340
I'm at Edward donna.com.

04:23.340 --> 04:24.740
I know you're expecting it.

04:24.740 --> 04:25.100
Now.

04:25.100 --> 04:27.380
The, uh, the magic's worn off.

04:27.420 --> 04:28.780
You're not impressed anymore?

04:28.900 --> 04:30.500
Well, I think that's really cool.

04:30.620 --> 04:36.220
So it has indeed, of course, notified me about my own email address, which is great.

04:36.220 --> 04:39.260
And so it shows you that it does hold together.

04:39.420 --> 04:44.460
Uh, and you are indeed able to have these interactions and get it to text you.

04:45.060 --> 04:45.780
Okay.

04:46.100 --> 04:46.860
That's great.

04:46.860 --> 04:48.420
I hope you enjoyed it.

04:48.420 --> 04:54.900
But next it's all about doing this for you and actually deploying this live to production so that you

04:54.900 --> 04:59.180
can serve your own avatar on your personal website.

05:00.060 --> 05:02.940
So if you've followed everything so far, then many congratulations.

05:02.940 --> 05:07.660
If you haven't, then also congratulations because it gives you this great opportunity to go through

05:07.820 --> 05:09.500
work through this until you do.

05:09.540 --> 05:10.700
And if I can help.

05:10.740 --> 05:13.260
Email me or contact me anytime.

05:13.260 --> 05:13.860
LinkedIn with me.

05:13.860 --> 05:16.980
Message me so that I can help you out.

05:17.300 --> 05:24.900
So what I want to do now is show you how you can deploy this application in production for yourself,

05:24.900 --> 05:28.100
so that you can have this as your virtual resume.

05:28.380 --> 05:30.460
Surely this is the future of resumes.

05:30.500 --> 05:36.900
No longer will we have profiles or CVS resumes where you list out your skills and experience, but rather

05:36.900 --> 05:41.220
you'll have a chat bot that people can interact with to learn about your career.

05:41.220 --> 05:48.020
And what better way to highlight your your AI abilities and your abilities to work with Agentic AI than

05:48.020 --> 05:55.870
to have an agentic solution up on your website that will allow you to interact with people and talk

05:55.870 --> 05:56.910
about your career.

05:57.510 --> 06:01.550
So let me show you some steps to deploying this.

06:01.950 --> 06:06.590
So the first thing to do is to put the code into a Python module.

06:06.590 --> 06:09.910
And I have done that right here for you in App.py.

06:10.230 --> 06:13.710
And you'll see that this has all of the stuff you would expect.

06:13.710 --> 06:20.550
It's got the same information in here, but organized into nice little functions at the top of the functions

06:20.550 --> 06:22.430
that cover the tools that we call.

06:22.750 --> 06:26.710
And then there is a class me as in me or or you.

06:27.070 --> 06:33.070
And that's something which has the handle tool call that we know so well that's right here.

06:33.070 --> 06:40.110
And it has the system prompt and this loop that we just went through, this chat loop that has the while

06:40.150 --> 06:46.590
not done it calls open I create, it passes in the tools.

06:46.710 --> 06:48.670
I don't think I mentioned this actually, so I'm pleased.

06:48.670 --> 06:51.430
I pause for a minute here because I do want to show this one more time.

06:51.630 --> 06:53.590
We call chat completions create.

06:53.630 --> 07:00.270
We select the model, we pass in the messages, and we pass in the tools JSON, the description of the

07:00.270 --> 07:01.550
tools that it can call.

07:01.910 --> 07:04.790
And with what comes back, we take choices zero.

07:04.910 --> 07:08.030
And we look at the finish reason back in the response.

07:08.030 --> 07:11.230
And we see whether or not that is tool calls.

07:11.430 --> 07:19.510
And if so, then we loop through to make sure that we run all of the tools before calling it again to

07:19.550 --> 07:20.950
get the final response.

07:21.350 --> 07:26.910
So this is so critical, this this chat with its loop that I do encourage you to take a look at it.

07:27.390 --> 07:30.950
And now at the bottom here we have the Gradio code.

07:30.950 --> 07:38.270
We've got it set up here so that if this is just run as it is then it will create a gradio chat interface

07:38.470 --> 07:44.550
with showing me chat and with the messages and it will launch it.

07:44.950 --> 07:49.840
So what I can do now, in fact, is I can bring up a terminal which you may remember.

07:49.840 --> 07:53.200
You press control and the backwards tick mark.

07:53.360 --> 07:56.200
I can go into the week one folder.

07:56.200 --> 07:59.200
Here we are and I can now type.

07:59.240 --> 08:01.120
Remember you don't type Python.

08:01.160 --> 08:04.040
You type, you run to run something.

08:04.040 --> 08:06.960
In this way you've run app.py.

08:07.680 --> 08:11.720
And if I run that then it should come up.

08:11.960 --> 08:13.520
So this link.

08:13.520 --> 08:17.920
Now on this link I can press control and click it to bring it up.

08:18.400 --> 08:19.160
Up it comes.

08:19.200 --> 08:20.840
Let me make that a bit bigger for you.

08:21.120 --> 08:26.240
This is now an app running on my box and I can say hi there.

08:27.040 --> 08:27.400
Hello.

08:27.400 --> 08:34.560
How can I assist you and, and uh, do you have a patent and so on and there we go.

08:34.760 --> 08:35.360
Okay.

08:35.680 --> 08:43.240
So so that works going back here, what we now want to do is look at actually deploying this.

08:43.560 --> 08:48.920
So there are various ways you can deploy an application like this, but one of them that's particularly

08:48.920 --> 08:55.800
simple and elegant is brought to you by the lovely AI company Hugging Face, which also happens to be

08:55.800 --> 08:57.960
the company that owns Gradio.

08:58.000 --> 09:02.960
That beautiful, framework hugging face has something called hugging face spaces, and hugging face

09:02.960 --> 09:06.880
spaces is a way that you can deploy things really simply.

09:06.880 --> 09:10.280
And then if you wish, you can also embed them in your own home page.

09:10.280 --> 09:13.680
So it gives you a really nice, simple way to do it.

09:13.960 --> 09:15.880
So this is how you do it.

09:15.880 --> 09:21.400
You first have to go to Hugging Faces website and set up your own account if you don't already have

09:21.400 --> 09:21.880
one.

09:21.880 --> 09:25.360
So you may already have a hugging face account, but if not, you need to set one up.

09:25.760 --> 09:31.640
Once you've done with that, you go into the foundations folder in a terminal and you run this command

09:31.680 --> 09:33.400
Gradio deploy.

09:34.000 --> 09:39.240
It's then going to ask you a series of questions, a bunch of simple questions to which I've got the

09:39.240 --> 09:40.920
answers you have to give right here.

09:41.360 --> 09:42.760
And I'll go through and do it right now.

09:42.760 --> 09:46.370
But I'm not going to do it properly, because one of the questions it's going to ask you about some

09:46.370 --> 09:52.890
secrets that you'll say yes, and you're going to provide your OpenAI API key so that it can use that

09:52.890 --> 09:54.050
in the deployment.

09:54.050 --> 09:57.250
And you can also give your pushover tokens as well.

09:57.530 --> 10:01.330
And then I have got the rest of the instructions right there for you.

10:01.810 --> 10:06.810
And once that's done, it will be deployed into a hugging face space.

10:06.810 --> 10:08.850
And you can choose whether that is public or private.

10:08.850 --> 10:12.810
You can have it be private if you don't want other people using your key.

10:12.850 --> 10:16.170
Although as I say, it's super cheap, but people would have to.

10:16.210 --> 10:20.690
It would have to go viral for you to have any kind of significant spend.

10:20.690 --> 10:25.450
And of course, make sure that your OpenAI account, you never want to have that auto refilling so that

10:25.450 --> 10:30.210
if that ever were to happen, if your app did go viral, then you would be protected.

10:30.210 --> 10:33.490
And anyway, OpenAI has limits, as you probably know.

10:34.170 --> 10:36.890
So, uh, let's go and actually do this.

10:36.890 --> 10:38.570
Let's run Gradio deploy.

10:38.770 --> 10:43.970
So I'm going to bring up the terminal now, and then we will go and do this ourselves together.
