Shubham170793 commited on
Commit
09c2f03
·
verified ·
1 Parent(s): a610ce4

Update src/qa.py

Browse files
Files changed (1) hide show
  1. src/qa.py +23 -9
src/qa.py CHANGED
@@ -125,16 +125,30 @@ def generate_answer(query: str, retrieved_chunks: list):
125
  prompt = PROMPT_TEMPLATE.format(context=context, query=query)
126
 
127
  try:
128
- result = _answer_model(
129
- prompt,
130
- max_new_tokens=300,
131
- do_sample=False,
132
- temperature=0.2
 
 
 
 
 
 
 
 
 
 
 
133
  )
134
- return result[0]["generated_text"].strip()
135
- except Exception as e:
136
- print(f"⚠️ Generation failed: {e}")
137
- return "⚠️ Error: Could not generate an answer at the moment."
 
 
 
138
 
139
 
140
  # ==========================================================
 
125
  prompt = PROMPT_TEMPLATE.format(context=context, query=query)
126
 
127
  try:
128
+ result = _answer_model(
129
+ prompt,
130
+ max_new_tokens=350, # allow longer, more complete answers
131
+ do_sample=True, # enable sampling for natural flow
132
+ temperature=0.7, # slightly higher = more expressive responses
133
+ top_p=0.95, # nucleus sampling for coherence
134
+ repetition_penalty=1.2 # discourages repetitive phrasing
135
+ )
136
+
137
+ answer = result[0]["generated_text"].strip()
138
+
139
+ # 🧩 If the model outputs something too short, expand gracefully
140
+ if len(answer.split()) < 8:
141
+ answer = (
142
+ "The document mentions this briefly. Based on the context, here's what it suggests: "
143
+ + answer
144
  )
145
+
146
+ return answer
147
+
148
+ except Exception as e:
149
+ print(f"⚠️ Generation failed: {e}")
150
+ return "⚠️ Error: Could not generate an answer at the moment."
151
+
152
 
153
 
154
  # ==========================================================