从LangChain根模块导入LLMChain已不被支持,求解决方案
解决LangChain中LLMChain导入错误的问题
问题原因
LangChain版本更新后,LLMChain不再支持从根模块langchain导入,需从专门的子模块获取该组件。
解决方案
修改导入语句,将LLMChain和PromptTemplate分别从对应子模块导入:
# 替换原导入行 from langchain.chains import LLMChain from langchain.prompts import PromptTemplate
(注:PromptTemplate在新版本中也建议从langchain.prompts子模块导入,避免后续版本出现类似兼容性警告)
修改后的核心代码片段
from cassandra.cluster import Cluster from cassandra.auth import PlainTextAuthProvider from langchain.memory import CassandraChatMessageHistory, ConversationBufferMemory from langchain.llms import OpenAI from langchain.chains import LLMChain from langchain.prompts import PromptTemplate import json # 其余代码保持不变...
补充说明
LangChain v0.1.0及以上版本对核心组件做了模块化拆分,所有链类统一归到langchain.chains下,提示模板类归到langchain.prompts下,遵循这个规范可以避免多数版本迭代引发的导入错误。
内容的提问来源于stack exchange,提问作者Atabek
相关产品推荐
相关产品推荐

