Entreprenerdly commited on
Commit
3bbb339
·
verified ·
1 Parent(s): 43c7a1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -74,7 +74,8 @@ def main(message: str):
74
  qa_chain = ConversationalRetrievalChain.from_llm(
75
  ChatOpenAI(temperature=0),
76
  vectorstore.as_retriever(),
77
- memory=memory
 
78
  )
79
 
80
  cl.Message(content=f"Selected paper: {selected_paper.title}\nLink: {selected_paper.entry_id}\nYou can now ask questions about this paper. Type 'new search' when you want to search for a different paper.").send()
@@ -90,7 +91,9 @@ def main(message: str):
90
  else:
91
  # Answer questions about the selected paper
92
  response = qa_chain({"question": message})
93
- cl.Message(content=response["answer"]).send()
 
 
94
 
95
  if __name__ == "__main__":
96
- cl.run()
 
74
  qa_chain = ConversationalRetrievalChain.from_llm(
75
  ChatOpenAI(temperature=0),
76
  vectorstore.as_retriever(),
77
+ memory=memory,
78
+ return_source_documents=True # This enables returning the source of the answer
79
  )
80
 
81
  cl.Message(content=f"Selected paper: {selected_paper.title}\nLink: {selected_paper.entry_id}\nYou can now ask questions about this paper. Type 'new search' when you want to search for a different paper.").send()
 
91
  else:
92
  # Answer questions about the selected paper
93
  response = qa_chain({"question": message})
94
+ answer = response["answer"]
95
+ sources = "\n".join([f"- {doc.metadata['source']}" for doc in response["source_documents"]])
96
+ cl.Message(content=f"{answer}\n\nSources:\n{sources}").send()
97
 
98
  if __name__ == "__main__":
99
+ cl.run()