自学内容网 自学内容网

Introduction to LangChain

1. LangChain

https://www.langchain.com/

LangChain is the platform developers and enterprises choose to build AI apps from prototype to production.

chain /tʃeɪn/:n. 链子,链条,锁链,一系列,一连串 (人或事),约束,连锁商店,连环式 vt. 用锁链拴住 (或束缚、固定)
prototype /ˈprəʊtətaɪp/:n. 原型,雏形,最初形态

LangChain was launched in October 2022 as an open source project by Harrison Chase, while working at machine learning startup Robust Intelligence.
LangChain 由 Harrison Chase 于 2022 年 10 月作为开源软件项目推出,当时他在机器学习初创公司 Robust Intelligence 工作。

2. Introduction

Python Docs
https://python.langchain.com/docs/introduction/

GitHub
https://github.com/langchain-ai

LangChain is a framework for developing applications powered by large language models (LLMs).
LangChain 是一个开源框架,用于构建基于大型语言模型 (large language models, LLMs) 的应用程序。LangChain 提供了一个标准接口,用于将不同的大型语言模型连接在一起,以及与其他工具和数据源的集成。

LLM 是基于大量数据预先训练的大型深度学习模型,可以生成对用户查询的响应。LLM 擅长在常规上下文下对提示做出响应,但在未接受过训练的特定领域却很吃力。提示是人们寻求 LLM 回复时所用的查询,可以根据特定的结构和上下文对生成模型的输入进行细化的实践。

在这里插入图片描述

LangChain simplifies every stage of the LLM application lifecycle:

  • Development: Build your applications using LangChain’s open-source building blocks, components, and third-party integrations. Use LangGraph to build stateful agents with first-class streaming and human-in-the-loop support.
  • Productionization: Use LangSmith to inspect, monitor and evaluate your chains, so that you can continuously optimize and deploy with confidence. (使用 LangSmith 检查、监控和评估你的 chains,以便你可以持续优化和自信地部署。)
  • Deployment: Turn your LangGraph applications into production-ready APIs and Assistants with LangGraph Cloud.

借助 LangChain,可以重新将 LLM 用于特定领域的应用程序,而无需重新训练或微调。开发团队可以构建引用专有信息的复杂应用程序,以增强模型响应。例如,您可以使用 LangChain 来构建应用程序,从存储的内部文档中读取数据并将其汇总为对话式响应。您可以创建检索增强生成 (RAG) 工作流程,在提示时向语言模型引入新信息。实施 RAG 等上下文感知工作流程可减少模型幻觉并提高响应精度。

在这里插入图片描述

3. Documentation

Python Docs
https://python.langchain.com/docs/introduction/

LangChain 中文网
https://www.langchain.asia/

4. Quick Install

With pip:

pip install langchain

With conda:

conda install langchain -c conda-forge

安装 LangChain:

(base) yongqiang@yongqiang:~/langchain_work$ pip install langchain
Collecting langchain
  Downloading langchain-0.3.7-py3-none-any.whl (1.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 1.3 MB/s eta 0:00:00
Requirement already satisfied: PyYAML>=5.3 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from langchain) (6.0.1)
Collecting SQLAlchemy<3,>=1.4 (from langchain)
  Downloading SQLAlchemy-2.0.36-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 1.3 MB/s eta 0:00:00
Collecting aiohttp<4.0.0,>=3.8.3 (from langchain)/3.2 MB 1.4 MB/s eta 0:00:01
  Downloading aiohttp-3.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 1.1 MB/s eta 0:00:00
Collecting langchain-core<0.4.0,>=0.3.15 (from langchain)
  Downloading langchain_core-0.3.18-py3-none-any.whl (409 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 409.3/409.3 kB 691.6 kB/s eta 0:00:00
Collecting langchain-text-splitters<0.4.0,>=0.3.0 (from langchain)
  Downloading langchain_text_splitters-0.3.2-py3-none-any.whl (25 kB)
Collecting langsmith<0.2.0,>=0.1.17 (from langchain)
  Downloading langsmith-0.1.143-py3-none-any.whl (306 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 307.0/307.0 kB 497.4 kB/s eta 0:00:00
Requirement already satisfied: numpy<2,>=1 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from langchain) (1.24.3)
Collecting pydantic<3.0.0,>=2.7.4 (from langchain)
  Downloading pydantic-2.9.2-py3-none-any.whl (434 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 434.9/434.9 kB 380.7 kB/s eta 0:00:00
Requirement already satisfied: requests<3,>=2 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from langchain) (2.31.0)
Collecting tenacity!=8.4.0,<10,>=8.1.0 (from langchain)
  Downloading tenacity-9.0.0-py3-none-any.whl (28 kB)
Collecting aiohappyeyeballs>=2.3.0 (from aiohttp<4.0.0,>=3.8.3->langchain)
  Downloading aiohappyeyeballs-2.4.3-py3-none-any.whl (14 kB)
Collecting aiosignal>=1.1.2 (from aiohttp<4.0.0,>=3.8.3->langchain)
  Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)
Requirement already satisfied: attrs>=17.3.0 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (23.1.0)
Collecting frozenlist>=1.1.1 (from aiohttp<4.0.0,>=3.8.3->langchain)
  Downloading frozenlist-1.5.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (274 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 274.9/274.9 kB 323.9 kB/s eta 0:00:00
Collecting multidict<7.0,>=4.5 (from aiohttp<4.0.0,>=3.8.3->langchain)
  Downloading multidict-6.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (129 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 129.0/129.0 kB 255.3 kB/s eta 0:00:00
Collecting propcache>=0.2.0 (from aiohttp<4.0.0,>=3.8.3->langchain)
  Downloading propcache-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (236 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 236.0/236.0 kB 327.2 kB/s eta 0:00:00
Collecting yarl<2.0,>=1.17.0 (from aiohttp<4.0.0,>=3.8.3->langchain)
  Downloading yarl-1.17.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (343 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 343.4/343.4 kB 333.9 kB/s eta 0:00:00
Collecting jsonpatch<2.0,>=1.33 (from langchain-core<0.4.0,>=0.3.15->langchain)
  Downloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB)
Collecting packaging<25,>=23.2 (from langchain-core<0.4.0,>=0.3.15->langchain)
  Downloading packaging-24.2-py3-none-any.whl (65 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.5/65.5 kB 410.2 kB/s eta 0:00:00
Collecting typing-extensions>=4.7 (from langchain-core<0.4.0,>=0.3.15->langchain)
  Downloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Collecting httpx<1,>=0.23.0 (from langsmith<0.2.0,>=0.1.17->langchain)
  Downloading httpx-0.27.2-py3-none-any.whl (76 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.4/76.4 kB 398.9 kB/s eta 0:00:00
Collecting orjson<4.0.0,>=3.9.14 (from langsmith<0.2.0,>=0.1.17->langchain)
  Downloading orjson-3.10.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 142.5/142.5 kB 443.3 kB/s eta 0:00:00
Collecting requests-toolbelt<2.0.0,>=1.0.0 (from langsmith<0.2.0,>=0.1.17->langchain)
  Downloading requests_toolbelt-1.0.0-py2.py3-none-any.whl (54 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.5/54.5 kB 366.3 kB/s eta 0:00:00
Collecting annotated-types>=0.6.0 (from pydantic<3.0.0,>=2.7.4->langchain)
  Downloading annotated_types-0.7.0-py3-none-any.whl (13 kB)
Collecting pydantic-core==2.23.4 (from pydantic<3.0.0,>=2.7.4->langchain)
  Downloading pydantic_core-2.23.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 393.7 kB/s eta 0:00:00
Requirement already satisfied: charset-normalizer<4,>=2 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from requests<3,>=2->langchain) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from requests<3,>=2->langchain) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from requests<3,>=2->langchain) (2.1.0)
Requirement already satisfied: certifi>=2017.4.17 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from requests<3,>=2->langchain) (2024.2.2)
Collecting greenlet!=0.4.17 (from SQLAlchemy<3,>=1.4->langchain)
  Downloading greenlet-3.1.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (602 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 602.4/602.4 kB 393.0 kB/s eta 0:00:00
Collecting anyio (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain)
  Downloading anyio-4.6.2.post1-py3-none-any.whl (90 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 90.4/90.4 kB 245.7 kB/s eta 0:00:00
Collecting httpcore==1.* (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain)
  Downloading httpcore-1.0.6-py3-none-any.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.0/78.0 kB 297.6 kB/s eta 0:00:00
Collecting sniffio (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain)
  Downloading sniffio-1.3.1-py3-none-any.whl (10 kB)
Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain)
  Downloading h11-0.14.0-py3-none-any.whl (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 kB 271.6 kB/s eta 0:00:00
Requirement already satisfied: jsonpointer>=1.9 in /home/yongqiang/miniconda3/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.4.0,>=0.3.15->langchain) (2.1)
Installing collected packages: typing-extensions, tenacity, sniffio, propcache, packaging, orjson, multidict, jsonpatch, h11, greenlet, frozenlist, annotated-types, aiohappyeyeballs, yarl, SQLAlchemy, requests-toolbelt, pydantic-core, httpcore, anyio, aiosignal, pydantic, httpx, aiohttp, langsmith, langchain-core, langchain-text-splitters, langchain
  Attempting uninstall: packaging
    Found existing installation: packaging 23.1
    Uninstalling packaging-23.1:
      Successfully uninstalled packaging-23.1
  Attempting uninstall: jsonpatch
    Found existing installation: jsonpatch 1.32
    Uninstalling jsonpatch-1.32:
      Successfully uninstalled jsonpatch-1.32
Successfully installed SQLAlchemy-2.0.36 aiohappyeyeballs-2.4.3 aiohttp-3.11.0 aiosignal-1.3.1 annotated-types-0.7.0 anyio-4.6.2.post1 frozenlist-1.5.0 greenlet-3.1.1 h11-0.14.0 httpcore-1.0.6 httpx-0.27.2 jsonpatch-1.33 langchain-0.3.7 langchain-core-0.3.18 langchain-text-splitters-0.3.2 langsmith-0.1.143 multidict-6.1.0 orjson-3.10.11 packaging-24.2 propcache-0.2.0 pydantic-2.9.2 pydantic-core-2.23.4 requests-toolbelt-1.0.0 sniffio-1.3.1 tenacity-9.0.0 typing-extensions-4.12.2 yarl-1.17.1
(base) yongqiang@yongqiang:~/langchain_work$

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/


原文地址:https://blog.csdn.net/chengyq116/article/details/143779677

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!