midrees2806 commited on
Commit
c8676ae
·
verified ·
1 Parent(s): 0280e01

Update rag.py

Browse files
Files changed (1) hide show
  1. rag.py +25 -11
rag.py CHANGED
@@ -23,8 +23,8 @@ HF_TOKEN = os.getenv("HF_TOKEN")
23
  # Greeting list
24
  GREETINGS = [
25
  "hi", "hello", "hey", "good morning", "good afternoon", "good evening",
26
- "assalam o alaikum", "salam", "namaste", "hola", "bonjour", "hi there",
27
- "hey there", "greetings", "howdy"
28
  ]
29
 
30
  # Load local dataset
@@ -110,21 +110,35 @@ def get_best_answer(user_input):
110
 
111
  if best_score >= 0.65:
112
  original_answer = dataset_answers[best_match_idx]
113
- prompt = f"""As an official assistant for University of Education Lahore, provide a clear response:
114
- Question: {user_input}
115
- Original Answer: {original_answer}
116
- Improved Answer:"""
 
 
 
 
 
 
 
 
 
 
117
  else:
118
  prompt = f"""As an official assistant for University of Education Lahore, provide a helpful response:
119
- Include relevant details about university policies.
120
- If unsure, direct to official channels.
121
- Question: {user_input}
122
- Official Answer:"""
 
 
 
 
123
 
124
  llm_response = query_groq_llm(prompt)
125
 
126
  if llm_response:
127
- for marker in ["Improved Answer:", "Official Answer:"]:
128
  if marker in llm_response:
129
  return llm_response.split(marker)[-1].strip()
130
  return llm_response
 
23
  # Greeting list
24
  GREETINGS = [
25
  "hi", "hello", "hey", "good morning", "good afternoon", "good evening",
26
+ "assalam o alaikum", "salam", "aoa", "hi there",
27
+ "hey there", "greetings"
28
  ]
29
 
30
  # Load local dataset
 
110
 
111
  if best_score >= 0.65:
112
  original_answer = dataset_answers[best_match_idx]
113
+ prompt = f"""You are an official assistant for the University of Education Lahore.
114
+
115
+ Rephrase the following official answer clearly and professionally.
116
+ Use structured formatting (like headings, bullet points, or numbered lists) where appropriate.
117
+ DO NOT add any new or extra information. ONLY rephrase and improve the clarity and formatting of the original answer.
118
+
119
+ ### Question:
120
+ {user_input}
121
+
122
+ ### Original Answer:
123
+ {original_answer}
124
+
125
+ ### Rephrased Answer:
126
+ """
127
  else:
128
  prompt = f"""As an official assistant for University of Education Lahore, provide a helpful response:
129
+ Include relevant details about university policies.
130
+ If unsure, direct to official channels.
131
+
132
+ ### Question:
133
+ {user_input}
134
+
135
+ ### Official Answer:
136
+ """
137
 
138
  llm_response = query_groq_llm(prompt)
139
 
140
  if llm_response:
141
+ for marker in ["Improved Answer:", "Official Answer:", "Rephrased Answer:"]:
142
  if marker in llm_response:
143
  return llm_response.split(marker)[-1].strip()
144
  return llm_response