Я получаю ниже предупреждение и могу переустановить PIP, но все же дает ниже предупреждение.
ошибка:
. Localpython/lib/python3.12/site-packages/langchain/document_loaders/ init .py: 36: langchaindeprecationwarning: импорт загрузчиков документов из Langchain устарел. Импорт из Langchain больше не будет поддерживаться по состоянию на Langchain == 0.2.0. Пожалуйста, импортируйте из Community вместо этого: < /p>
`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
import chromadb.config
File "/home/balm1fxr/.localpython/lib/python3.12/site-packages/chromadb/config.py", line 1, in
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 ... c-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
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
Подробнее здесь: https://stackoverflow.com/questions/779 ... -is-deprec
LangchaindeprecationWarning: импорт загрузчиков документов из Langchain устарел. Импорт из Langchain больше не будет под ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение