跳到主要內容
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

以下類別現在需要傳遞明確的嵌入模型作為引數

  • 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 事件 V1

如果您正在使用 astream_events,請檢閱如何遷移到 astream 事件 v2

langchain_core

try_load_from_hub

在模組:utils.loading 已棄用:0.1.30 移除:0.3.0

替代方案:使用 hwchase17/langchain-hub repo 取得提示已棄用。請改用 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

RunTypeEnum

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案:改用字串。

TracerSessionV1Base

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案

TracerSessionV1Create

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案

TracerSessionV1

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案

TracerSessionBase

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案

TracerSession

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案

BaseRun

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案:Run

LLMRun

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案:Run

ChainRun

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案:Run

ToolRun

在模組:tracers.schemas 已棄用:0.1.0 移除:0.3.0

替代方案:Run

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

在模組:utils.function_calling 已棄用:0.1.16 移除:0.3.0

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

convert_pydantic_to_openai_tool

在模組:utils.function_calling 已棄用:0.1.16 移除:0.3.0

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

convert_python_function_to_openai_function

在模組:utils.function_calling 已棄用:0.1.16 移除:0.3.0

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

format_tool_to_openai_function

在模組:utils.function_calling 已棄用:0.1.16 移除:0.3.0

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

format_tool_to_openai_tool

在模組:utils.function_calling 已棄用:0.1.16 移除:0.3.0

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

langchain

AgentType

在模組:agents.agent_types 已棄用:0.1.0 移除:0.3.0

替代方案:使用LangGraph 或新的代理程式建構子方法,例如 create_react_agent、create_json_agent、create_structured_chat_agent 等。

Chain.__call__

在模組:chains.base 已棄用:0.1.0 移除:0.3.0

替代方案:invoke

Chain.acall

在模組:chains.base 已棄用:0.1.0 移除:0.3.0

替代方案:ainvoke

Chain.run

在模組:chains.base 已棄用:0.1.0 移除:0.3.0

替代方案:invoke

Chain.arun

在模組:chains.base 已棄用:0.1.0 移除:0.3.0

替代方案:ainvoke

Chain.apply

在模組:chains.base 已棄用:0.1.0 移除:0.3.0

替代方案:batch

LLMChain

在模組:chains.llm 已棄用:0.1.17 移除:0.3.0

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

遷移指南有並排比較。

LLMSingleActionAgent

在模組:agents.agent 已棄用:0.1.0 移除:0.3.0

替代方案:使用LangGraph 或新的代理程式建構子方法,例如 create_react_agent、create_json_agent、create_structured_chat_agent 等。

Agent

在模組:agents.agent 已棄用:0.1.0 移除:0.3.0

替代方案:使用LangGraph 或新的代理程式建構子方法,例如 create_react_agent、create_json_agent、create_structured_chat_agent 等。

OpenAIFunctionsAgent

在模組:agents.openai_functions_agent.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_openai_functions_agent

ZeroShotAgent

在模組:agents.mrkl.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_react_agent

MRKLChain

在模組:agents.mrkl.base 已棄用:0.1.0 移除:0.3.0

替代方案

ConversationalAgent

在模組:agents.conversational.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_react_agent

ConversationalChatAgent

在模組:agents.conversational_chat.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_json_chat_agent

ChatAgent

在模組:agents.chat.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_react_agent

OpenAIMultiFunctionsAgent

在模組:agents.openai_functions_multi_agent.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_openai_tools_agent

ReActDocstoreAgent

在模組:agents.react.base 已棄用:0.1.0 移除:0.3.0

替代方案

DocstoreExplorer

在模組:agents.react.base 已棄用:0.1.0 移除:0.3.0

替代方案

ReActTextWorldAgent

在模組:agents.react.base 已棄用:0.1.0 移除:0.3.0

替代方案

ReActChain

在模組:agents.react.base 已棄用:0.1.0 移除:0.3.0

替代方案

SelfAskWithSearchAgent

在模組:agents.self_ask_with_search.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_self_ask_with_search

SelfAskWithSearchChain

在模組:agents.self_ask_with_search.base 已棄用:0.1.0 移除:0.3.0

替代方案

StructuredChatAgent

在模組:agents.structured_chat.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_structured_chat_agent

RetrievalQA

在模組:chains.retrieval_qa.base 已棄用:0.1.17 移除:0.3.0

替代方案:create_retrieval_chain遷移指南有並排比較。

load_agent_from_config

在模組:agents.loading 已棄用:0.1.0 移除:0.3.0

替代方案

load_agent

在模組:agents.loading 已棄用:0.1.0 移除:0.3.0

替代方案

initialize_agent

在模組:agents.initialize 已棄用:0.1.0 移除:0.3.0

替代方案:使用LangGraph 或新的代理程式建構子方法,例如 create_react_agent、create_json_agent、create_structured_chat_agent 等。

XMLAgent

在模組:agents.xml.base 已棄用:0.1.0 移除:0.3.0

替代方案:create_xml_agent

CohereRerank

在模組:retrievers.document_compressors.cohere_rerank 已棄用:0.0.30 移除:0.3.0

替代方案:langchain_cohere.CohereRerank

ConversationalRetrievalChain

在模組:chains.conversational_retrieval.base 已棄用:0.1.17 移除:0.3.0

替代方案:create_history_aware_retrievercreate_retrieval_chain 一起使用(請參閱文件字串中的範例)此遷移指南有並排比較。

create_extraction_chain_pydantic

在模組:chains.openai_tools.extraction 已棄用:0.1.14 移除:0.3.0

替代方案:支援工具呼叫的聊天模型上的 with_structured_output 方法。

create_openai_fn_runnable

在模組:chains.structured_output.base 已棄用:0.1.14 移除:0.3.0

替代方案:支援工具呼叫的聊天模型上的 with_structured_output 方法。

create_structured_output_runnable

在模組:chains.structured_output.base 已棄用:0.1.17 移除: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

建立提取鏈

在模組:chains.openai_functions.extraction 已棄用:0.1.14 移除:0.3.0

替代方案:支援工具呼叫的聊天模型上的 with_structured_output 方法。

建立提取鏈_Pydantic

在模組:chains.openai_functions.extraction 已棄用:0.1.14 移除:0.3.0

替代方案:支援工具呼叫的聊天模型上的 with_structured_output 方法。


此頁面是否有幫助?