minh-4T commited on
Commit
b984c99
·
1 Parent(s): cda3410

update analyze

Browse files
Files changed (1) hide show
  1. rag/analyze_and_expand.py +24 -0
rag/analyze_and_expand.py CHANGED
@@ -112,7 +112,31 @@ def analyze_and_expand_query(question: str) -> Dict[str, Any]:
112
  except json.JSONDecodeError:
113
  fixed_str = cleaned_json.replace("'", '"').replace("None", "null").replace("True", "true").replace("False", "false")
114
  result = json.loads(fixed_str)
 
 
 
 
 
 
 
 
 
 
 
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  # Logic an toàn: Nếu AI lỡ trả lời câu hỏi chuyên môn trong field "answer", ta xóa nó đi để ép hệ thống tìm docs
117
  q_type = result.get("question_type", "simple")
118
  ans = result.get("answer", None)
 
112
  except json.JSONDecodeError:
113
  fixed_str = cleaned_json.replace("'", '"').replace("None", "null").replace("True", "true").replace("False", "false")
114
  result = json.loads(fixed_str)
115
+ other_schools = [
116
+ "bách khoa", "bach khoa", "hust",
117
+ "neu", "kinh tế",
118
+ "ngoại thương", "ftu",
119
+ "sư phạm", "hpu",
120
+ "nông lâm",
121
+ "công nghệ", "uit",
122
+ "huflit", "rmit", "fpt", "văn hiến", "mở"
123
+ ]
124
+
125
+ has_other_school = any(school in question_lower for school in other_schools)
126
 
127
+ if has_other_school:
128
+ logger.info(f"⚠️ DETECTED trường khác trong câu hỏi! Force → outlier")
129
+ q_type = "outlier"
130
+ ans = "Xin lỗi, tôi là trợ lý AI chuyên trách của Trường Đại học Thủy Lợi. Tôi chỉ hỗ trợ giải đáp các quy chế và thông tin liên quan đến sinh viên Thủy Lợi."
131
+ queries = []
132
+
133
+ final_result = {
134
+ "question_type": q_type,
135
+ "answer": ans,
136
+ "expanded_queries": queries
137
+ }
138
+ print(f"✓ Phân loại: {final_result['question_type']} (Safety Check)")
139
+ return final_result
140
  # Logic an toàn: Nếu AI lỡ trả lời câu hỏi chuyên môn trong field "answer", ta xóa nó đi để ép hệ thống tìm docs
141
  q_type = result.get("question_type", "simple")
142
  ans = result.get("answer", None)