minh-4T commited on
Commit
f6f1186
·
1 Parent(s): d9fdf21

update not mentioned

Browse files
Files changed (1) hide show
  1. rag/qa_pipeline.py +18 -3
rag/qa_pipeline.py CHANGED
@@ -216,8 +216,9 @@ def ask_ai_stream_delta(message: str, history: List, hybrid_retriever, cohort_ke
216
  prompt = create_advanced_prompt(question, context, question_type, topic_hint)
217
 
218
  logger.info("Đang tạo câu trả lời cuối cùng ...")
219
- generated_text = ""
220
  success = False
 
 
221
  for _ in range(len(api_manager.groq_keys) if api_manager.groq_keys else 1):
222
  try:
223
  client = api_manager.get_groq_client()
@@ -251,7 +252,7 @@ def ask_ai_stream_delta(message: str, history: List, hybrid_retriever, cohort_ke
251
  response = model.generate_content(prompt, stream=True)
252
  for chunk in response:
253
  if chunk.text:
254
- generated_text += chunk.text
255
  yield chunk.text
256
  success = True
257
  break
@@ -262,7 +263,21 @@ def ask_ai_stream_delta(message: str, history: List, hybrid_retriever, cohort_ke
262
  if not success:
263
  yield "Đã xảy ra lỗi hệ thống hoặc quá tải. Vui lòng thử lại sau giây lát!"
264
  return
265
- is_refusal = "Xin lỗi, tôi là trợ lý" in generated_text or "không thể tư vấn" in generated_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  if context_docs and not is_refusal:
267
  yield "\n\n---\n\n"
268
  yield "## 📚 Tài liệu tham khảo\n\n"
 
216
  prompt = create_advanced_prompt(question, context, question_type, topic_hint)
217
 
218
  logger.info("Đang tạo câu trả lời cuối cùng ...")
 
219
  success = False
220
+ generated_text = ""
221
+
222
  for _ in range(len(api_manager.groq_keys) if api_manager.groq_keys else 1):
223
  try:
224
  client = api_manager.get_groq_client()
 
252
  response = model.generate_content(prompt, stream=True)
253
  for chunk in response:
254
  if chunk.text:
255
+ generated_text += chunk.text
256
  yield chunk.text
257
  success = True
258
  break
 
263
  if not success:
264
  yield "Đã xảy ra lỗi hệ thống hoặc quá tải. Vui lòng thử lại sau giây lát!"
265
  return
266
+
267
+
268
+ text_lower = generated_text.lower()
269
+ is_refusal = any(phrase in text_lower for phrase in [
270
+ "xin lỗi, tôi là trợ lý",
271
+ "không thể tư vấn",
272
+ "không có thông tin",
273
+ "không tìm thấy thông tin",
274
+ "không có đủ thông tin",
275
+ "không đề cập trực tiếp",
276
+ "không có tài liệu nào",
277
+ "tài liệu tham khảo không",
278
+ "không có thông tin cụ thể",
279
+ "không đủ thông tin để trả lời"
280
+ ])
281
  if context_docs and not is_refusal:
282
  yield "\n\n---\n\n"
283
  yield "## 📚 Tài liệu tham khảo\n\n"