AttributeError: 'Model' object has no attribute '_ctx' : error while using gpt4all with langchain

3.2k Views Asked by At
from langchain import PromptTemplate, LLMChain
from langchain.llms import GPT4All
from langchain.callbacks.base import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

local_path = './models/gpt4all-converted.bin'
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])

template = """Question: {question}

Answer: Let's think step by step.

"""

prompt = PromptTemplate(template=template, input_variables=["question"])
llm = GPT4All(model=local_path,
              callback_manager=callback_manager, verbose=True)
llm_chain = LLMChain(prompt=prompt, llm=llm)

question = "What NFL team won the Super Bowl in the year Justin Bieber was born?"

# question = input("Enter your question: ")

llm_chain.run(question)

Trying to test langchain with gpt4all locally and got this error. Looks like version stuff. I have tried a lot to surf on internet but didn't get anything.

Exception ignored in: <function Model.__del__ at 0x7f45417143a0>
Traceback (most recent call last):
  File "/home/chirag/.local/lib/python3.8/site-packages/pyllamacpp/model.py", line 336, in __del__
    if self._ctx:
AttributeError: 'Model' object has no attribute '_ctx'
Traceback (most recent call last):
  File "basic_langchain_setup.py", line 16, in <module>
    llm = GPT4All(model=local_path,
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for GPT4All
__root__
  __init__() got an unexpected keyword argument 'ggml_model' (type=type_error)

Please help to resolve it.

2

There are 2 best solutions below

0
On

I also run into the same problem but then resolved with this.

pip install llama-cpp-python --force-reinstall --upgrade --no-cache-dir

0
On

I ran into the same problem, it looks like one of the dependencies of the gpt4all library changed, by downgrading pyllamacpp to 2.1.3 I was able to fix it.

pip install pyllamacpp==2.1.3