英文:
Importing ConversationalRetrievalChain from langchain.chains isn't working
问题
我试图按照关于Langchain和Streamlit的各种教程,但在导入名称方面遇到了许多问题。我的主要问题是,我似乎无法从langchain.chains
中导入ConversationalRetrievalChain
。这并不是这个奇怪问题的第一个案例,例如
from langchain.chains import ConversationBufferMemory
这行代码不起作用,返回错误:无法从langchain.chains
导入名称ConversationBufferMemory
(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/langchain/chains/init.py)。
但是,当我写下以下代码时
from langchain.chains.conversation.memory import ConversationBufferMemory
它可以正常工作。似乎在导入语句中指定要使用的包的路径对其正常工作至关重要。
有了这个想法,我想知道有没有人知道ConversationalRetrievalChain
在哪个路径下。我尝试了这个链接,但langchain.chains.conversational_retrieval
并不存在,而且像官方Langchain网站等许多其他网站都让我更加困惑。
是否有人知道在Langchain版本0.0.27中ConversationalRetrievalChain
位于何处,或者我应该如何自行查找它。非常感谢
我在代码中尝试过以下内容:
from langchain.chains import ConversationalRetrievalChain
from langchain.chains.conversation import ConversationalRetrievalChain
from langchain.chains.conversation.memory import ConversationalRetrievalChain
langchain.chains.conversational_retrieval.base import ConversationalRetrievalChain
其他尝试:
- 安装较旧版本的Langchain(一直说我需要Python >= 3.8.1,尽管我有Python 3.8.9)
我去查找的地方:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/langchain/chains/
- Langchain文档
英文:
I am trying to follow various tutorials on langchain and streamlit and I have encountered many problems regarding the names of imports. My main problem is that I can't seem to import ConversationalRetrievalChain from langchain.chains. This isn't the first case of this strange issue, for example
from langchain.chains import ConversationBufferMemory
this line of code doesn't work, and returns the error: cannot import name 'ConversationBufferMemory' from 'langchain.chains' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/langchain/chains/init.py)
However, when I write the following code
from langchain.chains.conversation.memory import ConversationBufferMemory
It works fine. It would appear as if specifying the path to the packet I want to use in the import statement is imperative for it to work.
With this in mind I was wondering if anyone had any insight as to what path ConversationalRetrievalChain was in. I tried this, but langchain.chains.conversational_retrieval doesn't exist and many other websites like the [official langchain website] (https://python.langchain.com/docs/modules/memory/conversational_customization) have only lead me more astray.
Does anyone know where ConversationalRetrievalChain is located in Langchain version 0.0.27, or how I might go about finding it myself. Many thanks
What I have tried in my code:
- from langchain.chains import ConversationalRetrievalChain
- from langchain.chains.conversation import ConversationalRetrievalChain
- from langchain.chains.conversation.memory import ConversationalRetrievalChain
- langchain.chains.conversational_retrieval.base import ConversationalRetrievalChain
other things:
- Installing an older version of langchain (keeps saying I need python >= 3.8.1 even though I have python 3.8.9)
Where I have gone to look:
- /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/langchain/chains/
- Langchain documentation
答案1
得分: 1
请尝试以下步骤。
使用以下命令创建虚拟环境:
python -m venv my_venv_name
通过执行以下命令激活虚拟环境:
source my_venv_name/bin/activate
使用以下命令安装库:
pip install langchain==0.0.208
pip install """其他所需的库,如OpenAI等等"""
现在,您应该能够成功导入以下内容:
from langchain.chains import ConversationBufferMemory
英文:
Could you try below steps.
Create a virtual environment using the command
python -m venv my_venv_name
Activate the virtual environment by executing source
my_venv_name/bin/activate
PIP install libraries
pip install langchain==0.0.208
pip install """Other required libraries like OpenAI etc..
You should now successfully able to import
from langchain.chains import ConversationBufferMemory
答案2
得分: 1
我遇到了相似的问题:
ImportError: 无法从 'langchain.chains' 导入名称 'ConversationalRetrievalChain'
对我来说,升级到最新的 langchain 包版本有所帮助:
pip install langchain --upgrade
当前版本是 '0.0.266',所以也许可以安装它,而不是 '0.0.208',正如有人指出的那样。
还请安装最新版本的 Python(我使用的是 v.3.11),因为旧版本可能不支持 langchain 的新版本。
英文:
I had quite similar issue:
ImportError: cannot import name 'ConversationalRetrievalChain' from 'langchain.chains'
For me upgrading to the newest langchain package version helped:
pip install langchain --upgrade
Actual version is '0.0.266', so maybe install that instead of '0.0.208' which somebody pointed.
Please also install the newest version of Python (I'm using v.3.11), as the older ones may not support langchain in newer versions.
答案3
得分: 0
ConversationBufferMemory
属于 langchain.memory
或者更具体地说是 langchain.memory.buffer
,如果你这样做:
from langchain.memory.buffer import ConversationBufferMemory
from langchain.memory import ConversationBufferMemory
两种方式都可以。查看 API 参考文档 > https://api.python.langchain.com/en/latest/memory/langchain.memory.buffer.ConversationBufferMemory.html
顺便提一下,在我的环境中,langchain
版本如下:
pip list | grep langchain
langchain 0.0.264
英文:
ConversationBufferMemory
belongs to langchain.memory
or specifically langchain.memory.buffer
, if you do
from langchain.memory.buffer import ConversationBufferMemory
from langchain.memory import ConversationBufferMemory
Both should work. Check the API reference > https://api.python.langchain.com/en/latest/memory/langchain.memory.buffer.ConversationBufferMemory.html
By the way, langchain
in my env
pip list | grep langchain
langchain 0.0.264
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论