Subha95 commited on
Commit
d5a9c3a
·
verified ·
1 Parent(s): 0a6a1d9

Update chatbot_rag.py

Browse files
Files changed (1) hide show
  1. chatbot_rag.py +14 -13
chatbot_rag.py CHANGED
@@ -52,8 +52,8 @@ def build_qa():
52
  model=model,
53
  tokenizer=tokenizer,
54
  max_new_tokens=256,
55
- temperature=0.7,
56
- do_sample=True,
57
  return_full_text=False # 🚀 only return new text, avoids messy context echoes
58
  )
59
 
@@ -64,19 +64,20 @@ def build_qa():
64
 
65
  # 5. Prompt
66
  prompt = PromptTemplate(
67
- input_variables=["context", "question"],
68
- template="""
69
- Use the following context to answer the question at the end.
70
- If you don't know the answer, just say "I don't know" — do not make up an answer.
71
-
72
- Context:
73
- {context}
74
-
75
- Question: {question}
76
- Answer (one short sentence):
77
- """,
78
  )
79
 
 
80
  # 6. Helper functions
81
  def format_docs(docs):
82
  return "\n".join(doc.page_content for doc in docs)
 
52
  model=model,
53
  tokenizer=tokenizer,
54
  max_new_tokens=256,
55
+ temperature=0.2,
56
+ do_sample=False,
57
  return_full_text=False # 🚀 only return new text, avoids messy context echoes
58
  )
59
 
 
64
 
65
  # 5. Prompt
66
  prompt = PromptTemplate(
67
+ input_variables=["context", "question"],
68
+ template="""
69
+ You are a strict assistant. Only answer using the CONTEXT provided.
70
+ If the CONTEXT does not have the answer, reply exactly with: "I don't know".
71
+
72
+ CONTEXT:
73
+ {context}
74
+
75
+ QUESTION: {question}
76
+ ANSWER:
77
+ """,
78
  )
79
 
80
+
81
  # 6. Helper functions
82
  def format_docs(docs):
83
  return "\n".join(doc.page_content for doc in docs)