Spaces:
Running
Running
Update rag.py
Browse files
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", "
|
27 |
-
"hey there", "greetings"
|
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"""
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
else:
|
118 |
prompt = f"""As an official assistant for University of Education Lahore, provide a helpful response:
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
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
|