WEBVTT

00:00.400 --> 00:04.320
Okay, now it's on to a proper example that we'll use with Landgraaf.

00:04.680 --> 00:05.440
Just take the obvious.

00:05.440 --> 00:10.040
The reason I showed you the silly example was because I wanted to show that nodes don't need to have

00:10.040 --> 00:13.320
calls to llms, and they still do what they're meant to do.

00:13.360 --> 00:15.360
But now we are going to add an LLM.

00:15.400 --> 00:17.880
So we start by defining the state.

00:18.080 --> 00:21.040
We create a graph builder with that state.

00:21.160 --> 00:26.480
And now we create an LLM a real LLM using chat OpenAI.

00:26.520 --> 00:31.840
So chat OpenAI is a construct from Lang Chain the sibling to Landgraf.

00:32.000 --> 00:35.520
Uh and that's what we'll be using to connect with our LLM.

00:35.680 --> 00:39.640
And now you don't need to use lang chains llms for this.

00:39.640 --> 00:41.120
You can use any Llms.

00:41.120 --> 00:43.160
You could directly call the LLM yourself.

00:43.320 --> 00:47.560
You could also, uh, use maybe OpenAI agents SDK.

00:47.840 --> 00:53.320
But it does make things a bit simpler sometimes if you use Lang chain and most of the community examples

00:53.320 --> 00:55.840
of course go from Landgraf to Lang chain.

00:55.840 --> 00:57.520
So it's it's easy to do it that way.

00:57.520 --> 00:58.880
And that's what we'll do for here.

00:59.440 --> 01:03.150
So we're going to create a new node called chatbot node.

01:03.150 --> 01:06.070
It takes an old state and it returns a new state.

01:06.230 --> 01:07.390
And what does it do.

01:07.430 --> 01:12.390
Well it takes the the LM and it invokes on that LM.

01:12.390 --> 01:13.830
So it's again it's the Lang chain.

01:13.830 --> 01:18.950
Landgraf word invoke uh, passing in the messages from old state.

01:18.950 --> 01:21.950
So old state has a messages field and that is what we pass in.

01:22.270 --> 01:29.710
And then for the new state, it creates a new state object which contains within it as in its messages

01:29.710 --> 01:31.790
field, it contains the response.

01:31.790 --> 01:34.230
And we return the new state.

01:34.510 --> 01:40.310
And we add that node called chatbot, uh, into our graph builder.

01:40.350 --> 01:40.830
Done.

01:41.190 --> 01:47.150
Now we'll add some edges from start to chatbot from chatbot to end done.

01:47.510 --> 01:49.710
And now we will compile our graph.

01:49.710 --> 01:51.510
Step five and we'll look at the graph.

01:51.510 --> 01:54.750
And sure enough it goes start to chatbot to end.

01:55.350 --> 01:59.070
And then we put it all together in a simple gradio chat function.

01:59.070 --> 02:05.260
It takes an initial state, which is a state object set up with these messages like so.

02:05.700 --> 02:09.620
We then call graph dot invoke to actually call our graph.

02:09.740 --> 02:16.260
We print the result and we will also show the results back in Gradio.

02:16.540 --> 02:17.460
So here it is.

02:17.500 --> 02:18.860
And I can say hi there.

02:20.300 --> 02:22.180
And it's actually calling OpenAI.

02:22.220 --> 02:25.260
Now it's not using our silly adjectives.

02:25.420 --> 02:32.540
And you'll see down here that there's the user message and the response coming in these objects, this

02:32.540 --> 02:35.460
human message object that is coming back.

02:35.460 --> 02:36.780
Sorry, that human message is my.

02:36.780 --> 02:37.340
Hi there.

02:37.380 --> 02:38.980
I mean, there should be an AI message.

02:38.980 --> 02:39.740
There it is.

02:39.940 --> 02:44.740
There is the AI message, which is the response actually coming from OpenAI.

02:45.420 --> 02:50.860
But one thing that's worth noting is that if I continue this conversation every time we are invoking

02:50.980 --> 02:56.660
this graph, and you will see what you have probably already suspected, which is that we're not actually

02:56.700 --> 02:58.740
keeping track of any history here.

02:58.970 --> 03:00.410
Let's see that in action.

03:00.610 --> 03:02.770
Uh, if I, uh, say, um.

03:03.010 --> 03:03.890
My name's Ed.

03:07.490 --> 03:08.410
Nice to meet you, Ed.

03:08.450 --> 03:09.770
How can I assist you today?

03:11.290 --> 03:12.290
What's my name?

03:15.050 --> 03:17.770
I'm sorry, but I don't have access to your personal data.

03:17.970 --> 03:21.450
So there's a sign that it's not able to keep context.

03:21.450 --> 03:26.370
And you can see it yourself if you read the information that's going to and fro.

03:26.530 --> 03:33.050
So because we've just got this simple graph that we were invoking each time, there's nothing particularly

03:33.050 --> 03:34.770
interesting happening here.

03:34.810 --> 03:41.370
And the state uh, is just, just contains that that uh, doesn't contain the history or anything.

03:41.610 --> 03:44.850
So, uh, that's one of the things that we clearly need to address.

03:45.170 --> 03:47.370
And the good news is that we will indeed address it.

03:47.370 --> 03:49.450
But the bad news is not until tomorrow.

03:49.570 --> 03:56.170
But we'll also address things like tools, our old favorite, along with a couple of other things.

03:56.330 --> 03:58.010
So, uh, look forward to it.

03:58.010 --> 03:58.810
I'll see you then.
