Spaces:
Sleeping
Sleeping
Update rag.py
Browse files
rag.py
CHANGED
|
@@ -24,6 +24,13 @@ similarity_model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
|
| 24 |
HF_DATASET_REPO = "midrees2806/unmatched_queries"
|
| 25 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Load dataset (automatically using the path)
|
| 28 |
with open('dataset.json', 'r') as f:
|
| 29 |
dataset = json.load(f)
|
|
@@ -67,10 +74,20 @@ def query_groq_llm(prompt, model_name="llama3-70b-8192"):
|
|
| 67 |
return ""
|
| 68 |
|
| 69 |
def get_best_answer(user_input):
|
|
|
|
|
|
|
|
|
|
| 70 |
user_input_lower = user_input.lower().strip()
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
# 👉 Check if question is about fee
|
| 73 |
-
if any(keyword in user_input_lower for keyword in ["fee", "fees
|
| 74 |
return (
|
| 75 |
"💰 For complete and up-to-date fee details for this program, we recommend visiting the official University of Education fee structure page.\n"
|
| 76 |
"You’ll find comprehensive information regarding tuition, admission charges, and other applicable fees there.\n"
|
|
|
|
| 24 |
HF_DATASET_REPO = "midrees2806/unmatched_queries"
|
| 25 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 26 |
|
| 27 |
+
# Greeting list
|
| 28 |
+
GREETINGS = [
|
| 29 |
+
"hi", "hello", "hey", "good morning", "good afternoon", "good evening",
|
| 30 |
+
"assalam o alaikum", "salam", "aoa", "hi there",
|
| 31 |
+
"hey there", "greetings"
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
# Load dataset (automatically using the path)
|
| 35 |
with open('dataset.json', 'r') as f:
|
| 36 |
dataset = json.load(f)
|
|
|
|
| 74 |
return ""
|
| 75 |
|
| 76 |
def get_best_answer(user_input):
|
| 77 |
+
|
| 78 |
+
if not user_input.strip():
|
| 79 |
+
return "Please enter a valid question."
|
| 80 |
user_input_lower = user_input.lower().strip()
|
| 81 |
|
| 82 |
+
if any(greet in user_input_lower for greet in GREETINGS):
|
| 83 |
+
greeting_response = query_groq_llm(
|
| 84 |
+
f"You are an official assistant for University of Education Lahore. "
|
| 85 |
+
f"Respond to this greeting in a friendly and professional manner: {user_input}"
|
| 86 |
+
)
|
| 87 |
+
return greeting_response if greeting_response else "Hello! How can I assist you today?"
|
| 88 |
+
|
| 89 |
# 👉 Check if question is about fee
|
| 90 |
+
if any(keyword in user_input_lower for keyword in ["fee structure", "fees structure"]):
|
| 91 |
return (
|
| 92 |
"💰 For complete and up-to-date fee details for this program, we recommend visiting the official University of Education fee structure page.\n"
|
| 93 |
"You’ll find comprehensive information regarding tuition, admission charges, and other applicable fees there.\n"
|