Entreprenerdly commited on
Commit
d0474e3
·
verified ·
1 Parent(s): a141365

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -64,7 +64,7 @@ def main(message: str):
64
 
65
  # Create embeddings and vector store
66
  embeddings = OpenAIEmbeddings()
67
- vectorstore = FAISS.from_texts(chunks, embeddings)
68
 
69
  # Create the conversational chain
70
  memory = ConversationBufferMemory(
@@ -95,8 +95,8 @@ def main(message: str):
95
  response = qa_chain({"question": message})
96
  answer = response["answer"]
97
 
98
- # Handling the sources and formatting the response
99
- sources = "\n".join([f"- {doc.metadata['source']}" for doc in response.get("source_documents", [])])
100
  if sources:
101
  answer += f"\n\nSources:\n{sources}"
102
 
 
64
 
65
  # Create embeddings and vector store
66
  embeddings = OpenAIEmbeddings()
67
+ vectorstore = FAISS.from_texts(chunks, embeddings, metadatas=[{"title": selected_paper.title, "link": selected_paper.entry_id}] * len(chunks))
68
 
69
  # Create the conversational chain
70
  memory = ConversationBufferMemory(
 
95
  response = qa_chain({"question": message})
96
  answer = response["answer"]
97
 
98
+ # Check if source metadata is present, otherwise handle gracefully
99
+ sources = "\n".join([f"- {doc.metadata.get('title', 'Unknown title')} ({doc.metadata.get('link', 'No link')})" for doc in response.get("source_documents", [])])
100
  if sources:
101
  answer += f"\n\nSources:\n{sources}"
102