Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,8 +41,12 @@ def answer_question(question):
|
|
| 41 |
try:
|
| 42 |
docs = vectorstore.similarity_search(question, k=3)
|
| 43 |
context = "\n\n".join([doc.page_content for doc in docs])
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
sources = [f"{i}. Page {doc.metadata.get('page', 'N/A')}" for i, doc in enumerate(docs, 1)]
|
| 47 |
return response, "\n".join(sources)
|
| 48 |
except Exception as e:
|
|
|
|
| 41 |
try:
|
| 42 |
docs = vectorstore.similarity_search(question, k=3)
|
| 43 |
context = "\n\n".join([doc.page_content for doc in docs])
|
| 44 |
+
messages = [
|
| 45 |
+
{"role": "system", "content": "Answer based on the provided context only. If the answer is not in the context, say so."},
|
| 46 |
+
{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {question}"}
|
| 47 |
+
]
|
| 48 |
+
response = client.chat_completion(messages, max_tokens=512, temperature=0.7)
|
| 49 |
+
response = response.choices[0].message.content
|
| 50 |
sources = [f"{i}. Page {doc.metadata.get('page', 'N/A')}" for i, doc in enumerate(docs, 1)]
|
| 51 |
return response, "\n".join(sources)
|
| 52 |
except Exception as e:
|