diff --git a/_config.yml b/_config.yml index 8cb9758..058258a 100644 --- a/_config.yml +++ b/_config.yml @@ -21,7 +21,7 @@ bibtex_bibfiles: # Information about where the book exists on the web repository: - url: https://github.com/executablebooks/jupyter-book # Online location of your book + url: https://github.com/daliuchen/langchain-guide # Online location of your book path_to_book: docs # Optional path to your book, relative to the repository root branch: master # Which branch of the repository should be used when creating links (optional) diff --git a/_toc.yml b/_toc.yml index b9df9c2..5ec724a 100644 --- a/_toc.yml +++ b/_toc.yml @@ -5,3 +5,5 @@ format: jb-book root: intro chapters: - file: content/section_1 +- file: content/section_2 + diff --git a/content/section_1.ipynb b/content/section_1.ipynb index d481791..dc641af 100644 --- a/content/section_1.ipynb +++ b/content/section_1.ipynb @@ -531,9 +531,48 @@ "source": [ "# lang smith\n", "\n", - "todo" + "官网:\n", + "https://docs.smith.langchain.com/\n", + "lang Smith来监控上面的chain。在使用之前需要安装,配置api_key(api_key 在lang smith官网中配置就行)" ], "id": "50c9ba7bd9442ceb" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "```shell\n", + "export LANGCHAIN_TRACING_V2=true\n", + "export LANGCHAIN_API_KEY=\n", + "```" + ], + "id": "28654da3c9b1db40" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "配置之后,再次运行上面的结果,可以很清晰的看到chain的运行过程,可以如下
\n", + "![](../resource/img_4.png)" + ], + "id": "1edea1d3d552f06f" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "到此,happy path已经完成了,回顾一下,在这个例子中,了解到\n", + "\n", + "- LangChain Expression Language(LangChain的表达式)\n", + "- Prompt Template\n", + "- Chat Models\n", + "- Output Parsers\n", + "- Lang Server\n", + "- Lang Smith\n", + "\n", + "在之后的学习中,我会按照上面的顺序来学习分享,此外还会增加一些例子。💪🏻" + ], + "id": "b993119b73f2cfea" } ], "metadata": { diff --git a/content/section_2.ipynb b/content/section_2.ipynb new file mode 100644 index 0000000..90a2baa --- /dev/null +++ b/content/section_2.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "# LangChain Expression Language\n", + "\n", + "LangChain表达语言,简写为LCEL,是一种声明式的方式来链接LangChain组件。\n", + "\n", + "## 优点\n", + "- 一流的流媒体支持 \n", + " 当您使用LCEL构建链时,您将获得最佳的首次令牌时间(直到第一个输出块出现所经过的时间)。对于某些链,这意味着例如我们直接从LLM向流媒体输出解析器传输令牌,并且您以与LLM提供商输出原始令牌相同的速度返回解析后的增量输出块。\n", + "- 异步支持 \n", + " 任何使用LCEL构建的链都可以通过同步API(例如,在原型设计时在你的Jupyter笔记本中)以及异步API(例如,在LangServe服务器中)进行调用。这使得在原型和生产环境中使用相同的代码成为可能,具有出色的性能,并能够在同一服务器上处理许多并发请求。\n", + "- 优化的并行执行 \n", + " 每当您的LCEL链中有可以并行执行的步骤(例如,如果您从多个检索器获取文档),我们会在同步和异步接口中自动进行,以实现尽可能小的延迟。\n", + "- 重试和回退 \n", + " 为您的LCEL链的任何部分配置重试和回退。这是使您的链在大规模下更可靠的好方法。我们目前正在努力添加对重试/回退的流媒体支持,这样您就可以在不增加延迟成本的情况下获得额外的可靠性。\n", + "- 访问中间结果 \n", + " 对于更复杂的链条,通常在最终输出生成之前访问中间步骤的结果非常有用。这可以用于让终端用户知道某些事情正在发生,甚至只是调试你的链条。你可以流式传输中间结果,这在每个LangServe服务器上都可用。\n", + "- 输入和输出模式 \n", + " 输入和输出模式为每个 LCEL 链提供从链的结构推断出的 Pydantic 和 JSONSchema 模式。这可以用于验证输入和输出,是 LangServe 的一个重要组成部分。\n", + "- 无缝LangSmith追踪 \n", + " 随着链条变得越来越复杂,了解每一步到底发生了什么变得越来越重要。使用LCEL,所有步骤都会自动记录到LangSmith,以实现最大的可观察性和调试能力。\n", + "- 无缝LangServe部署 \n", + " 使用LCEL创建的任何链都可以轻松通过LangServe进行部署。\n", + "\n", + "## Runnable接口\n", + " 为了尽可能简化创建自定义链条的过程,我们实现了一个“Runnable”协议。许多LangChain组件都实现了Runnable协议,包括聊天模型、LLM、输出解析器、检索器、提示模板等。此外,还有一些有用的基本构件可以用于处理可运行事务,您可以在下面阅读相关信息。\n", + "这是一个标准接口,使得定义自定义链以及以标准方式调用它们变得容易。标准接口包括:\n" + ], + "id": "23a6f647250a9ab" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "todo 解析runnable接口的实现原理", + "id": "98493c2c4b73324e" + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/requirements.txt b/requirements.txt index fa69591..0cdade6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ matplotlib numpy langchain langchain-openai -langserve[all] \ No newline at end of file +langserve[all] +langsmith \ No newline at end of file diff --git a/resource/img_4.png b/resource/img_4.png new file mode 100644 index 0000000..566fa9a Binary files /dev/null and b/resource/img_4.png differ