Reputation: 89
Im getting below warning and im able to reinstall pip but still it gives below warning. Error: .localpython/lib/python3.12/site-packages/langchain/document_loaders/init.py:36: LangChainDeprecationWarning: Importing document loaders from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:
`from langchain_community.document_loaders import DirectoryLoader`.
To install langchain-community run `pip install -U langchain-community`.
warnings.warn(
/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain/document_loaders/__init__.py:36: LangChainDeprecationWarning: Importing document loaders from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:
`from langchain_community.document_loaders import TextLoader`.
To install langchain-community run `pip install -U langchain-community`.
warnings.warn(
/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain/embeddings/__init__.py:29: LangChainDeprecationWarning: Importing embeddings from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:
`from langchain_community.embeddings import OpenAIEmbeddings`.
To install langchain-community run `pip install -U langchain-community`.
warnings.warn(
/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain/llms/__init__.py:548: LangChainDeprecationWarning: Importing LLMs from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:
`from langchain_community.llms import OpenAI`.
To install langchain-community run `pip install -U langchain-community`.
warnings.warn(
/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain/vectorstores/__init__.py:35: LangChainDeprecationWarning: Importing vector stores from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:
`from langchain_community.vectorstores import Chroma`.
To install langchain-community run `pip install -U langchain-community`.
warnings.warn(
Traceback (most recent call last):
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain_community/vectorstores/chroma.py", line 81, in __init__
import chromadb
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/chromadb/__init__.py", line 2, in <module>
import chromadb.config
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/chromadb/config.py", line 1, in <module>
from pydantic import BaseSettings
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/pydantic/__init__.py", line 374, in __getattr__
return _getattr_migration(attr_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/pydantic/_migration.py", line 296, in wrapper
raise PydanticImportError(
pydantic.errors.PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.6/migration/#basesettings-has-moved-to-pydantic-settings for more details.
For further information visit https://errors.pydantic.dev/2.6/u/import-error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/bata/balm1fxr/OpenAI/chatgpt-retrieval-main/chatgpt.py", line 35, in <module>
index = VectorstoreIndexCreator().from_loaders([loader])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain/indexes/vectorstore.py", line 84, in from_loaders
return self.from_documents(docs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain/indexes/vectorstore.py", line 89, in from_documents
vectorstore = self.vectorstore_cls.from_documents(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain_community/vectorstores/chroma.py", line 778, in from_documents
return cls.from_texts(
^^^^^^^^^^^^^^^
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain_community/vectorstores/chroma.py", line 714, in from_texts
chroma_collection = cls(
^^^^
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/langchain_community/vectorstores/chroma.py", line 84, in __init__
raise ImportError(
**ImportError: Could not import chromadb python package. Please install it with `pip install chromadb`**
**Chatgp.py code**
import os
import sys
import openai
from langchain.chains import ConversationalRetrievalChain, RetrievalQA
from langchain.chat_models import ChatOpenAI
from langchain.document_loaders import DirectoryLoader, TextLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.indexes import VectorstoreIndexCreator
from langchain.indexes.vectorstore import VectorStoreIndexWrapper
from langchain.llms import OpenAI
from langchain.vectorstores import Chroma
import constants
os.environ["OPENAI_API_KEY"] = constants.APIKEY
PERSIST = False
query = None
if len(sys.argv) > 1:
query = sys.argv[1]
if PERSIST and os.path.exists("persist"):
print("Reusing index...\n")
vectorstore = Chroma(persist_directory="persist", embedding_function=OpenAIEmbeddings())
index = VectorStoreIndexWrapper(vectorstore=vectorstore)
else:
#loader = TextLoader("data/data.txt") # Use this line if you only need data.txt
loader = DirectoryLoader("data/")
if PERSIST:
index = VectorstoreIndexCreator(vectorstore_kwargs={"persist_directory":"persist"}).from_loaders([loader])
else:
index = VectorstoreIndexCreator().from_loaders([loader])
chain = ConversationalRetrievalChain.from_llm(
llm=ChatOpenAI(model="gpt-3.5-turbo"),
retriever=index.vectorstore.as_retriever(search_kwargs={"k": 1}),
)
chat_history = []
while True:
if not query:
query = input("Prompt: ")
if query in ['quit', 'q', 'exit']:
sys.exit()
result = chain({"question": query, "chat_history": chat_history})
print(result['answer'])
chat_history.append((query, result['answer']))
query = None
Upvotes: 3
Views: 12444
Reputation: 256
The warning you're seeing is due to a recent change in LangChain. As of version 0.2.0, document_loaders have been moved from the langchain package to langchain-community. To resolve this issue, follow these steps:
Install the new package:
pip install langchain-community
Update your imports: Instead of importing from langchain, you should now import from langchain_community:
from langchain_community.document_loaders import DirectoryLoader, TextLoader
python version: 3.10.12
Upvotes: 0
Reputation: 1
I got the same deprecation warning, but "from langchain_openai import ChatOpenAI" worked. There's a bug logged in the langchain that the team is looking at. https://github.com/DataDog/dd-trace-py/issues/8212
Upvotes: 0