1
00:00:00,120 --> 00:00:00,680
Okay.
好的。

2
00:00:00,720 --> 00:00:03,560
So next we're going to actually put these tools to good use.
接下来我们将实际充分利用这些工具。

3
00:00:03,800 --> 00:00:08,920
So this thing here is a neat neat little bit of Python called a dictionary comprehension.
所以这里的这个东西是 Python 的一个简洁的小部分，称为字典理解。

4
00:00:08,920 --> 00:00:10,080
You might be very familiar with it.
你可能对它非常熟悉。

5
00:00:10,120 --> 00:00:11,760
If not check out the guides.
如果没有请查看指南。

6
00:00:11,760 --> 00:00:16,960
We put together a dictionary by iterating through tools and creating something where the key is the
我们通过迭代工具并创建一些其中关键是的东西来组合字典

7
00:00:16,960 --> 00:00:22,200
name of the tool, and the value is the tool itself, and that allows us to pluck out the navigate tool
工具的名称，值是工具本身，这使我们能够取出导航工具

8
00:00:22,240 --> 00:00:25,360
and the extract text tool from this list of tools.
以及此工具列表中的提取文本工具。

9
00:00:25,760 --> 00:00:32,240
And we're then going to call the navigate tool asynchronously navigate tool with the web address for
然后我们将使用以下网址异步调用导航工具：

10
00:00:32,240 --> 00:00:32,800
CNN.
美国有线电视新闻网。

11
00:00:33,200 --> 00:00:38,920
And then we're going to call await to extract the text from it and call this.
然后我们将调用await 从中提取文本并调用它。

12
00:00:38,920 --> 00:00:40,800
So this has got nothing to do with LMS.
所以这与 LMS 无关。

13
00:00:40,840 --> 00:00:47,120
This is all about running Microsoft Playwright with the tools that come with Lang Chain.
这都是关于使用 Lang Chain 附带的工具运行 Microsoft Playwright。

14
00:00:47,440 --> 00:00:48,440
And we'll run that.
我们将运行它。

15
00:00:48,440 --> 00:00:54,680
Up comes a browser, it turns to CNN and stuff is happening and that just completed.
出现了一个浏览器，它转向 CNN，事情正在发生，而且刚刚完成。

16
00:00:55,040 --> 00:00:56,200
And isn't that cool?
那不是很酷吗？

17
00:00:56,240 --> 00:01:00,160
It was like, I know it's got nothing to do with AI, but it's just great technology.
就像，我知道这与人工智能无关，但它只是一项伟大的技术。

18
00:01:00,200 --> 00:01:03,480
Come back here and we print the text and there we go.
回到这里，我们打印文本，然后开始。

19
00:01:03,520 --> 00:01:05,720
We've got the text from CNN.
我们收到了来自 CNN 的短信。

20
00:01:06,200 --> 00:01:07,560
Impressive stuff.
令人印象深刻的东西。

21
00:01:08,000 --> 00:01:12,760
So we can now package this together into one collection of tools.
所以我们现在可以将其打包成一个工具集合。

22
00:01:12,960 --> 00:01:18,440
These tools that we just got from playwright, plus our push notification tool in it goes.
这些工具是我们刚刚从剧作家那里得到的，加上我们的推送通知工具。

23
00:01:18,520 --> 00:01:21,960
And now it's time for us to make some agents.
现在是我们制作一些代理的时候了。

24
00:01:22,440 --> 00:01:29,040
So the first thing we do is we do some, some pre-work to create our LLM, which is GPT four mini.
因此，我们要做的第一件事就是做一些准备工作来创建我们的 LLM，即 GPT 4 mini。

25
00:01:29,080 --> 00:01:30,800
Feel free to switch in your favorites.
请随意切换您的最爱。

26
00:01:30,960 --> 00:01:33,000
And then we bind it to tools.
然后我们将它绑定到工具上。

27
00:01:33,000 --> 00:01:36,920
This you remember is what we do to deal with creating all of that JSON.
您还记得我们在创建所有 JSON 时所做的事情吗？

28
00:01:36,920 --> 00:01:37,960
For all of these tools.
对于所有这些工具。

29
00:01:37,960 --> 00:01:39,560
We've got a whole ton of tools now.
我们现在拥有大量工具。

30
00:01:39,600 --> 00:01:41,480
JSON will be built for all of them.
JSON 将为所有这些构建。

31
00:01:41,720 --> 00:01:44,560
And now this is our chat bot function.
现在这是我们的聊天机器人功能。

32
00:01:44,560 --> 00:01:47,160
This is something that is going to be one of our nodes.
这将成为我们的节点之一。

33
00:01:47,160 --> 00:01:54,480
Because a node is just a function and it's something which will call it will invoke LLM with tools passing
因为节点只是一个函数，它会调用它，并通过工具传递来调用 LLM

34
00:01:54,480 --> 00:01:55,800
in the messages.
在消息中。

35
00:01:55,800 --> 00:01:59,760
And what comes out will be shoved into messages and returned.
结果将被塞入消息并返回。

36
00:01:59,760 --> 00:02:06,160
And that, of course, is our the new state, and the reducer will be used to combine it with the old
当然，这就是我们的新状态，减速器将用于将其与旧状态结合起来

37
00:02:06,160 --> 00:02:06,840
state.
状态。

38
00:02:07,160 --> 00:02:08,880
So let's execute that.
那么让我们执行一下吧。

39
00:02:09,120 --> 00:02:10,280
That's great.
那太棒了。

40
00:02:10,280 --> 00:02:12,640
And now we have our graph.
现在我们有了图表。

41
00:02:12,680 --> 00:02:18,080
I think this is probably makes more sense to go here just to be nice and tidy.
我认为去这里只是为了变得漂亮和整洁可能更有意义。

42
00:02:18,320 --> 00:02:23,520
So we create our graph builder with the state that we've specified.
因此，我们使用指定的状态创建图形生成器。

43
00:02:23,800 --> 00:02:25,600
We add the chatbot node.
我们添加聊天机器人节点。

44
00:02:25,600 --> 00:02:27,320
That's this function we just got here.
这就是我们刚刚到达的这个功能。

45
00:02:27,520 --> 00:02:29,200
We add in our tools.
我们添加我们的工具。

46
00:02:29,880 --> 00:02:32,320
We then add in a conditional edge.
然后我们添加条件边。

47
00:02:32,360 --> 00:02:36,080
This is going to be the if statement implemented behind the scenes.
这将是在幕后实现的 if 语句。

48
00:02:36,680 --> 00:02:39,880
If the tools condition is true then tools will be called.
如果工具条件为真，则将调用工具。

49
00:02:40,320 --> 00:02:47,400
We add an edge from tools to chatbot and then we add from the start to the chatbot.
我们将工具的优势添加到聊天机器人，然后从头开始添加到聊天机器人。

50
00:02:48,120 --> 00:02:49,240
So I said agents.
所以我说的是代理。

51
00:02:49,240 --> 00:02:50,360
It's only one agent.
这只是一名经纪人。

52
00:02:50,360 --> 00:02:51,200
That's it.
就是这样。

53
00:02:51,240 --> 00:02:52,320
We get some memory.
我们得到一些记忆。

54
00:02:52,360 --> 00:02:56,080
We compile with that memory and we draw our image.
我们用这些记忆进行编译并绘制我们的图像。

55
00:02:56,360 --> 00:02:57,280
There it is.
就在那里。

56
00:02:57,640 --> 00:02:59,560
It's a an image we're familiar with.
这是我们熟悉的画面。

57
00:02:59,560 --> 00:03:00,560
It's the same as last time.
和上次一样。

58
00:03:00,560 --> 00:03:04,440
The only difference is that these tools are a bit meatier than we had before.
唯一的区别是这些工具比我们以前的工具更丰富一些。

59
00:03:04,440 --> 00:03:07,240
We now can control a browser window.
我们现在可以控制浏览器窗口。

60
00:03:07,280 --> 00:03:13,200
Okay, so here we have at the end our final, our gradio, uh, flow.
好的，我们到了最后，我们的渐变，呃，流程。

61
00:03:13,360 --> 00:03:15,720
So we're going to create a Gradio interface.
所以我们要创建一个 Gradio 界面。

62
00:03:15,960 --> 00:03:19,560
Um, we're going to use a function called chat as our callback.
嗯，我们将使用一个名为 chat 的函数作为回调。

63
00:03:19,560 --> 00:03:20,440
And here is chat.
这是聊天。

64
00:03:20,440 --> 00:03:21,880
It's an async function.
这是一个异步函数。

65
00:03:22,080 --> 00:03:23,360
Gradio supports functions.
Gradio 支持功能。

66
00:03:23,360 --> 00:03:25,640
It's callbacks being being async or being async.
回调是异步的还是异步的。

67
00:03:26,040 --> 00:03:30,440
And it's um, we're going to to just simply call our graph that we've already built.
嗯，我们将简单地调用我们已经构建的图表。

68
00:03:30,440 --> 00:03:36,880
We're going to call a invoke the asynchronous version we pass in our first state, which is the user
我们将调用我们在第一个状态（即用户）中传递的异步版本

69
00:03:36,880 --> 00:03:37,280
input.
输入。

70
00:03:37,280 --> 00:03:38,360
This is a super step.
这是一个超级步骤。

71
00:03:38,360 --> 00:03:43,000
So every input is like another run of the graph we pass in the config.
因此，每个输入就像我们在配置中传递的图形的另一次运行。

72
00:03:43,000 --> 00:03:44,200
So we have memory.
所以我们有记忆。

73
00:03:44,240 --> 00:03:47,840
We don't actually use the history because we're relying on checkpointing for that.
我们实际上并不使用历史记录，因为我们依赖于检查点。

74
00:03:47,840 --> 00:03:49,840
But Gradio sends it to us anyway.
但无论如何，Gradio 都会将其发送给我们。

75
00:03:50,000 --> 00:03:51,560
And that is our gradio code.
这就是我们的渐变代码。

76
00:03:51,560 --> 00:03:53,000
And with that let's run it.
然后让我们运行它。

77
00:03:53,520 --> 00:03:54,320
There it is.
就在那里。

78
00:03:54,360 --> 00:03:54,760
Okay.
好的。

79
00:03:54,800 --> 00:03:55,680
Let's say hi there.
我们在那里打个招呼吧。

80
00:03:58,080 --> 00:03:58,440
Okay.
好的。

81
00:03:58,480 --> 00:04:02,600
Let's say, uh, please send me a push notification.
比方说，呃，请给我发送推送通知。

82
00:04:05,600 --> 00:04:11,440
With a news headline news headline from CNN.
带有来自 CNN 的新闻标题。

83
00:04:12,640 --> 00:04:13,760
See what happens there.
看看那里会发生什么。

84
00:04:13,960 --> 00:04:14,960
There goes the browser.
浏览器消失了。

85
00:04:15,000 --> 00:04:15,360
It's.
它是。

86
00:04:15,640 --> 00:04:16,800
I'm not touching it.
我不碰它。

87
00:04:23,360 --> 00:04:23,840
Haha.
哈哈。

88
00:04:24,640 --> 00:04:25,800
Have you expecting that?
你期待吗？

89
00:04:26,000 --> 00:04:26,960
We got a text.
我们收到一条短信。

90
00:04:26,960 --> 00:04:32,840
I could see the push and it says indeed this push notification about news going on.
我可以看到推送，它确实显示了有关正在发生的新闻的推送通知。

91
00:04:33,320 --> 00:04:34,320
Very cool.
非常酷。

92
00:04:34,360 --> 00:04:35,960
All right, let's try another.
好吧，我们再尝试一下。

93
00:04:36,280 --> 00:04:47,880
Uh, please, uh, send me a push notification with the current usd GBP exchange rate.
呃，请呃，给我发送一条包含当前美元英镑汇率的推送通知。

94
00:04:53,760 --> 00:04:55,240
The browser is still running behind.
浏览器仍然落后。

95
00:04:55,240 --> 00:04:56,960
Let me just bring that up there.
让我把这个提一下。

96
00:04:57,000 --> 00:05:00,480
It's gone to an exchange rates page and we got the push notification.
它进入了汇率页面，我们收到了推送通知。

97
00:05:00,480 --> 00:05:01,000
There he is.
他就在那里。

98
00:05:01,040 --> 00:05:01,480
Yep.
是的。

99
00:05:01,680 --> 00:05:04,080
And it is a different than yesterday.
而且与昨天不同。

100
00:05:04,480 --> 00:05:07,000
Down by a little bit 0.77 instead of 0.78.
下降了一点点 0.77，而不是 0.78。

101
00:05:07,520 --> 00:05:08,440
That's amazing.
太棒了。

102
00:05:08,440 --> 00:05:09,160
So there you go.
所以就这样吧。

103
00:05:09,200 --> 00:05:10,120
There you have it.
给你了。

104
00:05:10,360 --> 00:05:14,480
Uh, that is a really powerful tool in playwright.
呃，这对于剧作家来说是一个非常强大的工具。

105
00:05:14,480 --> 00:05:21,080
And isn't it amazing that we've now armed our agent to be able to drive a browser?
我们现在已经武装了我们的代理以能够驱动浏览器，这不是很令人惊讶吗？

106
00:05:21,080 --> 00:05:26,600
And you can start to see when you think of the excitement people have around things like Manus and this
当你想到人们对像马努斯这样的事情的兴奋时，你就会开始明白

107
00:05:26,600 --> 00:05:34,200
idea of agents that can drive, you can now see how this could become an agent that can drive a browser
可以驱动的代理的想法，您现在可以看到它如何成为可以驱动浏览器的代理

108
00:05:34,200 --> 00:05:35,720
and do work for you.
并为你做事。

109
00:05:35,960 --> 00:05:40,800
And of course, that is what we're coming to for this week's big project.
当然，这就是我们本周的大项目的目的。

110
00:05:41,000 --> 00:05:44,640
And I thought it'd be nice to just bring this up in Lang Smith for a second to show what it looks like.
我认为最好在 Lang Smith 中提出这一点，以展示它的样子。

111
00:05:44,760 --> 00:05:46,120
Uh, here we have it.
呃，我们这里有。

112
00:05:46,280 --> 00:05:52,600
Uh, you can see, if you look, that there was a fair amount of interactions that went on the process
呃，如果你看的话，你会发现这个过程中有相当多的互动

113
00:05:52,600 --> 00:05:55,680
of going around the browser and and doing various things.
浏览浏览器并做各种事情。

114
00:05:55,680 --> 00:05:57,520
It takes a little bit of interaction.
这需要一点互动。

115
00:05:57,680 --> 00:06:01,520
It takes, of course, doing some navigation, navigating and reading.
当然，这需要进行一些导航、导航和阅读。

116
00:06:01,680 --> 00:06:03,840
And if we look on the right, we can see what happened here.
如果我们向右看，我们可以看到这里发生了什么。

117
00:06:03,840 --> 00:06:05,280
This is the human making that.
这是人类造成的。

118
00:06:05,680 --> 00:06:06,760
So I said hi there.
所以我就在那里打招呼。

119
00:06:06,760 --> 00:06:07,400
It said, hello.
它说，你好。

120
00:06:07,440 --> 00:06:09,120
How can I assist you today.
今天我能为您提供什么帮助。

121
00:06:09,240 --> 00:06:16,960
Please send me push notification and then you can see it uh it called to visit navigate browser to CNN.com.
请向我发送推送通知，然后您就可以看到它，它调用了导航浏览器访问 CNN.com。

122
00:06:16,960 --> 00:06:23,800
So I think yeah I just said CNN so it knew to look up that that web page um and then it knew to navigate
所以我想是的，我刚才说的是 CNN，所以它知道查找该网页，然后它知道导航

123
00:06:23,840 --> 00:06:25,720
it extracted hyperlinks.
它提取了超链接。

124
00:06:25,720 --> 00:06:28,240
It looked at some hyperlinks, it did some stuff.
它查看了一些超链接，做了一些事情。

125
00:06:28,440 --> 00:06:31,600
And then it ended up sending a push notification.
然后它最终发送了一条推送通知。

126
00:06:31,920 --> 00:06:37,080
Uh, I noticed that I've got the tool returning just null, which is probably a bad thing.
呃，我注意到该工具仅返回 null，这可能是一件坏事。

127
00:06:37,080 --> 00:06:42,720
I should have it returning like some some fake JSON that says success or something so that it doesn't,
我应该让它像一些假的 JSON 一样返回，表示成功或其他内容，这样它就不会返回，

128
00:06:42,720 --> 00:06:45,360
uh, so, so that it just sort of lands better.
呃，所以，这样效果会更好。

129
00:06:45,400 --> 00:06:48,360
It's more coherent with the, with the call of the tool.
它与工具的调用更加一致。

130
00:06:48,360 --> 00:06:49,720
So I will make that change.
所以我会做出改变。

131
00:06:50,040 --> 00:06:56,800
Uh, and then, um, you can see that it then goes to exchange rates, it pulls that out, it gets the
呃，然后，嗯，你可以看到它然后转到汇率，它把它拉出来，它得到了

132
00:06:56,800 --> 00:06:59,440
results, it extracts all of the text.
结果，它提取了所有文本。

133
00:06:59,600 --> 00:07:02,360
And then once more it sends a push notification.
然后它再次发送推送通知。

134
00:07:02,400 --> 00:07:04,560
So it's great to see this trace.
所以很高兴看到这个痕迹。

135
00:07:04,560 --> 00:07:07,240
And then you can see some other information about this too.
然后你还可以看到一些与此相关的其他信息。

136
00:07:07,280 --> 00:07:09,520
I think I got to see over here.
我想我得看看这里。

137
00:07:09,560 --> 00:07:09,760
Yep.
是的。

138
00:07:09,800 --> 00:07:13,720
The total number of tokens that were exchanged with GPT four mini.
与 GPT 4 mini 交换的代币总数。

139
00:07:14,000 --> 00:07:20,840
And the fact that the total cost was, uh, $0.10 out of.
事实上，总成本是，呃，0.10 美元。

140
00:07:20,880 --> 00:07:21,080
Oh, no.
哦，不。

141
00:07:21,120 --> 00:07:22,760
That's from from all of the runs.
这是来自所有运行的结果。

142
00:07:22,760 --> 00:07:24,680
I was going to say that would be expensive.
我本来想说那会很贵。

143
00:07:24,920 --> 00:07:29,680
Uh, and I've been doing a lot of runs, so, so so you should not have spent $0.10.
呃，我已经跑了很多次了，所以，所以你不应该花 0.10 美元。

144
00:07:29,880 --> 00:07:34,520
Uh, that was, in fact, 0.8 of a cent for that whole conversation.
呃，事实上，整个谈话只花费了 0.8 美分。

145
00:07:34,720 --> 00:07:38,120
Uh, and if you've been using a llama, then it wouldn't have cost you anything, but you might have
呃，如果你一直在使用美洲驼，那么它不会花费你任何费用，但你可能会

146
00:07:38,120 --> 00:07:41,480
had more coherence issues because we're expecting a lot.
有更多的连贯性问题，因为我们期待很多。

147
00:07:41,520 --> 00:07:43,840
You probably needed to use a larger model.
您可能需要使用更大的模型。

148
00:07:44,080 --> 00:07:46,160
Um, but certainly worth experimenting with.
嗯，但确实值得尝试。

149
00:07:46,160 --> 00:07:52,080
But if you chose to splash out and use GPT four on many, it would have cost you all of 0.8 of a cent.
但如果您选择花大价钱在许多设备上使用 GPT 4，那么您将花费 0.8 美分。

150
00:07:52,360 --> 00:07:57,680
Uh, so, uh, you can see that these things and obviously they can rack up over time if you use it
呃，所以，呃，你可以看到这些东西，如果你使用它，它们显然会随着时间的推移而积累

151
00:07:57,720 --> 00:07:58,600
extensively.
广泛地。

152
00:07:58,600 --> 00:08:03,160
But for any one given call, it is, uh, relatively low cost.
但对于任何一个给定的呼叫来说，呃，成本相对较低。
