1
00:00:00,400 --> 00:00:04,320
Okay, now it's on to a proper example that we'll use with Landgraaf.

2
00:00:04,680 --> 00:00:05,440
Just take the obvious.

3
00:00:05,440 --> 00:00:10,040
The reason I showed you the silly example was because I wanted to show that nodes don't need to have

4
00:00:10,040 --> 00:00:13,320
calls to llms, and they still do what they're meant to do.

5
00:00:13,360 --> 00:00:15,360
But now we are going to add an LLM.

6
00:00:15,400 --> 00:00:17,880
So we start by defining the state.

7
00:00:18,080 --> 00:00:21,040
We create a graph builder with that state.

8
00:00:21,160 --> 00:00:26,480
And now we create an LLM a real LLM using chat OpenAI.

9
00:00:26,520 --> 00:00:31,840
So chat OpenAI is a construct from Lang Chain the sibling to Landgraf.

10
00:00:32,000 --> 00:00:35,520
Uh and that's what we'll be using to connect with our LLM.

11
00:00:35,680 --> 00:00:39,640
And now you don't need to use lang chains llms for this.

12
00:00:39,640 --> 00:00:41,120
You can use any Llms.

13
00:00:41,120 --> 00:00:43,160
You could directly call the LLM yourself.

14
00:00:43,320 --> 00:00:47,560
You could also, uh, use maybe OpenAI agents SDK.

15
00:00:47,840 --> 00:00:53,320
But it does make things a bit simpler sometimes if you use Lang chain and most of the community examples

16
00:00:53,320 --> 00:00:55,840
of course go from Landgraf to Lang chain.

17
00:00:55,840 --> 00:00:57,520
So it's it's easy to do it that way.

18
00:00:57,520 --> 00:00:58,880
And that's what we'll do for here.

19
00:00:59,440 --> 00:01:03,150
So we're going to create a new node called chatbot node.

20
00:01:03,150 --> 00:01:06,070
It takes an old state and it returns a new state.

21
00:01:06,230 --> 00:01:07,390
And what does it do.

22
00:01:07,430 --> 00:01:12,390
Well it takes the the LM and it invokes on that LM.

23
00:01:12,390 --> 00:01:13,830
So it's again it's the Lang chain.

24
00:01:13,830 --> 00:01:18,950
Landgraf word invoke uh, passing in the messages from old state.

25
00:01:18,950 --> 00:01:21,950
So old state has a messages field and that is what we pass in.

26
00:01:22,270 --> 00:01:29,710
And then for the new state, it creates a new state object which contains within it as in its messages

27
00:01:29,710 --> 00:01:31,790
field, it contains the response.

28
00:01:31,790 --> 00:01:34,230
And we return the new state.

29
00:01:34,510 --> 00:01:40,310
And we add that node called chatbot, uh, into our graph builder.

30
00:01:40,350 --> 00:01:40,830
Done.

31
00:01:41,190 --> 00:01:47,150
Now we'll add some edges from start to chatbot from chatbot to end done.

32
00:01:47,510 --> 00:01:49,710
And now we will compile our graph.

33
00:01:49,710 --> 00:01:51,510
Step five and we'll look at the graph.

34
00:01:51,510 --> 00:01:54,750
And sure enough it goes start to chatbot to end.

35
00:01:55,350 --> 00:01:59,070
And then we put it all together in a simple gradio chat function.

36
00:01:59,070 --> 00:02:05,260
It takes an initial state, which is a state object set up with these messages like so.

37
00:02:05,700 --> 00:02:09,620
We then call graph dot invoke to actually call our graph.

38
00:02:09,740 --> 00:02:16,260
We print the result and we will also show the results back in Gradio.

39
00:02:16,540 --> 00:02:17,460
So here it is.

40
00:02:17,500 --> 00:02:18,860
And I can say hi there.

41
00:02:20,300 --> 00:02:22,180
And it's actually calling OpenAI.

42
00:02:22,220 --> 00:02:25,260
Now it's not using our silly adjectives.

43
00:02:25,420 --> 00:02:32,540
And you'll see down here that there's the user message and the response coming in these objects, this

44
00:02:32,540 --> 00:02:35,460
human message object that is coming back.

45
00:02:35,460 --> 00:02:36,780
Sorry, that human message is my.

46
00:02:36,780 --> 00:02:37,340
Hi there.

47
00:02:37,380 --> 00:02:38,980
I mean, there should be an AI message.

48
00:02:38,980 --> 00:02:39,740
There it is.

49
00:02:39,940 --> 00:02:44,740
There is the AI message, which is the response actually coming from OpenAI.

50
00:02:45,420 --> 00:02:50,860
But one thing that's worth noting is that if I continue this conversation every time we are invoking

51
00:02:50,980 --> 00:02:56,660
this graph, and you will see what you have probably already suspected, which is that we're not actually

52
00:02:56,700 --> 00:02:58,740
keeping track of any history here.

53
00:02:58,970 --> 00:03:00,410
Let's see that in action.

54
00:03:00,610 --> 00:03:02,770
Uh, if I, uh, say, um.

55
00:03:03,010 --> 00:03:03,890
My name's Ed.

56
00:03:07,490 --> 00:03:08,410
Nice to meet you, Ed.

57
00:03:08,450 --> 00:03:09,770
How can I assist you today?

58
00:03:11,290 --> 00:03:12,290
What's my name?

59
00:03:15,050 --> 00:03:17,770
I'm sorry, but I don't have access to your personal data.

60
00:03:17,970 --> 00:03:21,450
So there's a sign that it's not able to keep context.

61
00:03:21,450 --> 00:03:26,370
And you can see it yourself if you read the information that's going to and fro.

62
00:03:26,530 --> 00:03:33,050
So because we've just got this simple graph that we were invoking each time, there's nothing particularly

63
00:03:33,050 --> 00:03:34,770
interesting happening here.

64
00:03:34,810 --> 00:03:41,370
And the state uh, is just, just contains that that uh, doesn't contain the history or anything.

65
00:03:41,610 --> 00:03:44,850
So, uh, that's one of the things that we clearly need to address.

66
00:03:45,170 --> 00:03:47,370
And the good news is that we will indeed address it.

67
00:03:47,370 --> 00:03:49,450
But the bad news is not until tomorrow.

68
00:03:49,570 --> 00:03:56,170
But we'll also address things like tools, our old favorite, along with a couple of other things.

69
00:03:56,330 --> 00:03:58,010
So, uh, look forward to it.

70
00:03:58,010 --> 00:03:58,810
I'll see you then.