alejandro-ao / ask-multiple-pdfs

A Langchain app that allows you to chat with multiple PDFs
1.63k stars 933 forks source link

langchain.verbose Attribute Error #4

Open fozrok opened 1 year ago

fozrok commented 1 year ago

I copied the entire code and I'm getting this error:

AttributeError: module 'langchain' has no attribute 'verbose' Traceback:

File "/Users/name/multi_PDF/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
    exec(code, module.__dict__)
File "/Users/name/multi_PDF/multi.py", line 104, in <module>
    main()
File "/Users/name/multi_PDF/multi.py", line 99, in main
    st.session_state.conversation = get_conversation_chain(
File "/Users/name/multi_PDF/multi.py", line 41, in get_conversation_chain
    llm = ChatOpenAI()
File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic/main.py", line 1066, in pydantic.main.validate_model
File "pydantic/fields.py", line 439, in pydantic.fields.ModelField.get_default
File "/Users/name/multi_PDF/venv/lib/python3.10/site-packages/langchain/chat_models/base.py", line 32, in _get_verbosity
    return langchain.verbose

Also noticed that the code is missing the HTML User & Bot set up.

Not sure how to fix this.

HagaiHen commented 1 year ago

Try this:

pip install langchain==0.0.137

princedalsaniya commented 1 year ago

Hey @fozrok I also got this error, I have resolved it by just adding this line before initialising the llm variable. Just add langchain.verbose = False in previous line of initialisation of LLM.

Now the get_conversation_chain should look something like this.

def get_conversation_chain(vectorstore):
    langchain.verbose = False
    # llm = ChatOpenAI()
    llm = HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":0.5, "max_length":512})

    memory = ConversationBufferMemory(
        memory_key='chat_history', return_messages=True)
    conversation_chain = ConversationalRetrievalChain.from_llm(
        llm=llm,
        retriever=vectorstore.as_retriever(),
        memory=memory
    )
    return conversation_chain

Hope this should work for you, let me know what happened. Thanks.