Skip to main content
Open on GitHub

弃用和破坏性变更

此代码包含 langchainlangchain-core 包中的弃用项和移除项列表。

新功能和改进未在此列出。有关本次发布新内容的摘要,请参阅概览

破坏性变更

自 0.2.0 版本发布以来,langchain 必须实现与集成无关。这意味着 langchain 中的代码默认不应实例化任何特定的聊天模型、大语言模型(LLM)、嵌入模型、向量存储等;相反,用户将被要求显式指定这些组件。

以下函数和类需要显式传递一个 LLM 作为参数:

  • langchain.agents.agent_toolkits.vectorstore.toolkit.VectorStoreToolkit
  • langchain.agents.agent_toolkits.vectorstore.toolkit.VectorStoreRouterToolkit
  • langchain.chains.openai_functions.get_openapi_chain
  • langchain.chains.router.MultiRetrievalQAChain.from_retrievers
  • langchain.indexes.VectorStoreIndexWrapper.query
  • langchain.indexes.VectorStoreIndexWrapper.query_with_sources
  • langchain.indexes.VectorStoreIndexWrapper.aquery_with_sources
  • langchain.chains.flare.FlareChain

以下类现在需要显式传递 Embedding 模型作为参数:

  • langchain.indexes.VectostoreIndexCreator

以下代码已被移除:

  • langchain.natbot.NatBotChain.from_default 已被 from_llm 类方法取代。

以下代码的行为已更改:

@tool 装饰器

@tool 装饰器现在将函数的文档字符串分配为工具描述。此前,@tool 装饰器用于在函数签名前添加内容。

在 0.2.0 之前:

@tool
def my_tool(x: str) -> str:
"""Some description."""
return "something"

print(my_tool.description)

将产生结果:my_tool: (x: str) -> str - Some description.

截至 0.2.0:

它将导致:Some description.

代码已移至另一个包

代码已从 langchain 移至另一个包(例如 langchain-community

如果您尝试从 langchain 导入,导入操作仍会继续执行,但会引发弃用警告。该警告将提供替换的导入语句。

python -c "from langchain.document_loaders.markdown import UnstructuredMarkdownLoader"
LangChainDeprecationWarning: Importing UnstructuredMarkdownLoader from langchain.document_loaders is deprecated. Please replace deprecated imports:

>> from langchain.document_loaders import UnstructuredMarkdownLoader

with new imports of:

>> from langchain_community.document_loaders import UnstructuredMarkdownLoader

我们将继续支持在 langchain 中的导入,直到发布 0.4 版本,前提是代码所在的相应包已安装。(例如,只要安装了 langchain_community。)

然而,我们建议用户不要依赖这些导入,而是迁移到新的导入。为了帮助这一过程,我们通过 LangChain CLI 发布了一个迁移脚本。请参阅迁移指南中的进一步说明。

代码目标移除

代码存在更好的替代方案,最终将被移除,因此只保留一种操作方式。(例如,ChatModels 中的 predict_messages 方法已被弃用,推荐使用 invoke。)

astream events V1

如果您正在使用 astream_events,请查看如何 迁移到 astream events v2

langchain_core

try_load_from_hub

在模块中:utils.loading 已弃用:0.1.30 移除版本:0.3.0

替代方案:使用 hwchase17/langchain-hub 仓库进行提示词开发已弃用。请使用 https://smith.langchain.com/hub 代替。

BaseLanguageModel.predict

在模块中:language_models.base 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseLanguageModel.predict_messages

在模块中:language_models.base 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseLanguageModel.apredict

在模块中:language_models.base 已弃用:0.1.7 移除版本:0.3.0

替代方案:ainvoke

BaseLanguageModel.apredict_messages

在模块中:language_models.base 已弃用:0.1.7 移除版本:0.3.0

替代方案:ainvoke

运行类型枚举

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:使用字符串。

追踪会话V1基础

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

TracerSessionV1Create

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

追踪会话V1

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

追踪会话基类

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

追踪会话

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

BaseRun

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:运行

LLMRun

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:运行

链运行

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:运行

ToolRun

In module: tracers.schemas Deprecated: 0.1.0 Removal: 0.3.0

替代方案:运行

BaseChatModel.call

在模块中:language_models.chat_models 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseChatModel.call_as_llm

在模块中:language_models.chat_models 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseChatModel.predict

在模块中:language_models.chat_models 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseChatModel.predict_messages

在模块中:language_models.chat_models 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseChatModel.apredict

在模块中:language_models.chat_models 已弃用:0.1.7 移除版本:0.3.0

替代方案:ainvoke

BaseChatModel.apredict_messages

在模块中:language_models.chat_models 已弃用:0.1.7 移除版本:0.3.0

替代方案:ainvoke

BaseLLM.call

在模块中:language_models.llms 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseLLM.predict

在模块中:language_models.llms 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseLLM.predict_messages

在模块中:language_models.llms 已弃用:0.1.7 移除版本:0.3.0

替代方案:invoke

BaseLLM.apredict

在模块中:language_models.llms 已弃用:0.1.7 移除版本:0.3.0

替代方案:ainvoke

BaseLLM.apredict_messages

在模块中:language_models.llms 已弃用:0.1.7 移除版本:0.3.0

替代方案:ainvoke

BaseRetriever.get_relevant_documents

在模块中:retrievers 已弃用:0.1.46 移除版本:0.3.0

替代方案:invoke

BaseRetriever.aget_relevant_documents

在模块中:retrievers 已弃用:0.1.46 移除版本:0.3.0

替代方案:ainvoke

ChatPromptTemplate.from_role_strings

在模块中:prompts.chat 已弃用:0.0.1 移除版本:

替代方案:from_messages 类方法

ChatPromptTemplate.from_strings

在模块中:prompts.chat 已弃用:0.0.1 移除版本:

替代方案:from_messages 类方法

BaseTool.call

在模块中:tools 已弃用:0.1.47 移除:0.3.0

替代方案:invoke

convert_pydantic_to_openai_function

In module: utils.function_calling 已弃用:0.1.16 移除版本:0.3.0

替代方案:langchain_core.utils.function_calling.convert_to_openai_function()

convert_pydantic_to_openai_tool

In module: utils.function_calling 已弃用:0.1.16 移除版本:0.3.0

替代方案:langchain_core.utils.function_calling.convert_to_openai_tool()

convert_python_function_to_openai_function

In module: utils.function_calling 已弃用:0.1.16 移除版本:0.3.0

替代方案:langchain_core.utils.function_calling.convert_to_openai_function()

format_tool_to_openai_function

In module: utils.function_calling 已弃用:0.1.16 移除版本:0.3.0

替代方案:langchain_core.utils.function_calling.convert_to_openai_function()

format_tool_to_openai_tool

In module: utils.function_calling 已弃用:0.1.16 移除版本:0.3.0

替代方案:langchain_core.utils.function_calling.convert_to_openai_tool()

langchain

AgentType

In module: agents.agent_types Deprecated: 0.1.0 Removal: 0.3.0

替代方案:使用 LangGraph 或新的代理构造函数方法,如 create_react_agent、create_json_agent、create_structured_chat_agent 等。

Chain.call

In module: chains.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:invoke

Chain.acall

In module: chains.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:ainvoke

Chain.run

In module: chains.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:invoke

Chain.arun

In module: chains.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:ainvoke

Chain.apply

In module: chains.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:批处理

LLMChain

In module: chains.llm Deprecated: 0.1.17 Removal: 0.3.0

替代方案:RunnableSequence,例如:prompt | llm

这份 迁移指南 提供了并排对比。

LLM单一操作代理

In module: agents.agent Deprecated: 0.1.0 Removal: 0.3.0

替代方案:使用 LangGraph 或新的代理构造函数方法,如 create_react_agent、create_json_agent、create_structured_chat_agent 等。

智能体

In module: agents.agent Deprecated: 0.1.0 Removal: 0.3.0

替代方案:使用 LangGraph 或新的代理构造函数方法,如 create_react_agent、create_json_agent、create_structured_chat_agent 等。

OpenAIFunctionsAgent

In module: agents.openai_functions_agent.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:create_openai_functions_agent

ZeroShotAgent

In module: agents.mrkl.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:create_react_agent

MRKLChain

In module: agents.mrkl.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

对话式智能体

In module: agents.conversational.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:create_react_agent

对话式聊天代理

In module: agents.conversational_chat.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:创建_json_聊天代理

ChatAgent

In module: agents.chat.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:create_react_agent

OpenAIMultiFunctionsAgent

In module: agents.openai_functions_multi_agent.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:create_openai_tools_agent

ReActDocstoreAgent

In module: agents.react.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

DocstoreExplorer

In module: agents.react.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

ReActTextWorldAgent

In module: agents.react.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

ReActChain

In module: agents.react.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

SelfAskWithSearchAgent

In module: agents.self_ask_with_search.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:create_self_ask_with_search

SelfAskWithSearchChain

In module: agents.self_ask_with_search.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

StructuredChatAgent

In module: agents.structured_chat.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:create_structured_chat_agent

检索问答

In module: chains.retrieval_qa.base Deprecated: 0.1.17 Removal: 0.3.0

替代方案:create_retrieval_chain迁移指南提供了并排对比。

load_agent_from_config

In module: agents.loading Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

load_agent

In module: agents.loading Deprecated: 0.1.0 Removal: 0.3.0

替代方案:

initialize_agent

In module: agents.initialize Deprecated: 0.1.0 Removal: 0.3.0

替代方案:使用 LangGraph 或新的代理构造函数方法,如 create_react_agent、create_json_agent、create_structured_chat_agent 等。

XMLAgent

In module: agents.xml.base Deprecated: 0.1.0 Removal: 0.3.0

替代方案:create_xml_agent

CohereRerank

在模块中:retrievers.document_compressors.cohere_rerank 已弃用:0.0.30 移除:0.3.0

替代方案:langchain_cohere.CohereRerank

对话检索链

In module: chains.conversational_retrieval.base Deprecated: 0.1.17 Removal: 0.3.0

替代方案:create_history_aware_retrievercreate_retrieval_chain 结合使用(文档字符串中的示例)。 本迁移指南提供了并排对比。

create_extraction_chain_pydantic

In module: chains.openai_tools.extraction Deprecated: 0.1.14 Removal: 0.3.0

替代方案:在支持工具调用的聊天模型上使用 with_structured_output 方法。

create_openai_fn_runnable

In module: chains.structured_output.base Deprecated: 0.1.14 Removal: 0.3.0

替代方案:在支持工具调用的聊天模型上使用 with_structured_output 方法。

create_structured_output_runnable

In module: chains.structured_output.base Deprecated: 0.1.17 Removal: 0.3.0

替代方案:在支持工具调用的聊天模型上使用 with_structured_output 方法。

create_openai_fn_chain

在模块中:chains.openai_functions.base 已弃用:0.1.1 移除:0.3.0

替代方案:create_openai_fn_runnable

create_structured_output_chain

在模块中:chains.openai_functions.base 已弃用:0.1.1 移除:0.3.0

替代方案:ChatOpenAI.with_structured_output

create_extraction_chain

In module: chains.openai_functions.extraction Deprecated: 0.1.14 Removal: 0.3.0

替代方案:在支持工具调用的聊天模型上使用 with_structured_output 方法。

create_extraction_chain_pydantic

In module: chains.openai_functions.extraction Deprecated: 0.1.14 Removal: 0.3.0

替代方案:在支持工具调用的聊天模型上使用 with_structured_output 方法。