Okay. 好的。
So next we're going to actually put these tools to good use. 接下来我们将实际充分利用这些工具。
So this thing here is a neat neat little bit of Python called a dictionary comprehension. 所以这里的这个东西是 Python 的一个简洁的小部分，称为字典理解。
You might be very familiar with it. 你可能对它非常熟悉。
If not check out the guides. 如果没有请查看指南。
We put together a dictionary by iterating through tools and creating something where the key is the 我们通过迭代工具并创建一些其中关键是的东西来组合字典
name of the tool, and the value is the tool itself, and that allows us to pluck out the navigate tool 工具的名称，值是工具本身，这使我们能够取出导航工具
and the extract text tool from this list of tools. 以及此工具列表中的提取文本工具。
And we're then going to call the navigate tool asynchronously navigate tool with the web address for 然后我们将使用以下网址异步调用导航工具：
CNN. 美国有线电视新闻网。
And then we're going to call await to extract the text from it and call this. 然后我们将调用await 从中提取文本并调用它。
So this has got nothing to do with LMS. 所以这与 LMS 无关。
This is all about running Microsoft Playwright with the tools that come with Lang Chain. 这都是关于使用 Lang Chain 附带的工具运行 Microsoft Playwright。
And we'll run that. 我们将运行它。
Up comes a browser, it turns to CNN and stuff is happening and that just completed. 出现了一个浏览器，它转向 CNN，事情正在发生，而且刚刚完成。
And isn't that cool? 那不是很酷吗？
It was like, I know it's got nothing to do with AI, but it's just great technology. 就像，我知道这与人工智能无关，但它只是一项伟大的技术。
Come back here and we print the text and there we go. 回到这里，我们打印文本，然后开始。
We've got the text from CNN. 我们收到了来自 CNN 的短信。
Impressive stuff. 令人印象深刻的东西。
So we can now package this together into one collection of tools. 所以我们现在可以将其打包成一个工具集合。
These tools that we just got from playwright, plus our push notification tool in it goes. 这些工具是我们刚刚从剧作家那里得到的，加上我们的推送通知工具。
And now it's time for us to make some agents. 现在是我们制作一些代理的时候了。
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。
Feel free to switch in your favorites. 请随意切换您的最爱。
And then we bind it to tools. 然后我们将它绑定到工具上。
This you remember is what we do to deal with creating all of that JSON. 您还记得我们在创建所有 JSON 时所做的事情吗？
For all of these tools. 对于所有这些工具。
We've got a whole ton of tools now. 我们现在拥有大量工具。
JSON will be built for all of them. JSON 将为所有这些构建。
And now this is our chat bot function. 现在这是我们的聊天机器人功能。
This is something that is going to be one of our nodes. 这将成为我们的节点之一。
Because a node is just a function and it's something which will call it will invoke LLM with tools passing 因为节点只是一个函数，它会调用它，并通过工具传递来调用 LLM
in the messages. 在消息中。
And what comes out will be shoved into messages and returned. 结果将被塞入消息并返回。
And that, of course, is our the new state, and the reducer will be used to combine it with the old 当然，这就是我们的新状态，减速器将用于将其与旧状态结合起来
state. 状态。
So let's execute that. 那么让我们执行一下吧。
That's great. 那太棒了。
And now we have our graph. 现在我们有了图表。
I think this is probably makes more sense to go here just to be nice and tidy. 我认为去这里只是为了变得漂亮和整洁可能更有意义。
So we create our graph builder with the state that we've specified. 因此，我们使用指定的状态创建图形生成器。
We add the chatbot node. 我们添加聊天机器人节点。
That's this function we just got here. 这就是我们刚刚到达的这个功能。
We add in our tools. 我们添加我们的工具。
We then add in a conditional edge. 然后我们添加条件边。
This is going to be the if statement implemented behind the scenes. 这将是在幕后实现的 if 语句。
If the tools condition is true then tools will be called. 如果工具条件为真，则将调用工具。
We add an edge from tools to chatbot and then we add from the start to the chatbot. 我们将工具的优势添加到聊天机器人，然后从头开始添加到聊天机器人。
So I said agents. 所以我说的是代理。
It's only one agent. 这只是一名经纪人。
That's it. 就是这样。
We get some memory. 我们得到一些记忆。
We compile with that memory and we draw our image. 我们用这些记忆进行编译并绘制我们的图像。
There it is. 就在那里。
It's a an image we're familiar with. 这是我们熟悉的画面。
It's the same as last time. 和上次一样。
The only difference is that these tools are a bit meatier than we had before. 唯一的区别是这些工具比我们以前的工具更丰富一些。
We now can control a browser window. 我们现在可以控制浏览器窗口。
Okay, so here we have at the end our final, our gradio, uh, flow. 好的，我们到了最后，我们的渐变，呃，流程。
So we're going to create a Gradio interface. 所以我们要创建一个 Gradio 界面。
Um, we're going to use a function called chat as our callback. 嗯，我们将使用一个名为 chat 的函数作为回调。
And here is chat. 这是聊天。
It's an async function. 这是一个异步函数。
Gradio supports functions. Gradio 支持功能。
It's callbacks being being async or being async. 回调是异步的还是异步的。
And it's um, we're going to to just simply call our graph that we've already built. 嗯，我们将简单地调用我们已经构建的图表。
We're going to call a invoke the asynchronous version we pass in our first state, which is the user 我们将调用我们在第一个状态（即用户）中传递的异步版本
input. 输入。
This is a super step. 这是一个超级步骤。
So every input is like another run of the graph we pass in the config. 因此，每个输入就像我们在配置中传递的图形的另一次运行。
So we have memory. 所以我们有记忆。
We don't actually use the history because we're relying on checkpointing for that. 我们实际上并不使用历史记录，因为我们依赖于检查点。
But Gradio sends it to us anyway. 但无论如何，Gradio 都会将其发送给我们。
And that is our gradio code. 这就是我们的渐变代码。
And with that let's run it. 然后让我们运行它。
There it is. 就在那里。
Okay. 好的。
Let's say hi there. 我们在那里打个招呼吧。
Okay. 好的。
Let's say, uh, please send me a push notification. 比方说，呃，请给我发送推送通知。
With a news headline news headline from CNN. 带有来自 CNN 的新闻标题。
See what happens there. 看看那里会发生什么。
There goes the browser. 浏览器消失了。
It's. 它是。
I'm not touching it. 我不碰它。
Haha. 哈哈。
Have you expecting that? 你期待吗？
We got a text. 我们收到一条短信。
I could see the push and it says indeed this push notification about news going on. 我可以看到推送，它确实显示了有关正在发生的新闻的推送通知。
Very cool. 非常酷。
All right, let's try another. 好吧，我们再尝试一下。
Uh, please, uh, send me a push notification with the current usd GBP exchange rate. 呃，请呃，给我发送一条包含当前美元英镑汇率的推送通知。
The browser is still running behind. 浏览器仍然落后。
Let me just bring that up there. 让我把这个提一下。
It's gone to an exchange rates page and we got the push notification. 它进入了汇率页面，我们收到了推送通知。
There he is. 他就在那里。
Yep. 是的。
And it is a different than yesterday. 而且与昨天不同。
Down by a little bit 0.77 instead of 0.78. 下降了一点点 0.77，而不是 0.78。
That's amazing. 太棒了。
So there you go. 所以就这样吧。
There you have it. 给你了。
Uh, that is a really powerful tool in playwright. 呃，这对于剧作家来说是一个非常强大的工具。
And isn't it amazing that we've now armed our agent to be able to drive a browser? 我们现在已经武装了我们的代理以能够驱动浏览器，这不是很令人惊讶吗？
And you can start to see when you think of the excitement people have around things like Manus and this 当你想到人们对像马努斯这样的事情的兴奋时，你就会开始明白
idea of agents that can drive, you can now see how this could become an agent that can drive a browser 可以驱动的代理的想法，您现在可以看到它如何成为可以驱动浏览器的代理
and do work for you. 并为你做事。
And of course, that is what we're coming to for this week's big project. 当然，这就是我们本周的大项目的目的。
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 中提出这一点，以展示它的样子。
Uh, here we have it. 呃，我们这里有。
Uh, you can see, if you look, that there was a fair amount of interactions that went on the process 呃，如果你看的话，你会发现这个过程中有相当多的互动
of going around the browser and and doing various things. 浏览浏览器并做各种事情。
It takes a little bit of interaction. 这需要一点互动。
It takes, of course, doing some navigation, navigating and reading. 当然，这需要进行一些导航、导航和阅读。
And if we look on the right, we can see what happened here. 如果我们向右看，我们可以看到这里发生了什么。
This is the human making that. 这是人类造成的。
So I said hi there. 所以我就在那里打招呼。
It said, hello. 它说，你好。
How can I assist you today. 今天我能为您提供什么帮助。
Please send me push notification and then you can see it uh it called to visit navigate browser to CNN.com. 请向我发送推送通知，然后您就可以看到它，它调用了导航浏览器访问 CNN.com。
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，所以它知道查找该网页，然后它知道导航
it extracted hyperlinks. 它提取了超链接。
It looked at some hyperlinks, it did some stuff. 它查看了一些超链接，做了一些事情。
And then it ended up sending a push notification. 然后它最终发送了一条推送通知。
Uh, I noticed that I've got the tool returning just null, which is probably a bad thing. 呃，我注意到该工具仅返回 null，这可能是一件坏事。
I should have it returning like some some fake JSON that says success or something so that it doesn't, 我应该让它像一些假的 JSON 一样返回，表示成功或其他内容，这样它就不会返回，
uh, so, so that it just sort of lands better. 呃，所以，这样效果会更好。
It's more coherent with the, with the call of the tool. 它与工具的调用更加一致。
So I will make that change. 所以我会做出改变。
Uh, and then, um, you can see that it then goes to exchange rates, it pulls that out, it gets the 呃，然后，嗯，你可以看到它然后转到汇率，它把它拉出来，它得到了
results, it extracts all of the text. 结果，它提取了所有文本。
And then once more it sends a push notification. 然后它再次发送推送通知。
So it's great to see this trace. 所以很高兴看到这个痕迹。
And then you can see some other information about this too. 然后你还可以看到一些与此相关的其他信息。
I think I got to see over here. 我想我得看看这里。
Yep. 是的。
The total number of tokens that were exchanged with GPT four mini. 与 GPT 4 mini 交换的代币总数。
And the fact that the total cost was, uh, $0.10 out of. 事实上，总成本是，呃，0.10 美元。
Oh, no. 哦，不。
That's from from all of the runs. 这是来自所有运行的结果。
I was going to say that would be expensive. 我本来想说那会很贵。
Uh, and I've been doing a lot of runs, so, so so you should not have spent $0.10. 呃，我已经跑了很多次了，所以，所以你不应该花 0.10 美元。
Uh, that was, in fact, 0.8 of a cent for that whole conversation. 呃，事实上，整个谈话只花费了 0.8 美分。
Uh, and if you've been using a llama, then it wouldn't have cost you anything, but you might have 呃，如果你一直在使用美洲驼，那么它不会花费你任何费用，但你可能会
had more coherence issues because we're expecting a lot. 有更多的连贯性问题，因为我们期待很多。
You probably needed to use a larger model. 您可能需要使用更大的模型。
Um, but certainly worth experimenting with. 嗯，但确实值得尝试。
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 美分。
Uh, so, uh, you can see that these things and obviously they can rack up over time if you use it 呃，所以，呃，你可以看到这些东西，如果你使用它，它们显然会随着时间的推移而积累
extensively. 广泛地。
But for any one given call, it is, uh, relatively low cost. 但对于任何一个给定的呼叫来说，呃，成本相对较低。