langchain
langchain copied to clipboard
Validation Error
System Info
Python Version: 3.9.11 Langchain version = 0.0.167
I'm getting a validation error with GPT4All where I'm following the instructions of the notebook and installed all packages but apparently there's some parameters called n_parts that isn't part of the GPT4All attribute
from langchain import PromptTemplate, LLMChain
from langchain.llms import GPT4All
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
import requests
from pathlib import Path
from tqdm import tqdm
Path(local_path).parent.mkdir(parents=True, exist_ok=True)
url = 'http://gpt4all.io/models/ggml-gpt4all-l13b-snoozy.bin'
response = requests.get(url, stream=True)
with open(local_path, 'wb') as f:
for chunk in tqdm(response.iter_content(chunk_size=8192)):
if chunk:
f.write(chunk)
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate(template=template, input_variables=["question"])
callbacks = [StreamingStdOutCallbackHandler()]
llm = GPT4All(model=local_path, callbacks=callbacks, verbose=True)
llm = GPT4All(model=local_path, backend='gptj', callbacks=callbacks, verbose=True)
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "What NFL team won the Super Bowl in the year Justin Bieber was born?"
llm_chain.run(question)
and this is the error I get
Exception ignored in: <function Model.__del__ at 0x2aaaed28aa60>
Traceback (most recent call last):
File "/home/traney/.conda/envs/openai/lib/python3.9/site-packages/pyllamacpp/model.py", line 402, in __del__
if self._ctx:
AttributeError: 'GPT4All' object has no attribute '_ctx'
Exception ignored in: <function Model.__del__ at 0x2aaaed28aa60>
Traceback (most recent call last):
File "/home/traney/.conda/envs/openai/lib/python3.9/site-packages/pyllamacpp/model.py", line 402, in __del__
if self._ctx:
AttributeError: 'GPT4All' object has no attribute '_ctx'
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
Cell In[31], line 11
9 callbacks = [StreamingStdOutCallbackHandler()]
10 # Verbose is required to pass to the callback manager
---> 11 llm = GPT4All(model=local_path, callbacks=callbacks, verbose=True)
12 # If you want to use a custom model add the backend parameter
13 # Check https://docs.gpt4all.io/gpt4all_python.html for supported backends
14 llm = GPT4All(model=local_path, backend='gptj', callbacks=callbacks, verbose=True)
File ~/.conda/envs/openai/lib/python3.9/site-packages/pydantic/main.py:341, in pydantic.main.BaseModel.__init__()
ValidationError: 1 validation error for GPT4All
__root__
__init__() got an unexpected keyword argument 'n_parts' (type=type_error)
I installed all relevant packages and checked the previous reports for these issues but I just get different errors from not being able to find the model, to validation error to GPT4All not existing. Is there any new things I have to do to implement GPT4All on langchain?
Who can help?
No response
Information
- [X] The official example notebooks/scripts
- [ ] My own modified scripts
Related Components
- [X] LLMs/Chat Models
- [ ] Embedding Models
- [X] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
Follow code above in Jupyter Notebook
Expected behavior
the chat model should answer the question
Generated by a 🤖
Answer
It seems like there is an issue with the GPT4All implementation in the LangChain library. The error message indicates that the 'n_parts' parameter is not expected in the GPT4All class. However, the provided context shows that 'n_parts' is indeed a part of the GPT4All class definition.
One possible reason for this discrepancy could be that you have an older version of the LangChain library installed, which might not have the 'n_parts' parameter in the GPT4All class. To resolve this issue, try updating the LangChain library to the latest version using the following command:
pip install --upgrade langchain
After updating the library, try running your code again. If the issue persists, it might be a bug in the library, and you should consider reporting it to the LangChain developers
Sources
This response is meant to be helpful and save users time. It is not meant to be a precise solution.
Please leave a 👍 if this is helpful and 👎 if it is irrelevant
I did update langchain and unfortunately, same error occurs
a new PR was merged to this repo just yesterday, that fixes this issue. You can install the application directly from the repo. This fixes the issue.
Hi, @talraney! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
Based on my understanding, you were experiencing a validation error when trying to implement GPT4All on langchain. You mentioned that you have installed all relevant packages and checked previous reports, but are still encountering different errors. "devstein" suggested updating the LangChain library to the latest version, but you mentioned that you have already done so without success. However, "intiamaru" commented that a new PR was merged to the repository that fixes the issue and suggested installing the application directly from the repo.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.
Thank you for your understanding and cooperation!
Hi, @talraney! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
Based on my understanding, you were experiencing a validation error when trying to implement GPT4All on langchain. You mentioned that you have installed all relevant packages and checked previous reports, but are still encountering different errors. "devstein" suggested updating the LangChain library to the latest version, but you mentioned that you have already done so without success. However, "intiamaru" commented that a new PR was merged to the repository that fixes the issue and suggested installing the application directly from the repo.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.
Thank you for your understanding and cooperation!