diff --git a/content/LangChain for LLM Application Development/1.简介 Introduction.md b/content/LangChain for LLM Application Development/1.简介 Introduction.md new file mode 100644 index 0000000..fe143a4 --- /dev/null +++ b/content/LangChain for LLM Application Development/1.简介 Introduction.md @@ -0,0 +1,32 @@ +# 第一章 简介 + +欢迎来到LangChain大模型应用开发短期课程👏🏻👏🏻 + +本课程由哈里森·蔡斯 (Harrison Chase,LangChain作者)与Deeplearning.ai合作开发,旨在教大家使用这个神奇工具。 + + +## 一、LangChain的诞生和发展 + +通过对LLM或大型语言模型给出提示(prompt),现在可以比以往更快地开发AI应用程序,但是一个应用程序可能需要进行多轮提示以及解析输出。 + +在此过程有很多胶水代码需要编写,基于此需求,哈里森·蔡斯 (Harrison Chase) 创建了LangChain,使开发过程变得更加丝滑。 + +LangChain开源社区快速发展,贡献者已达数百人,正以惊人的速度更新代码和功能。 + + +## 二、课程基本内容 + +LangChain是用于构建大模型应用程序的开源框架,有Python和JavaScript两个不同版本的包。LangChain基于模块化组合,有许多单独的组件,可以一起使用或单独使用。此外LangChain还拥有很多应用案例,帮助我们了解如何将这些模块化组件以链式方式组合,以形成更多端到端的应用程序 。 + +在本课程中,我们将介绍LandChain的常见组件。具体而言我们会讨论一下几个方面 +- 模型(Models) +- 提示(Prompts): 使模型执行操作的方式 +- 索引(Indexes): 获取数据的方式,可以与模型结合使用 +- 链式(Chains): 端到端功能实现 +- 代理(Agents): 使用模型作为推理引擎 + + + +## 三、致谢课程重要贡献者 + +最后特别感谢Ankush Gholar(LandChain的联合作者)、Geoff Ladwig,、Eddy Shyu 以及 Diala Ezzedine,他们也为本课程内容贡献颇多~ \ No newline at end of file diff --git a/content/LangChain for LLM Application Development/1.简介.ipynb b/content/LangChain for LLM Application Development/1.简介.ipynb deleted file mode 100644 index 62cee6b..0000000 --- a/content/LangChain for LLM Application Development/1.简介.ipynb +++ /dev/null @@ -1,87 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "cfab521b-77fa-41be-a964-1f50f2ef4689", - "metadata": {}, - "source": [ - "# 1. 简介\n", - "
\n", - "\n", - "欢迎来到LangChain大模型应用开发短期课程👏🏻👏🏻\n", - "\n", - "本课程由哈里森·蔡斯 (Harrison Chase,LangChain作者)与Deeplearning.ai合作开发,旨在教大家使用这个神奇工具。\n", - "\n", - "\n", - "\n", - "## 1.1 LangChain的诞生和发展\n", - "\n", - "通过对LLM或大型语言模型给出提示(prompt),现在可以比以往更快地开发AI应用程序,但是一个应用程序可能需要进行多轮提示以及解析输出。\n", - "\n", - "在此过程有很多胶水代码需要编写,基于此需求,哈里森·蔡斯 (Harrison Chase) 创建了LangChain,使开发过程变得更加丝滑。\n", - "\n", - "LangChain开源社区快速发展,贡献者已达数百人,正以惊人的速度更新代码和功能。\n", - "\n", - "\n", - "## 1.2 课程基本内容\n", - "\n", - "LangChain是用于构建大模型应用程序的开源框架,有Python和JavaScript两个不同版本的包。LangChain基于模块化组合,有许多单独的组件,可以一起使用或单独使用。此外LangChain还拥有很多应用案例,帮助我们了解如何将这些模块化组件以链式方式组合,以形成更多端到端的应用程序 。\n", - "\n", - "在本课程中,我们将介绍LandChain的常见组件。具体而言我们会讨论一下几个方面\n", - "- 模型(Models)\n", - "- 提示(Prompts): 使模型执行操作的方式\n", - "- 索引(Indexes): 获取数据的方式,可以与模型结合使用\n", - "- 链式(Chains): 端到端功能实现\n", - "- 代理(Agents): 使用模型作为推理引擎\n", - "\n", - " \n", - "\n", - "## 1.3 致谢课程重要贡献者\n", - "\n", - "最后特别感谢Ankush Gholar(LandChain的联合作者)、Geoff Ladwig,、Eddy Shyu 以及 Diala Ezzedine,他们也为本课程内容贡献颇多~ " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e3618ca8", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.12" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": false, - "sideBar": true, - "skip_h1_title": false, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": true - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/content/LangChain for LLM Application Development/2.模型、提示和解析器.ipynb b/content/LangChain for LLM Application Development/2.模型、提示和解析器 Models, Prompts and Output Parsers.ipynb similarity index 98% rename from content/LangChain for LLM Application Development/2.模型、提示和解析器.ipynb rename to content/LangChain for LLM Application Development/2.模型、提示和解析器 Models, Prompts and Output Parsers.ipynb index ee92c3e..eb47fd2 100644 --- a/content/LangChain for LLM Application Development/2.模型、提示和解析器.ipynb +++ b/content/LangChain for LLM Application Development/2.模型、提示和解析器 Models, Prompts and Output Parsers.ipynb @@ -4,16 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# 模型,提示和输出解释器\n", - "\n", - "\n", - "**目录**\n", - "* 获取你的OpenAI API Key\n", - "* 直接调用OpenAI的API\n", - "* 通过LangChain进行的API调用:\n", - " * 提示(Prompts)\n", - " * [模型(Models)](#model)\n", - " * 输出解析器(Output parsers)\n", + "# 第二章 模型,提示和输出解释器\n", " " ] }, @@ -23,9 +14,9 @@ "tags": [] }, "source": [ - "## 获取你的OpenAI API Key\n", + "## 一、设置OpenAI API Key\n", "\n", - "登陆[OpenAI账户获取你的API Key](https://platform.openai.com/account/api-keys) " + "登陆[OpenAI账户](https://platform.openai.com/account/api-keys) 获取你的API Key" ] }, { @@ -72,10 +63,11 @@ { "cell_type": "markdown", "metadata": { + "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ - "## Chat API:OpenAI\n", + "## 二、Chat API:OpenAI\n", "\n", "我们先从直接调用OpenAI的API开始。\n", "\n", @@ -113,7 +105,7 @@ "tags": [] }, "source": [ - "### 一个简单的例子\n", + "### 2.1 一个简单的例子\n", "\n", "我们来一个简单的例子 - 分别用中英文问问模型\n", "\n", @@ -166,9 +158,11 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "tags": [] + }, "source": [ - "### 复杂一点例子\n", + "### 2.2 复杂一点例子\n", "\n", "上面的简单例子,模型`gpt-3.5-turbo`对我们的关于1+1是什么的提问给出了回答。\n", "\n", @@ -228,6 +222,22 @@ "下一步需要做的是将`customer_email`和`style`结合起来构造我们的提示:`prompt`" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# 非正式用语\n", + "customer_email = \"\"\" \n", + "阿,我很生气,\\\n", + "因为我的搅拌机盖掉了,\\\n", + "把奶昔溅到了厨房的墙上!\\\n", + "更糟糕的是,保修不包括打扫厨房的费用。\\\n", + "我现在需要你的帮助,伙计!\n", + "\"\"\"" + ] + }, { "cell_type": "code", "execution_count": 8, @@ -313,9 +323,11 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "tags": [] + }, "source": [ - "### 中文" + "### 2.3 中文版本提示" ] }, { @@ -325,22 +337,6 @@ "假设我们是电商公司员工,我们的顾客是一名海盗A,他在我们的网站上买了一个榨汁机用来做奶昔,在制作奶昔的过程中,奶昔的盖子飞了出去,弄得厨房墙上到处都是。于是海盗A给我们的客服中心写来以下邮件:`customer_email`" ] }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "# 非正式用语\n", - "customer_email = \"\"\" \n", - "阿,我很生气,\\\n", - "因为我的搅拌机盖掉了,\\\n", - "把奶昔溅到了厨房的墙上!\\\n", - "更糟糕的是,保修不包括打扫厨房的费用。\\\n", - "我现在需要你的帮助,伙计!\n", - "\"\"\"" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -442,7 +438,7 @@ "tags": [] }, "source": [ - "## Chat API:LangChain\n", + "## 三、Chat API:LangChain\n", "\n", "在前面一部分,我们通过封装函数`get_completion`直接调用了OpenAI完成了对方言邮件进行了的翻译,得到用平和尊重的语气、正式的普通话表达的邮件。\n", "\n", @@ -451,19 +447,11 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "^C\n" - ] - } - ], + "outputs": [], "source": [ "# 如果你需要查看安装过程日志,可删除 -q \n", "# --upgrade 让我们可以安装到最新版本的 langchain\n", @@ -476,7 +464,7 @@ "tags": [] }, "source": [ - "### 模型\n", + "### 3.1 模型\n", "\n", "从`langchain.chat_models`导入`OpenAI`的对话模型`ChatOpenAI`。 除去OpenAI以外,`langchain.chat_models`还集成了其他对话模型,更多细节可以查看[Langchain官方文档](https://python.langchain.com/en/latest/modules/models/chat/integrations.html)。" ] @@ -528,7 +516,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 提示模板\n", + "### 3.2 提示模板\n", "\n", "在前面的例子中,我们通过[f字符串](https://docs.python.org/zh-cn/3/tutorial/inputoutput.html#tut-f-strings)把Python表达式的值`style`和`customer_email`添加到`prompt`字符串内。\n", "\n", @@ -546,7 +534,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### 📚 使用LangChain提示模版\n", + "#### 3.2.1 使用LangChain提示模版\n", "##### 1️⃣ 构造提示模版字符串\n", "我们构造一个提示模版字符串:`template_string`" ] @@ -933,7 +921,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -1059,14 +1047,17 @@ "tags": [] }, "source": [ - "#### ❓为什么需要提示模版\n", + "#### 3.2.2 为什么需要提示模版\n", "\n", "\n" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "jp-MarkdownHeadingCollapsed": true, + "tags": [] + }, "source": [ "\n", "在应用于比较复杂的场景时,提示可能会非常长并且包含涉及许多细节。**使用提示模版,可以让我们更为方便地重复使用设计好的提示**。\n", @@ -1118,8 +1109,6 @@ " \"\"\"\n", "```\n", "\n", - "# 中文\n", - "\n", "```python\n", " prompt = \"\"\" 你的任务是判断学生的解决方案是正确的还是不正确的\n", "\n", @@ -1226,14 +1215,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 输出解析器" + "### 3.3 输出解析器" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "#### 📚 如果没有输出解析器\n", + "#### 3.3.1 如果没有输出解析器\n", "\n", "对于给定的评价`customer_review`, 我们希望提取信息,并按以下格式输出:\n", "\n", @@ -1514,7 +1503,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### 📚 LangChain输出解析器" + "#### 3.3.2 LangChain输出解析器" ] }, { @@ -1947,14 +1936,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 补充材料" + "## 四、补充材料" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### 链式思考推理(ReAct) \n", + "### 4.1 链式思考推理(ReAct) \n", "参考资料:[ReAct (Reason+Act) prompting in OpenAI GPT and LangChain](https://tsmatz.wordpress.com/2023/03/07/react-with-openai-gpt-and-langchain/)" ] }, diff --git a/content/LangChain for LLM Application Development/3.存储.ipynb b/content/LangChain for LLM Application Development/3.存储 Memory.ipynb similarity index 96% rename from content/LangChain for LLM Application Development/3.存储.ipynb rename to content/LangChain for LLM Application Development/3.存储 Memory.ipynb index 305bc33..8ae5468 100644 --- a/content/LangChain for LLM Application Development/3.存储.ipynb +++ b/content/LangChain for LLM Application Development/3.存储 Memory.ipynb @@ -5,9 +5,7 @@ "id": "a786c77c", "metadata": {}, "source": [ - "# 3. 储存\n", - "\n", - "\n", + "# 第三章 储存\n", "\n", "当你与那些语言模型进行交互的时候,他们不会记得你之前和他进行的交流内容,这在我们构建一些应用程序(如聊天机器人)的时候,是一个很大的问题---显得不够智能!\n", "\n", @@ -48,22 +46,12 @@ "为了延长LLM短期记忆的保留时间,则需要借助一些外部存储方式来进行记忆,以便在用户与LLM对话中,LLM能够尽可能的知道用户与它所进行的历史对话信息。 " ] }, - { - "cell_type": "markdown", - "id": "1297dcd5", - "metadata": {}, - "source": [ - "## 3.1 对话缓存储存 \n", - " \n", - "这种记忆允许存储消息,然后从变量中提取消息。" - ] - }, { "cell_type": "markdown", "id": "0768ca9b", "metadata": {}, "source": [ - "### 1.首先,让我们导入相关的包和 OpenAI API 秘钥" + "## 一、设置OpenAI API Key" ] }, { @@ -71,7 +59,7 @@ "id": "d76f6ba7", "metadata": {}, "source": [ - "### dotenv模块使用解析: \n", + "dotenv模块使用解析: \n", "- 安装方式:pip install python-dotenv\n", "- load_dotenv()函数用于加载环境变量,\n", "- find_dotenv()函数用于寻找并定位.env文件的路径 \n", @@ -97,6 +85,16 @@ "_ = load_dotenv(find_dotenv()) " ] }, + { + "cell_type": "markdown", + "id": "1297dcd5", + "metadata": {}, + "source": [ + "## 二、对话缓存储存 \n", + " \n", + "这种记忆允许存储消息,然后从变量中提取消息。" + ] + }, { "cell_type": "code", "execution_count": 2, @@ -135,7 +133,7 @@ "id": "dea83837", "metadata": {}, "source": [ - "### 2.开始对话,第一轮" + "### 2.1 开始对话,第一轮" ] }, { @@ -232,7 +230,7 @@ "id": "e71564ad", "metadata": {}, "source": [ - "### 3.第二轮对话" + "### 2.2 第二轮对话" ] }, { @@ -343,7 +341,7 @@ "id": "33cb734b", "metadata": {}, "source": [ - "### 4.第三轮对话" + "### 2.3 第三轮对话" ] }, { @@ -458,7 +456,7 @@ "id": "5a96a8d9", "metadata": {}, "source": [ - "### 5.memory.buffer存储了当前为止所有的对话信息" + "### 2.4 .memory.buffer存储了当前为止所有的对话信息" ] }, { @@ -527,7 +525,7 @@ "id": "6bd222c3", "metadata": {}, "source": [ - "### 6.也可以通过memory.load_memory_variables({})打印历史消息" + "### 2.5 也可以通过memory.load_memory_variables({})打印历史消息" ] }, { @@ -588,7 +586,7 @@ "id": "07d2e892", "metadata": {}, "source": [ - "### 7.添加指定的输入输出内容到记忆缓存区" + "### 2.6 添加指定的输入输出内容到记忆缓存区" ] }, { @@ -768,7 +766,7 @@ "id": "cf98e9ff", "metadata": {}, "source": [ - "## 3.2 对话缓存窗口储存\n", + "## 三、对话缓存窗口储存\n", " \n", "随着对话变得越来越长,所需的内存量也变得非常长。将大量的tokens发送到LLM的成本,也会变得更加昂贵,这也就是为什么API的调用费用,通常是基于它需要处理的tokens数量而收费的。\n", " \n", @@ -793,7 +791,7 @@ "id": "641477a4", "metadata": {}, "source": [ - "### 1.向memory添加两轮对话,并查看记忆变量当前的记录" + "### 3.1 向memory添加两轮对话,并查看记忆变量当前的记录" ] }, { @@ -851,7 +849,7 @@ "id": "9b401f0b", "metadata": {}, "source": [ - "### 2.在看一个例子,发现和上面的结果一样,只保留了一轮对话记忆" + "### 3.2 在看一个例子,发现和上面的结果一样,只保留了一轮对话记忆" ] }, { @@ -886,7 +884,7 @@ "id": "63bda148", "metadata": {}, "source": [ - "### 3.将对话缓存窗口记忆应用到对话链中" + "### 3.3 将对话缓存窗口记忆应用到对话链中" ] }, { @@ -1022,7 +1020,7 @@ "id": "d2931b92", "metadata": {}, "source": [ - "## 3.3 对话token缓存储存" + "## 四、对话token缓存储存" ] }, { @@ -1051,7 +1049,7 @@ "id": "2187cfe6", "metadata": {}, "source": [ - "### 1.导入相关包和API密钥" + "### 4.1 导入相关包和API密钥" ] }, { @@ -1075,7 +1073,7 @@ "id": "f3a84112", "metadata": {}, "source": [ - "### 2.限制token数量,进行测试" + "### 4.2 限制token数量,进行测试" ] }, { @@ -1132,7 +1130,7 @@ "id": "f7f6be43", "metadata": {}, "source": [ - "### 3.在看一个中文例子" + "### 4.3 中文例子" ] }, { @@ -1181,7 +1179,7 @@ "id": "5ff55d5d", "metadata": {}, "source": [ - "## 3.4 对话摘要缓存储存" + "## 四、对话摘要缓存储存" ] }, { @@ -1222,7 +1220,7 @@ "id": "6572ef39", "metadata": {}, "source": [ - "### 创建一个长字符串,其中包含某人的日程安排" + "### 5.1 创建一个长字符串,其中包含某人的日程安排" ] }, { @@ -1279,7 +1277,7 @@ "id": "7ccb97b6", "metadata": {}, "source": [ - "### 基于上面的memory,新建一个对话链" + "### 5.2 基于上面的memory,新建一个对话链" ] }, { @@ -1371,7 +1369,7 @@ "height": 31 }, "source": [ - "### 中文" + "### 5.3 中文例子" ] }, { diff --git a/content/LangChain for LLM Application Development/4.模型链.ipynb b/content/LangChain for LLM Application Development/4.模型链 Chains.ipynb similarity index 96% rename from content/LangChain for LLM Application Development/4.模型链.ipynb rename to content/LangChain for LLM Application Development/4.模型链 Chains.ipynb index 7477286..4418366 100644 --- a/content/LangChain for LLM Application Development/4.模型链.ipynb +++ b/content/LangChain for LLM Application Development/4.模型链 Chains.ipynb @@ -1,32 +1,31 @@ { "cells": [ { - "attachments": {}, "cell_type": "markdown", "id": "52824b89-532a-4e54-87e9-1410813cd39e", "metadata": {}, "source": [ - "# Chains in LangChain(LangChain中的链)\n", - "\n", - "## Outline\n", - "\n", - "* LLMChain(大语言模型链)\n", - "* Sequential Chains(顺序链)\n", - " * SimpleSequentialChain\n", - " * SequentialChain\n", - "* Router Chain(路由链)" + "# 第四章 模型链" ] }, { - "attachments": {}, "cell_type": "markdown", "id": "54810ef7", "metadata": {}, "source": [ - "### 为什么我们需要Chains ?\n", "链允许我们将多个组件组合在一起,以创建一个单一的、连贯的应用程序。链(Chains)通常将一个LLM(大语言模型)与提示结合在一起,使用这个构建块,您还可以将一堆这些构建块组合在一起,对您的文本或其他数据进行一系列操作。例如,我们可以创建一个链,该链接受用户输入,使用提示模板对其进行格式化,然后将格式化的响应传递给LLM。我们可以通过将多个链组合在一起,或者通过将链与其他组件组合在一起来构建更复杂的链。" ] }, + { + "cell_type": "markdown", + "id": "67fbb012-bee5-49a8-9b62-9bad7ee87e94", + "metadata": {}, + "source": [ + "## 一、设置OpenAI API Key\n", + "\n", + "登陆[OpenAI账户获取你的API Key](https://platform.openai.com/account/api-keys) " + ] + }, { "cell_type": "code", "execution_count": 44, @@ -68,7 +67,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "663fc885", "metadata": {}, @@ -167,16 +165,14 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "b940ce7c", "metadata": {}, "source": [ - "## 1. LLMChain" + "## 二、LLMChain" ] }, { - "attachments": {}, "cell_type": "markdown", "id": "e000bd16", "metadata": {}, @@ -197,7 +193,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "94a32c6f", "metadata": {}, @@ -216,7 +211,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "81887434", "metadata": {}, @@ -238,7 +232,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "5c22cb13", "metadata": {}, @@ -257,7 +250,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "8d7d5ff6", "metadata": {}, @@ -288,7 +280,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "1e1ede1c", "metadata": {}, @@ -324,21 +315,19 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "49158430", "metadata": {}, "source": [ - "## 2. Sequential Chains" + "## 三、Sequential Chains" ] }, { - "attachments": {}, "cell_type": "markdown", "id": "69b03469", "metadata": {}, "source": [ - "### 2.1 SimpleSequentialChain\n", + "### 3.1 SimpleSequentialChain\n", "\n", "顺序链(Sequential Chains)是按预定义顺序执行其链接的链。具体来说,我们将使用简单顺序链(SimpleSequentialChain),这是顺序链的最简单类型,其中每个步骤都有一个输入/输出,一个步骤的输出是下一个步骤的输入" ] @@ -364,7 +353,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "0e732589", "metadata": {}, @@ -391,7 +379,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "dcfca7bd", "metadata": {}, @@ -417,7 +404,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "3a1991f4", "metadata": {}, @@ -438,7 +424,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "5122f26a", "metadata": {}, @@ -534,16 +519,14 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "7b5ce18c", "metadata": {}, "source": [ - "### 2.2 SequentialChain" + "### 3.2 SequentialChain" ] }, { - "attachments": {}, "cell_type": "markdown", "id": "1e69f4c0", "metadata": {}, @@ -567,7 +550,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "3d4be4e8", "metadata": {}, @@ -586,7 +568,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "9811445c", "metadata": {}, @@ -693,7 +674,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "0509de01", "metadata": {}, @@ -869,16 +849,14 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "3041ea4c", "metadata": {}, "source": [ - "## 3. Router Chain(路由链)" + "## 四、 Router Chain(路由链)" ] }, { - "attachments": {}, "cell_type": "markdown", "id": "f0c32f97", "metadata": {}, @@ -896,12 +874,11 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "cb1b4708", "metadata": {}, "source": [ - "### 定义提示模板" + "### 4.1 定义提示模板" ] }, { @@ -1017,7 +994,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "6922b35e", "metadata": {}, @@ -1028,6 +1004,7 @@ { "cell_type": "code", "execution_count": 27, + "id": "141a3d32", "metadata": {}, "outputs": [], "source": [ @@ -1088,12 +1065,11 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "80eb1de8", "metadata": {}, "source": [ - "### 导入相关的包" + "### 4.2 导入相关的包" ] }, { @@ -1109,12 +1085,11 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "50c16f01", "metadata": {}, "source": [ - "### 定义语言模型" + "### 4.3 定义语言模型" ] }, { @@ -1128,12 +1103,11 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "8795cd42", "metadata": {}, "source": [ - "### LLMRouterChain(此链使用 LLM 来确定如何路由事物)\n", + "### 4.4 LLMRouterChain(此链使用 LLM 来确定如何路由事物)\n", "\n", "在这里,我们需要一个**多提示链**。这是一种特定类型的链,用于在多个不同的提示模板之间进行路由。\n", "但是,这只是你可以路由的一种类型。你也可以在任何类型的链之间进行路由。\n", @@ -1143,12 +1117,11 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "46633b43", "metadata": {}, "source": [ - "#### 创建目标链 \n", + "#### 4.4.1 创建目标链 \n", "目标链是由路由链调用的链,每个目标链都是一个语言模型链" ] }, @@ -1192,12 +1165,11 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "eba115de", "metadata": {}, "source": [ - "#### 创建默认目标链\n", + "#### 4.4.2 创建默认目标链\n", "除了目标链之外,我们还需要一个默认目标链。这是一个当路由器无法决定使用哪个子链时调用的链。在上面的示例中,当输入问题与物理、数学、历史或计算机科学无关时,可能会调用它。" ] }, @@ -1213,17 +1185,15 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "948700c4", "metadata": {}, "source": [ - "#### 创建LLM用于在不同链之间进行路由的模板\n", + "#### 4.4.3 创建LLM用于在不同链之间进行路由的模板\n", "这包括要完成的任务的说明以及输出应该采用的特定格式。" ] }, { - "attachments": {}, "cell_type": "markdown", "id": "24f30c2c", "metadata": {}, @@ -1348,12 +1318,11 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "de5c46d0", "metadata": {}, "source": [ - "#### 构建路由链\n", + "#### 4.4.4 构建路由链\n", "首先,我们通过格式化上面定义的目标创建完整的路由器模板。这个模板可以适用许多不同类型的目标。\n", "因此,在这里,您可以添加一个不同的学科,如英语或拉丁语,而不仅仅是物理、数学、历史和计算机科学。\n", "\n", @@ -1382,12 +1351,11 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "7e92355c", "metadata": {}, "source": [ - "#### 最后,将所有内容整合在一起,创建整体链路" + "#### 4.4.5 创建整体链路" ] }, { @@ -1406,16 +1374,14 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "086503f7", "metadata": {}, "source": [ - "#### 进行提问" + "#### 4.4.6 进行提问" ] }, { - "attachments": {}, "cell_type": "markdown", "id": "969cd878", "metadata": {}, @@ -1522,7 +1488,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "289c5ca9", "metadata": {}, @@ -1611,7 +1576,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "4186a2b9", "metadata": {}, @@ -1704,7 +1668,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.9.12" } }, "nbformat": 4, diff --git a/content/LangChain for LLM Application Development/5.基于文档的问答.ipynb b/content/LangChain for LLM Application Development/5.基于文档的问答 Question and Answer.ipynb similarity index 95% rename from content/LangChain for LLM Application Development/5.基于文档的问答.ipynb rename to content/LangChain for LLM Application Development/5.基于文档的问答 Question and Answer.ipynb index 811e8df..2ddeced 100644 --- a/content/LangChain for LLM Application Development/5.基于文档的问答.ipynb +++ b/content/LangChain for LLM Application Development/5.基于文档的问答 Question and Answer.ipynb @@ -5,8 +5,7 @@ "id": "f200ba9a", "metadata": {}, "source": [ - "# 5 基于文档的问答 \n", - "" + "# 第五章 基于文档的问答" ] }, { @@ -94,7 +93,7 @@ "height": 30 }, "source": [ - "## 5.1 导入embedding模型和向量存储组件\n", + "## 一、导入embedding模型和向量存储组件\n", "使用Dock Array内存搜索向量存储,作为一个内存向量存储,不需要连接外部数据库" ] }, @@ -289,7 +288,7 @@ "id": "2963fc63", "metadata": {}, "source": [ - "### 5.1.2 创建向量存储\n", + "### 1.1 创建向量存储\n", "将导入一个索引,即向量存储索引创建器" ] }, @@ -396,7 +395,7 @@ "id": "dd34e50e", "metadata": {}, "source": [ - "### 5.1.3 使用语言模型与文档结合使用\n", + "### 1.2 使用语言模型与文档结合使用\n", "想要使用语言模型并将其与我们的许多文档结合使用,但是语言模型一次只能检查几千个单词,如果我们有非常大的文档,如何让语言模型回答关于其中所有内容的问题呢?通过embedding和向量存储实现\n", "* embedding \n", "文本片段创建数值表示文本语义,相似内容的文本片段将具有相似的向量,这使我们可以在向量空间中比较文本片段\n", @@ -607,7 +606,7 @@ "id": "fe41b36f", "metadata": {}, "source": [ - "## 5.2 如何回答我们文档的相关问题\n", + "## 二、 如何回答我们文档的相关问题\n", "首先,我们需要从这个向量存储中创建一个检索器,检索器是一个通用接口,可以由任何接受查询并返回文档的方法支持。接下来,因为我们想要进行文本生成并返回自然语言响应\n" ] }, @@ -798,7 +797,7 @@ "id": "44f1fa38", "metadata": {}, "source": [ - "### 5.2.1 不同类型的chain链\n", + "### 1.3 不同类型的chain链\n", "想在许多不同类型的块上执行相同类型的问答,该怎么办?之前的实验中只返回了4个文档,如果有多个文档,那么我们可以使用几种不同的方法\n", "* Map Reduce \n", "将所有块与问题一起传递给语言模型,获取回复,使用另一个语言模型调用将所有单独的回复总结成最终答案,它可以在任意数量的文档上运行。可以并行处理单个问题,同时也需要更多的调用。它将所有文档视为独立的\n", @@ -809,6 +808,14 @@ "* Stuff \n", "将所有内容组合成一个文档" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41c9d68a-251a-41f1-a571-f6a13b3d7b40", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/content/LangChain for LLM Application Development/6.评估.ipynb b/content/LangChain for LLM Application Development/6.评估 Evaluation.ipynb similarity index 99% rename from content/LangChain for LLM Application Development/6.评估.ipynb rename to content/LangChain for LLM Application Development/6.评估 Evaluation.ipynb index 4601453..8f93fce 100644 --- a/content/LangChain for LLM Application Development/6.评估.ipynb +++ b/content/LangChain for LLM Application Development/6.评估 Evaluation.ipynb @@ -5,7 +5,7 @@ "id": "52824b89-532a-4e54-87e9-1410813cd39e", "metadata": {}, "source": [ - "# 6.评估\n", + "# 第六章 评估\n", "\n", "当使用llm构建复杂应用程序时,评估应用程序的表现是一个重要但有时棘手的步骤,它是否满足某些准确性标准?\n", "通常更有用的是从许多不同的数据点中获得更全面的模型表现情况\n", @@ -1087,7 +1087,6 @@ "source": [] }, { - "attachments": {}, "cell_type": "markdown", "id": "0b6680d2", "metadata": {}, @@ -1367,7 +1366,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "952fc528", "metadata": {}, @@ -1419,7 +1417,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "b5b994b0", "metadata": {}, @@ -1428,7 +1425,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "0214fe01", "metadata": {}, @@ -1456,7 +1452,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "27f3bc68", "metadata": {}, @@ -1475,7 +1470,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "d2117da8", "metadata": {}, @@ -1484,7 +1478,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "9e76a2ae", "metadata": {}, @@ -1539,7 +1532,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "13e72db4", "metadata": {}, @@ -1600,6 +1592,7 @@ { "cell_type": "code", "execution_count": 39, + "id": "82ec0488", "metadata": {}, "outputs": [], "source": [ @@ -1743,7 +1736,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "0f076f4c", "metadata": {}, @@ -1794,7 +1786,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "9737c0cc", "metadata": {}, @@ -1934,7 +1925,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "9f3ebc93", "metadata": {}, @@ -1955,7 +1945,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "dd57860a", "metadata": {}, @@ -2340,7 +2329,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "ece7c7b4", "metadata": {}, diff --git a/content/LangChain for LLM Application Development/7.代理.ipynb b/content/LangChain for LLM Application Development/7.代理 Agent.ipynb similarity index 97% rename from content/LangChain for LLM Application Development/7.代理.ipynb rename to content/LangChain for LLM Application Development/7.代理 Agent.ipynb index d746699..fb955b1 100644 --- a/content/LangChain for LLM Application Development/7.代理.ipynb +++ b/content/LangChain for LLM Application Development/7.代理 Agent.ipynb @@ -1,28 +1,11 @@ { "cells": [ { - "attachments": {}, "cell_type": "markdown", "id": "2caa79ba-45e3-437c-9cb6-e433f443f0bf", "metadata": {}, "source": [ - "# 7. 代理\n", - "\n", - "