WEBVTT

00:00.120 --> 00:00.520
Okay.

00:00.560 --> 00:04.360
So here we are looking at our node creation.

00:04.760 --> 00:06.840
Remember a node is a function.

00:06.840 --> 00:08.440
So we're going to create a function.

00:08.440 --> 00:10.200
It's called our first node.

00:10.600 --> 00:14.440
It takes an old state and it returns a new state.

00:14.760 --> 00:16.640
Its states are immutable as we say.

00:16.680 --> 00:18.720
And so we are not going to do anything.

00:18.720 --> 00:20.520
We're not going to come and mutate old state.

00:20.560 --> 00:23.920
In fact, you may see from the way that it's grayed out here that we don't actually touch Old State,

00:23.920 --> 00:26.560
which is unusual, but just for this example.

00:26.800 --> 00:28.120
So what are we actually going to do?

00:28.160 --> 00:30.160
So we're going to make a string called reply.

00:30.440 --> 00:35.240
And that reply is going to be some random word choice of a noun.

00:35.520 --> 00:38.480
And then the word r and then a random choice of an adjective.

00:38.960 --> 00:45.640
And we're going to create one of these kinds of message structures and OpenAI familiar message structure

00:45.800 --> 00:47.360
and put that into messages.

00:47.920 --> 00:53.640
We're going to say that the new state is R another a new state class.

00:53.640 --> 00:56.800
We're going to instantiate it passing in this messages.

00:57.000 --> 00:59.680
And we are going to return that the new state.

00:59.680 --> 01:02.320
And that is the end of our first node.

01:02.400 --> 01:05.330
And we then call graph dot add node.

01:05.330 --> 01:08.650
This is how we officially add it to the graph that is being built.

01:08.690 --> 01:14.850
We give it a name, we call it first node and we pass in the function the function that represents the

01:14.850 --> 01:17.170
node called our first node.

01:17.610 --> 01:17.930
Okay.

01:17.970 --> 01:19.490
So we're going to run that cell.

01:19.490 --> 01:22.890
And now we're coming on to look at creating our edges.

01:23.250 --> 01:28.930
So you can see here that I now call Graph Builder add edge to add a couple of edges.

01:28.930 --> 01:32.330
And you'll see that these words start and end there.

01:32.410 --> 01:33.250
So what are they.

01:33.290 --> 01:37.330
Well these are things that we've imported at the top in from graph graph.

01:37.370 --> 01:39.490
They are constants start and end.

01:39.490 --> 01:43.050
And of course they signify the beginning of our workflow and the end of it.

01:43.090 --> 01:49.650
And so here what we say is we want an edge to take us from the start to our first node.

01:49.650 --> 01:53.610
And then we want another edge to go from the first node to the end.

01:54.050 --> 01:55.970
Okay, that sounds logical doesn't it?

01:56.010 --> 01:57.210
So we'll run that.

01:57.410 --> 02:02.090
And now with that we get to step five which you'll remember is compiling the graph.

02:02.130 --> 02:03.210
It's saying we're done.

02:03.210 --> 02:04.730
This is our workflow.

02:04.930 --> 02:06.530
And we can now display it.

02:06.570 --> 02:10.500
This is rather nice a quick way to show visually what it is we're talking about.

02:10.500 --> 02:11.900
And hopefully this will be no surprise.

02:11.900 --> 02:16.140
We've got a start going into our first node going into our end.

02:16.540 --> 02:17.660
What could be easier?

02:17.900 --> 02:18.580
That's lovely.

02:18.620 --> 02:25.460
Okay, so we've done the five steps, which is of course the what the first part of running a graph

02:25.460 --> 02:26.060
system.

02:26.060 --> 02:31.300
We've compiled our graph and we've done it by adding nodes and edges.

02:31.300 --> 02:33.420
It's now time to run it.

02:33.580 --> 02:34.140
Okay.

02:34.180 --> 02:36.060
And what we're going to do is to run it.

02:36.100 --> 02:39.540
We're going to create a gradio chat function.

02:39.660 --> 02:40.420
Why not.

02:40.540 --> 02:48.060
Remember gradio chat functions take the user's current input and the history of prior inputs, and it's

02:48.060 --> 02:51.300
meant to respond with the next output.

02:51.300 --> 02:56.260
That's just what you do with a gradio chat function that we're going to pass into gradients chat interface

02:56.260 --> 02:57.020
right there.

02:57.220 --> 02:58.100
So that's what we have to do.

02:58.100 --> 02:58.940
So what do we want to do.

02:58.940 --> 03:06.780
Well, we're going to turn the message into a standard OpenAI format and put that into a message.

03:07.140 --> 03:11.710
We're then going to create a state object with that as the is the message.

03:12.270 --> 03:14.950
We are then going to invoke our graph.

03:15.110 --> 03:17.870
And this is the key long chain word invoke.

03:18.030 --> 03:18.790
You may be familiar.

03:18.830 --> 03:20.430
Sorry I said long chain.

03:20.430 --> 03:22.310
It's the graph word invoke.

03:22.310 --> 03:25.590
But you may be familiar with it because it's the word in long chain as well.

03:26.150 --> 03:32.470
So you invoke a graph in land graph with the state in order to get the result.

03:32.710 --> 03:35.510
And that's what's going to execute our graph.

03:35.510 --> 03:37.950
And what will come out will be the result.

03:37.950 --> 03:41.390
And we will print it and we will also return it.

03:41.630 --> 03:45.430
And that will come out of our chat function.

03:45.590 --> 03:49.310
And so with that let's run this and see what happens.

03:49.870 --> 03:51.150
Well we have a greater UI.

03:51.190 --> 03:51.790
That's good.

03:51.790 --> 03:53.070
Let's say hi there.

03:55.590 --> 03:57.070
Muffins are haunted.

03:58.750 --> 04:00.390
Is that so?

04:02.430 --> 04:04.390
Penguins are sparkly.

04:05.470 --> 04:09.710
You don't say penguins are outrageous.

04:11.110 --> 04:11.750
For real.

04:13.830 --> 04:16.520
Pickles are untrustworthy.

04:17.640 --> 04:18.400
Ha ha ha.

04:18.880 --> 04:19.800
You get the idea.

04:20.160 --> 04:27.400
Uh, so, uh, this is the results of our small language model that is picking a random noun and adjective.

04:27.400 --> 04:28.640
And I show you this.

04:28.760 --> 04:30.680
If you're wondering what on earth are you doing?

04:30.800 --> 04:36.480
I'm doing it to show that the graph setup has nothing to do with Llms necessarily.

04:36.600 --> 04:42.080
The node is just a function, in this case a silly function, but it's a function there and it's taking

04:42.080 --> 04:46.320
in a state and it's returning a state, and it doesn't need to have anything to do with llms.

04:46.560 --> 04:50.200
Now down here, I'm printing the result of this.

04:50.240 --> 04:52.480
And let me just show you that print statement.

04:52.720 --> 04:57.640
Uh, we're printing what's coming back from calling invoke on the graph.

04:57.960 --> 05:02.560
And I want to point out that that it may be something a bit different to what you're expecting because

05:02.560 --> 05:07.320
it's not it's not messages with just a list of, of strings.

05:07.480 --> 05:13.040
It's got a list of these things called human message, which you may know from, from Lang chain work.

05:13.040 --> 05:16.680
It's like a, it's a construct to package things up.

05:16.680 --> 05:20.010
And this is of course the result of the reducer running.

05:20.010 --> 05:24.450
And when I said before that the reducer simply concatenates things into a list, I wasn't telling the

05:24.450 --> 05:29.490
full story because it also does some of this packaging up that comes with Landgraf.

05:29.490 --> 05:34.890
So if it just takes the text that's come back, it knows how to package it into a human message.

05:34.890 --> 05:41.090
In terms of the things that I was saying and an AI message in terms of muffins or haunted and penguins

05:41.090 --> 05:43.370
are sparkly and the like.

05:43.530 --> 05:49.810
So that's this is some of the of the stuff hanging happening behind the scenes as a result of Landgraf,

05:50.210 --> 05:51.730
which doesn't really matter to us.

05:51.770 --> 05:53.290
We're taking advantage of that.

05:53.290 --> 05:57.130
But we just wrote a simple, a super simple state.

05:57.370 --> 06:00.570
Uh, super simple node.

06:00.570 --> 06:02.810
We made a state that contained messages.

06:03.010 --> 06:09.530
We made a node we take in an old state, we return a new state which is using this random sentence,

06:09.730 --> 06:10.850
and it works.

06:10.850 --> 06:17.650
We can invoke our graph and get a response, and we can have a conversation of rather one sided conversation

06:17.650 --> 06:19.810
with a silly language model.

06:20.570 --> 06:22.530
All right, let's do something more sensible.
