Nav772 commited on
Commit
d4da64e
·
verified ·
1 Parent(s): 3fee55d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
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
- prompt = f"<|system|>\nAnswer based on context only.\n</s>\n<|user|>\nContext:\n{context}\n\nQuestion: {question}\n</s>\n<|assistant|>\n"
45
- response = client.text_generation(prompt, max_new_tokens=512, temperature=0.7)
 
 
 
 
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: