LangChain v0.3
上次更新:07.08.25
¥Last updated: 07.08.25
有哪些变化
¥What's changed
所有 LangChain 软件包现在都将
@langchain/core
作为对等依赖,而不是直接依赖,以帮助避免 核心版本冲突 周围的类型错误。¥All LangChain packages now have
@langchain/core
as a peer dependency instead of a direct dependency to help avoid type errors around core version conflicts.现在你需要明确安装
@langchain/core
,而不是依赖其他软件包的内部解析版本。¥You will now need to explicitly install
@langchain/core
rather than relying on an internally resolved version from other packages.
回调现在默认在后台运行且非阻塞,而不是阻塞。
¥Callbacks are now backgrounded and non-blocking by default rather than blocking.
这意味着如果你在无服务器环境中使用 LangSmith 等进行跟踪,则需要 await 回调函数以确保它们在函数结束前完成。
¥This means that if you are using e.g. LangSmith for tracing in a serverless environment, you will need to await the callbacks to ensure they finish before your function ends.
从
langchain
中移除了已弃用的文档加载器和自查询入口点,转而使用@langchain/community
和集成包中的入口点。¥Removed deprecated document loader and self-query entrypoints from
langchain
in favor of entrypoints in@langchain/community
and integration packages.从社区中移除了已弃用的 Google PaLM 入口点,转而使用
@langchain/google-vertexai
和@langchain/google-genai
中的入口点。¥Removed deprecated Google PaLM entrypoints from community in favor of entrypoints in
@langchain/google-vertexai
and@langchain/google-genai
.不推荐使用
"type"
对象作为BaseMessageLike
对象,而是使用更类似于 OpenAI 的MessageWithRole
对象。¥Deprecated using objects with a
"type"
as aBaseMessageLike
in favor of the more OpenAI-likeMessageWithRole
有哪些新功能
¥What’s new
在 0.2.x 开发过程中添加了以下功能:
¥The following features have been added during the development of 0.2.x:
简化的工具定义和使用。阅读更多 此处。
¥Simplified tool definition and usage. Read more here.
已添加 通用聊天模型构造器。
¥Added a generalized chat model constructor.
为 调度自定义事件 添加了此功能。
¥Added the ability to dispatch custom events.
发布了 LangGraph.js 0.2.0 版本,并将其与 LangChain.js 一起作为 创建代理的推荐方法 版本。
¥Released LangGraph.js 0.2.0 and made it the recommended way to create agents with LangChain.js.
改进了集成文档和 API 参考。阅读更多 此处。
¥Revamped integration docs and API reference. Read more here.
如何更新代码
¥How to update your code
如果你使用的是 langchain
/ @langchain/community
/ @langchain/core
0.0 或 0.1,我们建议你先升级到 升级到 0.2 版本。
¥If you're using langchain
/ @langchain/community
/ @langchain/core
0.0 or 0.1, we recommend that you first upgrade to 0.2.
如果你使用的是 @langchain/langgraph
,请升级到 @langchain/langgraph>=0.2.3
。这将适用于所有基础软件包的 0.2 或 0.3 版本。
¥If you're using @langchain/langgraph
, upgrade to @langchain/langgraph>=0.2.3
. This will work with either 0.2 or 0.3 versions of all the base packages.
以下是已发布的所有软件包的完整列表,以及我们建议你在 package.json
中升级到的版本约束。任何现在支持 @langchain/core
0.3 的软件包都进行了小版本升级。
¥Here is a complete list of all packages that have been released and what we recommend upgrading your version constraints to in your package.json
.
Any package that now supports @langchain/core
0.3 had a minor version bump.
基础包
¥Base packages
Package | Latest | Recommended package.json constraint |
---|---|---|
langchain | 0.3.29 | >=0.3.58 <0.4.0 |
@langchain/community | 0.3.48 | >=0.3.58 <0.4.0 |
@langchain/textsplitters | 0.1.0 | >=0.2.21 <0.4.0 |
@langchain/core | 0.3.62 | >=0.3.0 <0.4.0 |
下游软件包
¥Downstream packages
Package | Latest | Recommended package.json constraint |
---|---|---|
@langchain/langgraph | 0.3.7 | >=0.3.58 <0.4.0 |
集成包
¥Integration packages
Package | Latest | Recommended package.json constraint |
---|---|---|
@langchain/anthropic | 0.3.24 | >=0.3.58 <0.4.0 |
@langchain/aws | 0.1.11 | >=0.3.58 <0.4.0 |
@langchain/azure-cosmosdb | 0.2.8 | >=0.2.21 <0.4.0 |
@langchain/azure-dynamic-sessions | 0.2.0 | >=0.2.21 <0.4.0 |
@langchain/baidu-qianfan | 0.1.0 | >=0.1.0 <0.4.0 |
@langchain/cloudflare | 0.1.0 | >=0.1.0 <0.4.0 |
@langchain/cohere | 0.3.4 | >=0.3.58 <0.4.0 |
@langchain/exa | 0.1.0 | >=0.1.0 <0.4.0 |
@langchain/google-genai | 0.2.14 | >=0.3.58 <0.4.0 |
@langchain/google-vertexai | 0.2.14 | >=0.3.58 <0.4.0 |
@langchain/google-vertexai-web | 0.2.14 | >=0.3.58 <0.4.0 |
@langchain/groq | 0.2.3 | >=0.3.58 <0.4.0 |
@langchain/mistralai | 0.2.1 | >=0.3.58 <0.4.0 |
@langchain/mixedbread-ai | 0.2.0 | >=0.2.21 <0.4.0 |
@langchain/mongodb | 0.1.0 | >=0.1.0 <0.4.0 |
@langchain/nomic | 0.1.0 | >=0.3.0 <0.4.0 |
@langchain/ollama | 0.2.3 | >=0.3.58 <0.4.0 |
@langchain/openai | 0.5.18 | >=0.3.58 <0.4.0 |
@langchain/pinecone | 0.2.0 | >=0.2.21 <0.4.0 |
@langchain/qdrant | 0.1.2 | >=0.2.21 <0.4.0 |
@langchain/redis | 0.1.1 | >=0.2.21 <0.4.0 |
@langchain/weaviate | 0.2.1 | >=0.2.21 <0.4.0 |
@langchain/yandex | 0.1.0 | >=0.2.21 <0.4.0 |
更新到软件包的最新版本后,如果尚未安装 @langchain/core
,则需要显式安装:
¥Once you've updated to recent versions of the packages, you will need to explicitly install @langchain/core
if you haven't already:
- npm
- Yarn
- pnpm
npm install @langchain/core
yarn add @langchain/core
pnpm add @langchain/core
我们还建议你检查锁定文件或运行 合适的包管理器命令,以确保你的软件包管理器仅安装了一个版本的 @langchain/core
。
¥We also suggest checking your lockfile or running the appropriate package manager command to make sure that your package manager only has one version of @langchain/core
installed.
如果你当前在无服务器环境中运行代码(例如,Cloudflare Worker、Edge 函数或 AWS Lambda 函数),并且正在使用 LangSmith 追踪或其他回调,则需要 await 回调函数以确保它们在函数结束前完成。以下是一个简单的示例:
¥If you are currently running your code in a serverless environment (e.g., a Cloudflare Worker, Edge function, or AWS Lambda function) and you are using LangSmith tracing or other callbacks, you will need to await callbacks to ensure they finish before your function ends. Here's a quick example:
import { RunnableLambda } from "@langchain/core/runnables";
import { awaitAllCallbacks } from "@langchain/core/callbacks/promises";
const runnable = RunnableLambda.from(() => "hello!");
const customHandler = {
handleChainEnd: async () => {
await new Promise((resolve) => setTimeout(resolve, 2000));
console.log("Call finished");
},
};
const startTime = new Date().getTime();
await runnable.invoke({ number: "2" }, { callbacks: [customHandler] });
console.log(`Elapsed time: ${new Date().getTime() - startTime}ms`);
await awaitAllCallbacks();
console.log(`Final elapsed time: ${new Date().getTime() - startTime}ms`);
Elapsed time: 1ms
Call finished
Final elapsed time: 2164ms
你还可以将 LANGCHAIN_CALLBACKS_BACKGROUND
设置为 "false"
,以使所有回调阻塞:
¥You can also set LANGCHAIN_CALLBACKS_BACKGROUND
to "false"
to make all callbacks blocking:
process.env.LANGCHAIN_CALLBACKS_BACKGROUND = "false";
const startTimeBlocking = new Date().getTime();
await runnable.invoke({ number: "2" }, { callbacks: [customHandler] });
console.log(
`Initial elapsed time: ${new Date().getTime() - startTimeBlocking}ms`
);
Call finished
Initial elapsed time: 2002ms