Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 99 |
-
sources = "\n".join([f"- {doc.metadata
|
| 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 |
|