Ali Abdullah commited on
Commit
8b6d78f
·
verified ·
1 Parent(s): 6a0b840

Update chatbot.py

Browse files
Files changed (1) hide show
  1. 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 that answers questions based on the provided context.
 
 
178
 
179
- Guidelines:
180
- - Use ONLY the information provided in the context to answer questions
181
- - If the context doesn't contain enough information, say so clearly
182
- - Be accurate and cite specific details from the context
183
- - Provide comprehensive answers but stay focused on the question
184
- - If asked about sources, refer to the context provided
185
- - Be conversational and helpful in your tone
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}