Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will this no longer work? #63

Open
soorajthekkepatt opened this issue May 31, 2024 · 6 comments
Open

Will this no longer work? #63

soorajthekkepatt opened this issue May 31, 2024 · 6 comments

Comments

@soorajthekkepatt
Copy link

Traceback (most recent call last):
File "/Users/sooraj/Documents/chat/chatgpt-retrieval/chatgpt.py", line 6, in
from langchain.chat_models import ChatOpenAI
File "/opt/homebrew/lib/python3.12/site-packages/langchain/chat_models/init.py", line 27, in getattr
from langchain_community import chat_models
ModuleNotFoundError: No module named 'langchain_community'
iconv: iconv_open(, -t): Invalid argument
Error converting string from to UTF-8

@Zhi0467
Copy link

Zhi0467 commented Jun 2, 2024

This is the imports that worked for me:
`import os
import sys

import openai
from langchain.chains import ConversationalRetrievalChain, RetrievalQA
from langchain_openai import ChatOpenAI
from langchain_community.document_loaders import DirectoryLoader, TextLoader
from langchain_openai import OpenAIEmbeddings
from langchain.indexes import VectorstoreIndexCreator
from langchain.indexes.vectorstore import VectorStoreIndexWrapper
from langchain_community.llms import OpenAI
from langchain_community.vectorstores import Chroma

import constants`

If you are using conda to install packages, I would suggest using python -m pip install langchain-openai langchain-community langchain-core in your conda environment, and avoid using conda install, so that your conda can actually find these packages.

@TamimLikhon
Copy link

TamimLikhon commented Jun 29, 2024

`import os
import sys

import openai
from langchain.chains import ConversationalRetrievalChain, RetrievalQA
from langchain_openai import ChatOpenAI
from langchain_community.document_loaders import DirectoryLoader, TextLoader
from langchain_openai import OpenAIEmbeddings
from langchain.indexes import VectorstoreIndexCreator
from langchain.indexes.vectorstore import VectorStoreIndexWrapper
from langchain_community.llms import OpenAI
from langchain_community.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`

when I run - python chatgpt.py "What is my name"
output:
ModuleNotFoundError: No module named 'langchain_community.indexes.vectorstore'

@Zhi0467
Copy link

Zhi0467 commented Jun 30, 2024

have you installed langchain-core and langchain-community manually using pip install? Check if your Python interpreter can find these packages, e.g. go to site-packages
or if you are using conda, stick to python -m pip install in the virtual env
of course, you can also try updating with pip install --upgrade langchain langchain-community

@TamimLikhon
Copy link

TamimLikhon commented Jul 2, 2024

`import os
import sys

import openai
from langchain.chains import ConversationalRetrievalChain, RetrievalQA
from langchain.indexes import VectorstoreIndexCreator
from langchain.indexes.vectorstore import VectorStoreIndexWrapper

import constants
from langchain_community.document_loaders import DirectoryLoader, TextLoader
from langchain_community.vectorstores import Chroma
from langchain_openai import ChatOpenAI, OpenAI, OpenAIEmbeddings

os.environ["OPENAI_API_KEY"] = constants.APIKEY

Enable to save to disk & reuse the model (for repeated queries on the same data)

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
`

output: still same
Traceback (most recent call last):
File "/home/tamim/Downloads/chatgpt-retrieval/chatgpt.py", line 6, in
from langchain.indexes import VectorstoreIndexCreator
File "/home/tamim/.local/lib/python3.10/site-packages/langchain/indexes/init.py", line 20, in
from langchain.indexes.vectorstore import VectorstoreIndexCreator
File "/home/tamim/.local/lib/python3.10/site-packages/langchain/indexes/vectorstore.py", line 8, in
from langchain_community.indexes.vectorstore import VectorstoreIndexCreator # Adjusted import
ModuleNotFoundError: No module named 'langchain_community.indexes.vectorstore'

@LevYas
Copy link

LevYas commented Aug 26, 2024

It does not make sense to fix these errors one by one. I had to completely rewrite it, but it still is not as good as I wanted. Here I wrote about my experience, my script included https://yastr.dev/posts/genai-rag-pitfalls/

@KaySchneider
Copy link

@LevYas thank you for your updates on that. Your Version looks really good and its actually workin for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants