Spaces:
Sleeping
Sleeping
Ali Abdullah
commited on
Update chatbot.py
Browse files- chatbot.py +22 -8
chatbot.py
CHANGED
|
@@ -139,6 +139,17 @@ class RAGChatbot:
|
|
| 139 |
|
| 140 |
context = "\n\n".join(context_parts)
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
# Step 3: Generate response using Groq
|
| 143 |
generation_start = time.time()
|
| 144 |
response = self._generate_response(message, context)
|
|
@@ -174,16 +185,19 @@ class RAGChatbot:
|
|
| 174 |
Returns:
|
| 175 |
Generated response
|
| 176 |
"""
|
| 177 |
-
system_prompt = """You are a helpful AI assistant
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
- Be accurate and
|
| 183 |
-
-
|
| 184 |
-
- If asked
|
| 185 |
-
-
|
| 186 |
"""
|
|
|
|
| 187 |
|
| 188 |
user_prompt = f"""Context:
|
| 189 |
{context}
|
|
|
|
| 139 |
|
| 140 |
context = "\n\n".join(context_parts)
|
| 141 |
|
| 142 |
+
# ✅ Fallback: if no meaningful context remains after filtering
|
| 143 |
+
if not context.strip():
|
| 144 |
+
return {
|
| 145 |
+
'response': "I couldn't find any good content to answer your question. Try ingesting a more informative page.",
|
| 146 |
+
'sources': [],
|
| 147 |
+
'retrieval_time': round(retrieval_time, 3),
|
| 148 |
+
'generation_time': 0,
|
| 149 |
+
'total_time': round(retrieval_time, 3),
|
| 150 |
+
'context_used': 0
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
# Step 3: Generate response using Groq
|
| 154 |
generation_start = time.time()
|
| 155 |
response = self._generate_response(message, context)
|
|
|
|
| 185 |
Returns:
|
| 186 |
Generated response
|
| 187 |
"""
|
| 188 |
+
system_prompt = """You are a helpful AI assistant.
|
| 189 |
+
|
| 190 |
+
You must answer user questions based strictly on the provided context below. Do not use outside knowledge, do not make up facts, and do not guess.
|
| 191 |
|
| 192 |
+
If the context does not contain enough information, say clearly: "I don’t have enough information in the context to answer that."
|
| 193 |
+
|
| 194 |
+
When you do answer:
|
| 195 |
+
- Be accurate, concise, and truthful
|
| 196 |
+
- Use facts and phrases from the context only
|
| 197 |
+
- If asked for a source, refer to the matching context
|
| 198 |
+
- Keep your tone friendly and professional
|
| 199 |
"""
|
| 200 |
+
|
| 201 |
|
| 202 |
user_prompt = f"""Context:
|
| 203 |
{context}
|