从langchain.chains导入ConversationalRetrievalChain不起作用。

huangapple go评论120阅读模式
英文:

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在哪个路径中。我尝试了这个链接(https://api.python.langchain.com/en/latest/chains/langchain.chains.conversational_retrieval.base.ConversationalRetrievalChain.html),但langchain.chains.conversational_retrieval不存在,而且像官方的langchain网站(https://python.langchain.com/docs/modules/memory/conversational_customization)这样的其他网站只会让我更加困惑。

有人知道ConversationalRetrievalChain在Langchain版本0.0.27中的位置吗,或者我如何自己找到它。非常感谢 从langchain.chains导入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 从langchain.chains导入ConversationalRetrievalChain不起作用。

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安装库:

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(我正在使用 v3.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

huangapple
  • 本文由 发表于 2023年8月9日 12:34:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864606.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定