langcorn icon indicating copy to clipboard operation
langcorn copied to clipboard

Does it work with when chains are passed with return_source_documents=True,

Open sharrajesh opened this issue 1 year ago • 6 comments

I seem to be getting an whenever my chains have above config....

sharrajesh avatar Jun 02 '23 04:06 sharrajesh

Hi @sharrajesh! Thx for reporting the issue! Could you please share your code snippet?

msoedov avatar Jun 02 '23 09:06 msoedov

faiss_db_path = os.path.join(BASE_DIR, "workspace", "chat_with_text_files", "faiss_db")

def load_db(): embeddings = OpenAIEmbeddings() vectordb = FAISS.load_local(faiss_db_path, embeddings) retriever = vectordb.as_retriever() return retriever

def create_qa_chain(retriever): qa_chain = RetrievalQA.from_chain_type( llm=OpenAI(), chain_type="stuff", retriever=retriever, return_source_documents=True, verbose=True, ) return qa_chain

def cite_sources(llm_response): print(llm_response["result"]) print("\n\nSources:") for source in llm_response["source_documents"]: print(source.metadata["source"])

retriever = load_db() qa_chain = create_qa_chain(retriever)

sharrajesh avatar Jun 02 '23 19:06 sharrajesh

Another error AttributeError: 'ConversationalRetrievalChain' object has no attribute 'input_key'. Did you mean: 'input_keys'?

def create_qa_chain(retriever): memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True) chat_llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=OPENAI_TEMPERATURE) qa_chain = ConversationalRetrievalChain.from_llm( llm=chat_llm, retriever=retriever, chain_type="stuff", verbose=True, memory=memory, ) return qa_chain

def cite_sources(llm_response): # Check if 'answer' key exists in the llm_response. if "answer" in llm_response: print(llm_response["answer"])

# Check if 'source_documents' key exists in the llm_response.
if "source_documents" in llm_response:
    print("\n\nSources:")
    for source in llm_response["source_documents"]:
        print(source.metadata["source"])

retriever = load_db() qa_chain = create_qa_chain(retriever)

sharrajesh avatar Jun 03 '23 00:06 sharrajesh

Thx! Received all info. I have a local patch but still requires testing.

msoedov avatar Jun 06 '23 09:06 msoedov

Fixed this issue in 0.0.12

msoedov avatar Jul 12 '23 12:07 msoedov

this does not work with ConversationalRetrievalChain , please provide a fix as RetrievalQA is being depricated

joinalahmed avatar Aug 02 '23 19:08 joinalahmed