Wow. 哇。
You've come back for week two. 你已经回来第二周了。
Listen, you're not gonna regret it. 听着，你不会后悔的。
I have such a fabulous week lined up for you. 我为你准备了美好的一周。
And it starts today with. 从今天开始。
With. 和。
We've got such a huge lab today. 今天我们有一个如此巨大的实验室。
Such a gigantic lab. 这么大的实验室。
First of all, what can you already do? 首先，你已经可以做什么？
You've had your introduction to Transformers with tokens context. 您已经通过令牌上下文介绍了 Transformer。
Windows API costs the memory illusion and so on. Windows API 会消耗内存错觉等等。
You can contrast the leading frontier models and you can confidently use OpenAI's API including streaming 您可以对比领先的前沿模型，并且可以自信地使用 OpenAI 的 API，包括流式处理
markdown JSON. 降价 JSON。
Okay, today. 好吧，今天。
Today is big API day. 今天是 API 日。
Today we are going to cover so many APIs. 今天我们将介绍很多 API。
You're going to have had enough of APIs. 您已经受够了 API。
We're going to connect to many different frontier models. 我们将连接到许多不同的前沿模型。
We're going to use routers and abstraction layers. 我们将使用路由器和抽象层。
And we're also going to write some code that interacts between different frontier models. 我们还将编写一些在不同前沿模型之间交互的代码。
We're going to have them talk to each other, not just to us. 我们会让他们互相交谈，而不仅仅是我们。
All right. 好的。
So much to get done. 有这么多事情要做。
But let me quickly remind you of the journey we started on the left. 但让我快速提醒您我们从左侧开始的旅程。
You were there. 你当时就在那里。
We covered the The foundations the chat completions API last week. 上周我们介绍了聊天完成 API 的基础。
This week it's about frontier models. 本周的主题是前沿模型。
With APIs, we're going to build UIs with the amazing Gradio and we're going to build multi-modal stuff. 借助 API，我们将使用令人惊叹的 Gradio 构建 UI，并且我们将构建多模式内容。
And then next week open source with Hugging Face the week after picking the right LLM. 然后下周在选择合适的法学硕士后一周与 Hugging Face 开源。
That crucial topic the week after that. 在那之后的一周，这个至关重要的话题。
It's all rag rag rag rag on week five. 第五周一切都是破烂破破烂烂。
But don't jump there. 但不要跳到那里。
This week is so great. 这周真是太棒了。
Week six is about fine tuning a frontier model and traditional data science. 第六周是关于微调前沿模型和传统数据科学。
Week seven is about fine tuning an open source model with shocking results and week eight finale Agentic 第七周是关于微调开源模型，其结果令人震惊，第八周的结局是 Agentic
AI. 人工智能。
That is everything I have in store for you. 这就是我为你准备的一切。
But but trust me, you don't want to miss this week. 但是相信我，你不想错过本周。
It's it's a really great one. 这真是太棒了。
And at the end when you've got past week eight, you will of course be able to say you have mastered 最后，当你度过第八周时，你当然可以说你已经掌握了
LLM engineering. 法学硕士工程。
Now, what we're going to do today is a lot more calling to lots more frontier models. 现在，我们今天要做的就是更多地调用更多前沿模型。
And that's going to involve setting up more keys. 这将涉及设置更多密钥。
And I'm here to tell you that this is optional. 我在这里告诉你这是可选的。
If you've already set up the OpenAI key, that's great. 如果您已经设置了 OpenAI 密钥，那就太好了。
We'll use some of that. 我们将使用其中的一些。
If you haven't, you can just use Olama for everything. 如果还没有，您可以使用 Olama 来完成所有操作。
There's also something called Open Router that I will mention that you can use that will allow you to 还有一个叫做“开放路由器”的东西，我会提到你可以使用它来
do everything, but should you wish to. 做一切事情，但如果你愿意的话。
Another couple of keys Anthropic and Google. 另外几个键 Anthropic 和 Google。
The Google one I do believe is free in many situations. 我相信谷歌在很多情况下都是免费的。
So you may find that when you go to Google, I'll give you the link you'll be able to set one up for 因此，您可能会发现，当您访问 Google 时，我会给您一个链接，您可以为其设置一个链接
free. 自由的。
And Tropic does have a cost. Tropic 确实有成本。
Now I personally love anthropic. 现在我个人很喜欢人类。
I would always recommend if you if you can afford it. 如果你能负担得起的话，我总是会推荐你。
If you've got the budget to spend that $5, it will be money well spent. 如果您有足够的预算花这 5 美元，那么这笔钱花得值。
You'll get great use out of Claude, but only do it if you're comfortable with that. 你会从克劳德那里得到很大的利用，但只有当你对此感到满意时才这样做。
But once you have updated your you've gone to the website that I will give you a link to. 但是，一旦您更新了您的内容，您就可以访问我将为您提供链接的网站。
You've set up your account, you'll get an API key. 您已设置帐户，您将获得 API 密钥。
You will then need to update your EMV file with that API key. 然后，您需要使用该 API 密钥更新您的 EMV 文件。
You'll need to save it in the EMV file and make sure that it's saved for everything to work, but that 您需要将其保存在 EMV 文件中，并确保保存后一切才能正常工作，但是
that's all the slides I've got for, you. 这就是我为你准备的所有幻灯片。
No, no more slides. 不，不再有幻灯片了。
The rest of this session. 本次会议的剩余时间。
The rest of week two. 第二周剩下的时间。
Day one is all lab. 第一天都是实验室。
And wow, is it a big lab. 哇，这是一个大实验室吗？
Let's go there now. 我们现在就去那里吧。
Okay, so here I am in Cursa and I'm going now to week two. 好的，我现在在库萨，现在要进入第二周了。
Week two. 第二周。
And I'm going to day one. 我要去第一天。
The day one lab in week two. 第二周的第一天实验室。
Here we are. 我们到了。
So I start with an important note that I am always updating these labs. 因此，我首先要强调的是，我一直在更新这些实验室。
I'm constantly refining them. 我不断地完善它们。
So at the start of the week, it's always worth checking at this point that you've got the latest code. 因此，在本周开始时，总是值得检查一下您是否拥有最新的代码。
And you'll find in the git instructions and the git guide, there are steps for how you make sure you've 您会在 git 说明和 git 指南中找到如何确保您已完成的步骤
updated the latest code. 更新了最新的代码。
If you've made changes to these labs, you might want to merge your changes with my latest. 如果您对这些实验室进行了更改，您可能希望将您的更改与我的最新更改合并。
And. 和。
But you should do that. 但你应该这样做。
Now, the wonderful thing about UV is that because we're using UV, it will automatically then update 现在，UV 的美妙之处在于，因为我们使用的是 UV，所以它会自动更新
any packages that you need. 您需要的任何软件包。
You don't need to rebuild an environment or anything like that, which is great. 您不需要重建环境或类似的东西，这很棒。
But but you do need to pull the code. 但是你确实需要提取代码。
So to check that out. 所以要检查一下。
Check out these instructions. 查看这些说明。
And then one more reminder about the resources page that you can link to, which has other things like 然后再提醒您可以链接到的资源页面，其中还有其他内容，例如
the slides for the. 的幻灯片。
Of course, not that we had any slides today because we're getting straight to the lab. 当然，我们今天并不是有任何幻灯片，因为我们要直接进入实验室。
All right. 好的。
Let's go on with week two. 让我们继续第二周。
Day one lab. 第一天实验室。
So today is all about using APIs to connect to many models just like we used the user interfaces, the 所以今天的主题是使用 API 连接到许多模型，就像我们使用用户界面一样
products last week. 上周的产品。
So we're going to be going through the APIs. 因此，我们将详细介绍 API。
And you shouldn't feel like you need to to connect to these APIs. 而且您不应该觉得需要连接到这些 API。
I'm going to do it through lots of them so that you can live vicariously through me. 我将通过他们中的很多人来做到这一点，这样你就可以通过我来代替生活。
You can enjoy what I do, but should you wish to, then you can as well. 你可以享受我所做的事情，但如果你愿意，那么你也可以。
So here are the links if you wish to. 如果您愿意，这里是链接。
You've already gone to OpenAI to set that up before that. 在此之前您已经访问 OpenAI 进行了设置。
Here is the links for anthropic for Claude, Google for Gemini deep seq, AI for deep seq grok with 以下是 Claude 的 anthropic、Gemini deep seq 的 Google、deep seq grok 的 AI 的链接
a Q. 一个问。
And I will explain the difference in a minute between grok with a q and grok with a k. 我将在一分钟内解释带有 q 的 grok 和带有 k 的 grok 之间的区别。
Um. 一。
Also, should you wish, there is another alternative to going to all of these websites. 另外，如果您愿意，除了访问所有这些网站之外，还有另一种选择。
There is a platform called Open Router and Open Router. 有一个平台叫做Open Router和Open Router。
Is this really cool way that you can you can have one account with open router AI. 这是一种非常酷的方式，您可以拥有一个具有开放路由器 AI 的帐户。
And when you specify the model, you can choose any of these models and from any of these providers. 当您指定模型时，您可以选择任何这些模型并从任何这些提供程序中选择。
And that gives you like one account, one amount to pay up front. 这样您就可以拥有一个帐户，只需预付一笔金额。
And you can access all of them. 您可以访问所有这些。
And what I'm going to do is I'm going to go through and connect to each of these. 我要做的就是仔细研究并连接到其中的每一个。
But I'm also then going to show you Open router. 但接下来我还将向您展示开放路由器。
So if you wish you can you can choose just to go with Open Router. 因此，如果您愿意，您可以选择使用开放路由器。
Hang on in there and come back and try out all the different models via open router. 坚持住，然后回来通过开放路由器尝试所有不同的模型。
But we'll do it all today okay. 但我们今天会把这一切都做好。
So when you've gone to each of these sites, you would go to their billing page to add the minimum top 因此，当您访问这些网站中的每一个时，您将转到他们的计费页面以添加最低顶部
up. 向上。
So OpenAI's $5 at least as of now. 所以 OpenAI 目前至少是 5 美元。
Anthropic also $5. 人为也5美元。
Google I believe has a free tier. 我相信谷歌有免费套餐。
Deep seq I believe is $2 up front. 我认为 Deep seq 的预付费用是 2 美元。
They need grok, I think also has a free tier and grok with a k, I don't know. 他们需要 grok，我想也有一个免费套餐，而 grok 带有 k，我不知道。
They they change a lot. 他们改变了很多。
They might have a free tier as well. 他们也可能有免费套餐。
I'm pretty sure they do, actually. 事实上，我很确定他们确实这么做了。
All right. 好的。
So once you have done that, you then go to the API key page for all of these. 因此，一旦完成此操作，您就可以转到 API 密钥页面来获取所有这些内容。
And you collect your API key the same as with open AI. 您可以像开放 AI 一样收集 API 密钥。
You have to make sure that you give it all the right access, and then you have to put it in your dot 您必须确保授予它所有正确的访问权限，然后您必须将其放入您的点中
EMV file. EMV 文件。
You know the drill. 你知道该怎么做。
Now you put this in here. 现在你把它放在这里。
Any one of these keys, you can choose none of them. 这些键中的任何一个，您都不能选择。
If you don't wish any one of these keys, um, put them in the env file. 如果您不希望使用这些密钥中的任何一个，嗯，请将它们放入 env 文件中。
You need to spell it right. 你需要拼写正确。
Any typo and it's not going to work. 任何拼写错误都不会起作用。
Then you need to save the file. 然后您需要保存文件。
Make sure the white blob goes away. 确保白色斑点消失。
Uh, but the one with the stop sign is fine, as I explained last week. 呃，但是有停车标志的就可以，正如我上周解释的那样。
And, uh, then make sure any time you change it, you save it and you have to rerun, load underscore 并且，呃，然后确保每次更改它时，保存它并且必须重新运行，加载下划线
EMV. 电磁势。
And that is what we will do right now. 这就是我们现在要做的。
So I will, uh, I will run that cell. 所以我会，呃，我会运行那个单元。
Um, it's telling me that we don't need this here, so I'll take that out. 嗯，它告诉我我们这里不需要这个，所以我会把它拿出来。
Uh, run that cell. 呃，运行那个单元格。
And now this is where I load in all of my API keys. 现在这是我加载所有 API 密钥的地方。
And then I just check them that they all look good. 然后我只是检查它们看起来都不错。
And you can see that I have a lot of API keys. 你可以看到我有很多 API 密钥。
I've signed up for all these things. 我已经报名参加了所有这些事情。
I'm a sucker. 我是个傻瓜。
You don't need to. 你不需要。
As you wish. 如你所愿。
You can watch me. 你可以关注我。
I've got OpenAI, anthropic, Google, uh, deep seq grok with a Q, grok with a K and open router. 我有 OpenAI、anthropic、Google、呃、带有 Q 的 Deep seq grok、带有 K 的 grok 和开放路由器。
All right. 好的。
Now, of course, you remember OpenAI equals OpenAI. 现在，当然，您还记得 OpenAI 等于 OpenAI。
This is a way of us creating the lightweight Python client library so that we can connect to their endpoint. 这是我们创建轻量级 Python 客户端库的一种方法，以便我们可以连接到它们的端点。
And what you also remember, I'm sure, is that there is this nice little trick that we can use to connect 我相信你还记得，我们可以用这个漂亮的小技巧来连接
to any other model, any other provider, just reusing the same Python client library. 对于任何其他模型、任何其他提供商，只需重用相同的 Python 客户端库即可。
Now, later, we will use a couple of the dedicated client libraries that Anthropic and Google Gemini 现在，稍后，我们将使用 Anthropic 和 Google Gemini 的几个专用客户端库
both have their own libraries, but you don't need to. 两者都有自己的库，但您不需要。
And honestly, it's becoming increasingly common in industry for people just to always use OpenAI's 老实说，人们总是使用 OpenAI 在行业中变得越来越普遍
client library. 客户端库。
But we'll do both today. 但今天我们将两者都做。
All right. 好的。
So I run that and I've just created all of these client libraries. 所以我运行它并且刚刚创建了所有这些客户端库。
And I've also of course again done this trick where I've created one for llama as well. 当然，我也再次完成了这个技巧，我也为美洲驼创建了一个。
All right. 好的。
So far so good. 到目前为止，一切都很好。
We've got lots of keys, lots of client libraries. 我们有很多密钥，很多客户端库。
It's time for us to talk to lots of LMS. 现在是我们与许多 LMS 交谈的时候了。
Okay, so first of all, I've got a message to send an LLM, and it's called Tell a joke. 好的，首先，我收到一条消息要发送法学硕士，它的名字叫“讲一个笑话”。
And it is a list of dictionaries. 这是一个字典列表。
Remember, they're always a list of dictionaries and it has just a user prompt. 请记住，它们始终是字典列表，并且只有用户提示。
You don't actually need to have a system prompt. 您实际上不需要系统提示。
And if all you're going to put in your system prompt is you're a helpful assistant, it doesn't really 如果您要在系统提示中输入的只是您是一个有用的助手，那实际上并没有什么意义
make any difference. 有任何区别。
You don't you don't need it at all. 你不知道，你根本不需要它。
So we haven't got a system prompt, just a user prompt. 所以我们没有系统提示，只有用户提示。
Tell a joke for a student. 给学生讲个笑话。
Two A's for a student on the journey to becoming an expert in LLM engineering. 一名正在成为 LLM 工程专家的学生获得了两个 A。
All right. 好的。
So now we want to make that call to GPT 4.1 mini, one of my very favorite models to use quick and nice. 所以现在我们想要调用 GPT 4.1 mini，这是我最喜欢的模型之一，使用起来又快又好。
And how do we do it again? 我们该如何再次做到这一点？
We say response is open AI chat bot completions, create chat completions API. 我们说响应是开放AI聊天机器人完成，创建聊天完成API。
The model we're going to use is GPT 4.1 mini. 我们要使用的模型是 GPT 4.1 mini。
And the message is we'll finish it off is tell a joke. 传达的信息是我们会讲一个笑话来结束它。
And with what comes back we'll say display markdown of response .0. message content. 对于返回的内容，我们会说显示响应 .0 的降价。消息内容。
All right. 好的。
Let's see what kind of joke GPT 4.1 mini can say. 看看GPT 4.1 mini能开什么玩笑。
Sure. 当然。
Here's a joke for an aspiring MLM engineer. 这是一个针对一位有抱负的传销工程师的笑话。
Why did the engineer bring a ladder to the data center? 工程师为什么要带梯子到数据中心？
Because they wanted to reach the next level of training. 因为他们想要达到下一个级别的训练。
Boom, boom. 繁荣，繁荣。
Uh, that feels like it's right. 呃，感觉好像是对的。
It would have been funny if it weren't to data center, but something that where you'd have to get to 如果不是数据中心，而是你必须到达的地方，那会很有趣
a next level of training. 下一个级别的培训。
I feel like I feel like that's a miss. 我感觉我感觉那是一种怀念。
That could have been funnier. 那可能会更有趣。
It wasn't bad. 这还不错。
All right, let's try Claude sonnet 4.5. 好吧，让我们试试克劳德十四行诗 4.5。
The one that's just come out for me anyway, this is brand new and I should mention good point for me 无论如何，这是刚刚为我推出的，这是全新的，我应该为我提到优点
to mention. 提一下。
Uh, as as time goes on, I plan to keep this updated and I plan to slip in latest models. 呃，随着时间的推移，我计划不断更新，并计划加入最新型号。
So the code that you see may have different model version numbers in here, which should give you even 因此，您看到的代码可能在这里有不同的模型版本号，这应该给您甚至
more incentive to come in and run it because you might get something better than me. 更有动力进来经营它，因为你可能会得到比我更好的东西。
So I'm calling anthropic, which is of course, just the other, this one right here. 所以我称之为人择，当然，这只是另一个，就是这里的这个。
It's the other, uh, OpenAI that I've created with the anthropic URL and I'm calling it ChatGPT completions 这是我用人类 URL 创建的另一个，呃，OpenAI，我称之为 ChatGPT 补全
dot create. 点创建。
I'm passing in sonnet 4.5, the latest model, and it's a hybrid model, a reasoning and chat. 我传递的是十四行诗 4.5，最新的模型，它是一个混合模型，推理和聊天。
So it's not nearly as fast as GPT four one. 所以它的速度远不如 GPT 4 1 快。
It's obviously thrashing around this joke and it's a long one. 显然它是在绕这个笑话，而且这个笑话很长。
Goodness. 善良。
Junior engineer walks into a bar and asked the bartender, can you help me? 初级工程师走进一家酒吧，问调酒师，你能帮我吗？
I've been trying to reduce my model's hallucinations. 我一直在努力减少模型的幻觉。
The bartender replies, sure, that'll be $47 in API costs. 调酒师回答说，当然，API 成本为 47 美元。
The engineer says, well, wait, I only asked one question. 工程师说，好吧，等等，我只问了一个问题。
The bartender responds, I know, but you set temperature to 1.5 and your system prompt was 3000 tokens 调酒师回应，我知道，但是你将温度设置为 1.5，而你的系统提示是 3000 个代币
of. 的。
You're a helpful bartender assistant who provides detailed, comprehensive responses. 您是一位乐于助人的调酒师助理，可以提供详细、全面的答复。
Uh, okay. 呃，好吧。
Uh, I feel like it's more of a stand up routine. 呃，我觉得这更像是一个站立的例行公事。
It's not bad. 这还不错。
It's quite funny. 这很有趣。
It's quite, quite witty. 真是非常非常机智啊。
Uh, but, uh. 呃，但是，呃。
Yeah, I haven't even explained to you about temperature yet, but I will do. 是的，我什至还没有向你解释温度，但我会的。
Um, but, um, it's, uh. 嗯，但是，嗯，这是，呃。
Yeah, it's it's kind of amusing, and it's obviously very apropos and very relevant, so it's clever, 是的，这有点有趣，而且显然非常恰当并且非常相关，所以它很聪明，
for sure. 一定。
Bonus wisdom. 奖励智慧。
You know, you're becoming an expert when you stop asking, can we fine tune this and start asking, 你知道，当你停止提问时，你就成为了专家，我们可以对此进行微调并开始提问，
should we fine tune this? 我们应该对此进行微调吗？
Wow. 哇。
That is is a pearl of wisdom. 那是一颗智慧的珍珠。
Very good. 非常好。
Claude. 克劳德.
Um, usually the answer is no. 嗯，通常答案是否定的。
Prompt engineering and Rag solves 80% of what people think needs fine tuning. 即时工程和 Rag 解决了人们认为需要微调的 80%。
I couldn't agree more. 我完全同意。
Uh, wow. 呃，哇。
Uh, okay. 呃，好吧。
Very nicely put and slightly controversial. 说得非常好，但略有争议。
I might say context engineering rather than prompt engineering, but otherwise very nicely done by Claude. 我可能会说上下文工程而不是即时工程，但克劳德在其他方面做得非常好。