langchain icon indicating copy to clipboard operation
langchain copied to clipboard

langchain + gpt4all 执行异常,总提示参数问题

Open guanman opened this issue 1 year ago • 2 comments

System Info

LangChain v0.0.225, Windows10, Python 3.10

Who can help?

No response

Information

  • [ ] The official example notebooks/scripts
  • [ ] My own modified scripts

Related Components

  • [ ] LLMs/Chat Models
  • [ ] Embedding Models
  • [ ] Prompts / Prompt Templates / Prompt Selectors
  • [ ] Output Parsers
  • [ ] Document Loaders
  • [ ] Vector Stores / Retrievers
  • [ ] Memory
  • [ ] Agents / Agent Executors
  • [ ] Tools / Toolkits
  • [ ] Chains
  • [ ] Callbacks/Tracing
  • [ ] Async

Reproduction

一个来自langchain的事例代码如下: from langchain import PromptTemplate, LLMChain from langchain.llms import GPT4All from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

local_path = ( "ggml-gpt4all-j-v1.3-groovy.bin" # replace with your desired local file path )

callbacks = [StreamingStdOutCallbackHandler()] llm = GPT4All(model=local_path, 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)

执行的结果如下: TypeError: GPT4All.generate() got an unexpected keyword argument 'n_ctx'

当我加上参数 max_tokens=200 时:llm = GPT4All(model=local_path, max_tokens=200, callbacks=callbacks, verbose=True) 出现如下结果: ValidationError: 1 validation error for GPT4All max_tokens extra fields not permitted (type=value_error.extra)

Expected behavior

callbacks = [StreamingStdOutCallbackHandler()] llm = GPT4All(model=local_path, max_tokens=200, 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)

#可以输出正确结果

guanman avatar Jul 06 '23 09:07 guanman

Answer generated by a 🤖

Answer

I understand that you're encountering an issue when trying to run a LangChain example code with the GPT4All model. The error messages you're seeing suggest that there's an unexpected keyword argument 'n_ctx' and that 'max_tokens' is not a permitted field.

Based on the context, it seems that the instantiation of the GPT4All class requires the path to the pre-trained model file and the model's configuration. The 'n_ctx' parameter should be accepted here, which contradicts the TypeError you're encountering. Here's how your code should look:

llm = GPT4All(model=local_path, n_ctx=512, callbacks=callbacks, verbose=True)

As for the 'max_tokens' parameter, there's no information provided in the context about it, so I can't confirm whether it should be set when instantiating GPT4All.

This is just one potential solution based on the information available. If this doesn't resolve your issue, it might be worth checking if you're using the latest version of LangChain, as the code behavior you're experiencing might have been addressed in a more recent update.

If you find that this solution is correct and you believe this is a bug that could impact other users, I encourage you to make a pull request to help improve LangChain.

Sources


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

dosubot[bot] avatar Jul 06 '23 12:07 dosubot[bot]

按照您的方式,增加参数n_ctx=512后问题依然存在。我的gpt4all版本是1.0.2,当我换成0.3.6时问题解决。我想知道对于高版本的gpt4all这是否算是一个bug? image

guanman avatar Jul 06 '23 13:07 guanman

Hi, @guanman! I'm Dosu, and I'm helping the LangChain team manage our backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you encountered an error when executing the langchain + gpt4all code, which mentioned unexpected keyword arguments and extra fields not permitted. Another user named dosu-beta suggested a potential solution by providing the correct code snippet and advised checking for the latest version of LangChain. You confirmed that updating to version 0.3.6 resolves the issue and asked if this is a bug in the higher version of gpt4all.

Before we close this issue, could you please let us know if this issue is still relevant to the latest version of the LangChain repository? If it is, please comment on this issue and let us know. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.

Thank you for your contribution to the LangChain repository!

dosubot[bot] avatar Oct 06 '23 16:10 dosubot[bot]