Update calendar_rag.py
Browse files- calendar_rag.py +264 -42
calendar_rag.py
CHANGED
@@ -119,6 +119,52 @@ class TuitionFee:
|
|
119 |
regular_fee: RegularFee
|
120 |
late_payment_fee: LatePaymentFee
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
class OpenAIDateParser:
|
124 |
"""Uses OpenAI to parse complex Thai date formats"""
|
@@ -413,40 +459,7 @@ class CacheManager:
|
|
413 |
"""Cache document"""
|
414 |
self.document_cache[doc_id] = (document, datetime.now())
|
415 |
self._save_cache("documents", self.document_cache)
|
416 |
-
|
417 |
-
@dataclass
|
418 |
-
class ModelConfig:
|
419 |
-
openai_api_key: str
|
420 |
-
embedder_model: str = "sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
|
421 |
-
openai_model: str = "gpt-4o"
|
422 |
-
temperature: float = 0.7
|
423 |
-
|
424 |
-
@dataclass
|
425 |
-
class RetrieverConfig:
|
426 |
-
top_k: int = 5
|
427 |
-
|
428 |
-
@dataclass
|
429 |
-
class CacheConfig:
|
430 |
-
enabled: bool = True
|
431 |
-
cache_dir: Path = Path("./cache")
|
432 |
-
ttl: int = 86400 # 24 hours
|
433 |
-
|
434 |
-
@dataclass
|
435 |
-
class ProcessingConfig:
|
436 |
-
batch_size: int = 32
|
437 |
-
|
438 |
-
@dataclass
|
439 |
-
class LocalizationConfig:
|
440 |
-
enable_thai_normalization: bool = True
|
441 |
-
|
442 |
-
@dataclass
|
443 |
-
class PipelineConfig:
|
444 |
-
model: ModelConfig
|
445 |
-
retriever: RetrieverConfig = field(default_factory=RetrieverConfig)
|
446 |
-
cache: CacheConfig = field(default_factory=CacheConfig)
|
447 |
-
processing: ProcessingConfig = field(default_factory=ProcessingConfig)
|
448 |
-
localization: LocalizationConfig = field(default_factory=LocalizationConfig)
|
449 |
-
|
450 |
def create_default_config(api_key: str) -> PipelineConfig:
|
451 |
"""
|
452 |
Create a default pipeline configuration with optimized settings for Thai language processing.
|
@@ -823,6 +836,90 @@ class CalendarDataProcessor:
|
|
823 |
)
|
824 |
|
825 |
return [tuition_fee]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
826 |
|
827 |
class HybridDocumentStore:
|
828 |
"""Enhanced document store with hybrid retrieval capabilities"""
|
@@ -922,7 +1019,9 @@ class HybridDocumentStore:
|
|
922 |
course_structure: Optional[List[CourseStructure]] = None,
|
923 |
study_plans: Optional[List[StudyPlan]] = None,
|
924 |
program_details: Optional[List[ProgramDetailInfo]] = None,
|
925 |
-
tuition_fees: Optional[List[TuitionFee]] = None
|
|
|
|
|
926 |
"""Add events and additional data with caching"""
|
927 |
documents = []
|
928 |
added_events = set() # Track added events to prevent duplicates
|
@@ -1167,6 +1266,43 @@ class HybridDocumentStore:
|
|
1167 |
)
|
1168 |
documents.append(doc)
|
1169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1170 |
batch_size = 10
|
1171 |
for i in range(0, len(documents), batch_size):
|
1172 |
batch = documents[i:i + batch_size]
|
@@ -1211,9 +1347,6 @@ class HybridDocumentStore:
|
|
1211 |
query=query
|
1212 |
)["documents"]
|
1213 |
|
1214 |
-
if event_type == "program_details":
|
1215 |
-
weight_semantic = 0.3 # Give more weight to keyword matching
|
1216 |
-
|
1217 |
# Combine results using score fusion
|
1218 |
combined_results = self._merge_results(
|
1219 |
semantic_results=semantic_results,
|
@@ -1438,6 +1571,8 @@ class AdvancedQueryProcessor:
|
|
1438 |
3. **โครงสร้างหลักสูตร (curriculum)**: รายละเอียดเกี่ยวกับวิชาเรียน หน่วยกิต และแผนการศึกษา
|
1439 |
4. **ค่าเล่าเรียน (fees)**: ข้อมูลเกี่ยวกับค่าใช้จ่ายในการศึกษา ค่าธรรมเนียม และทุนการศึกษา
|
1440 |
5. **แผนการศึกษารายปี (study_plan)**: ข้อมูลแผนการเรียนแบ่งตามชั้นปีและภาคการศึกษา รายละเอียดรายวิชาที่ต้องลงทะเบียนในแต่ละเทอม และจำนวนหน่วยกิตรวม
|
|
|
|
|
1441 |
|
1442 |
**คำถาม**: {{query}}
|
1443 |
|
@@ -1513,6 +1648,16 @@ class AdvancedQueryProcessor:
|
|
1513 |
"response_format": "detailed",
|
1514 |
"uncertainty": "low"
|
1515 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1516 |
|
1517 |
กรุณาตอบเป็นภาษาไทยและตรวจสอบให้แน่ใจว่า JSON มีโครงสร้างที่ถูกต้อง
|
1518 |
"""
|
@@ -1590,6 +1735,10 @@ class AdvancedQueryProcessor:
|
|
1590 |
analysis['event_type'] = 'fees'
|
1591 |
elif any(keyword in query.lower() for keyword in ['หน่วยกิต', 'วิชา', 'หลักสูตร', 'แผนการเรียน', 'วิชาเลือก', 'วิชาบังคับ', 'วิชาหลัก', 'หมวดวิชา']):
|
1592 |
analysis['event_type'] = 'curriculum'
|
|
|
|
|
|
|
|
|
1593 |
return {
|
1594 |
"original_query": query,
|
1595 |
**analysis
|
@@ -1622,6 +1771,7 @@ class AcademicCalendarRAG:
|
|
1622 |
self.course_structure = []
|
1623 |
self.study_plans = []
|
1624 |
self.tuition_fees = []
|
|
|
1625 |
|
1626 |
def add_to_conversation(self, role: str, content: str):
|
1627 |
"""Add a message to the conversation history"""
|
@@ -1630,6 +1780,7 @@ class AcademicCalendarRAG:
|
|
1630 |
if len(self.conversation_history) > self.max_history_length * 2: # Each exchange is 2 messages
|
1631 |
self.conversation_history = self.conversation_history[-(self.max_history_length * 2):]
|
1632 |
|
|
|
1633 |
def load_data(self, json_data: Dict):
|
1634 |
"""Load and process all data sources"""
|
1635 |
try:
|
@@ -1645,6 +1796,7 @@ class AcademicCalendarRAG:
|
|
1645 |
self.course_structure = self.data_processor.extract_course_structure(json_data)
|
1646 |
self.study_plans = self.data_processor.extract_program_study_plan(json_data)
|
1647 |
self.tuition_fees = self.data_processor.extract_fees(json_data)
|
|
|
1648 |
|
1649 |
self.document_store.add_events(
|
1650 |
events=self.calendar_events,
|
@@ -1652,7 +1804,8 @@ class AcademicCalendarRAG:
|
|
1652 |
contact_details=self.contact_details,
|
1653 |
course_structure=self.course_structure,
|
1654 |
study_plans=self.study_plans,
|
1655 |
-
tuition_fees=self.tuition_fees
|
|
|
1656 |
)
|
1657 |
|
1658 |
except Exception as e:
|
@@ -1755,9 +1908,78 @@ class AcademicCalendarRAG:
|
|
1755 |
|
1756 |
# pipeline.load_data(raw_data)
|
1757 |
|
1758 |
-
# # Test queries with different semantic weights
|
1759 |
-
# queries = [
|
1760 |
-
# #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1761 |
# print("=" * 80)
|
1762 |
|
1763 |
# for query in queries:
|
|
|
119 |
regular_fee: RegularFee
|
120 |
late_payment_fee: LatePaymentFee
|
121 |
|
122 |
+
@dataclass
|
123 |
+
class ModelConfig:
|
124 |
+
openai_api_key: str
|
125 |
+
embedder_model: str = "sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
|
126 |
+
openai_model: str = "gpt-4o"
|
127 |
+
temperature: float = 0.7
|
128 |
+
|
129 |
+
@dataclass
|
130 |
+
class RetrieverConfig:
|
131 |
+
top_k: int = 5
|
132 |
+
|
133 |
+
@dataclass
|
134 |
+
class CacheConfig:
|
135 |
+
enabled: bool = True
|
136 |
+
cache_dir: Path = Path("./cache")
|
137 |
+
ttl: int = 86400 # 24 hours
|
138 |
+
|
139 |
+
@dataclass
|
140 |
+
class ProcessingConfig:
|
141 |
+
batch_size: int = 32
|
142 |
+
|
143 |
+
@dataclass
|
144 |
+
class LocalizationConfig:
|
145 |
+
enable_thai_normalization: bool = True
|
146 |
+
|
147 |
+
@dataclass
|
148 |
+
class PipelineConfig:
|
149 |
+
model: ModelConfig
|
150 |
+
retriever: RetrieverConfig = field(default_factory=RetrieverConfig)
|
151 |
+
cache: CacheConfig = field(default_factory=CacheConfig)
|
152 |
+
processing: ProcessingConfig = field(default_factory=ProcessingConfig)
|
153 |
+
localization: LocalizationConfig = field(default_factory=LocalizationConfig)
|
154 |
+
|
155 |
+
@dataclass
|
156 |
+
class Scholarship:
|
157 |
+
title: str
|
158 |
+
institution: str
|
159 |
+
semester: str
|
160 |
+
program_type: str
|
161 |
+
funding_details: str
|
162 |
+
eligibility_requirements: str
|
163 |
+
application_process: str
|
164 |
+
required_documents: str
|
165 |
+
selection_process: str
|
166 |
+
authority: str
|
167 |
+
event_type: str = 'scholarship'
|
168 |
|
169 |
class OpenAIDateParser:
|
170 |
"""Uses OpenAI to parse complex Thai date formats"""
|
|
|
459 |
"""Cache document"""
|
460 |
self.document_cache[doc_id] = (document, datetime.now())
|
461 |
self._save_cache("documents", self.document_cache)
|
462 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
463 |
def create_default_config(api_key: str) -> PipelineConfig:
|
464 |
"""
|
465 |
Create a default pipeline configuration with optimized settings for Thai language processing.
|
|
|
836 |
)
|
837 |
|
838 |
return [tuition_fee]
|
839 |
+
|
840 |
+
@staticmethod
|
841 |
+
def extract_scholarships(json_data: Dict) -> List[Scholarship]:
|
842 |
+
"""Extract and structure scholarship information into Scholarship objects"""
|
843 |
+
scholarship_data = json_data.get('scholarship_details', {})
|
844 |
+
|
845 |
+
if not scholarship_data:
|
846 |
+
return []
|
847 |
+
|
848 |
+
# Extract program info
|
849 |
+
program_info = scholarship_data.get('program_info', {})
|
850 |
+
title = program_info.get('title', '')
|
851 |
+
institution = program_info.get('institution', '')
|
852 |
+
semester = program_info.get('semester', '')
|
853 |
+
program_type = program_info.get('program_type', '')
|
854 |
+
|
855 |
+
# Extract and format funding details
|
856 |
+
funding_data = scholarship_data.get('funding_details', {})
|
857 |
+
funding_details = f"""จำนวนทุน: {funding_data.get('number_of_scholarships', 'ไม่ระบุ')}
|
858 |
+
จำนวนเงิน: {funding_data.get('amount_per_scholarship', 'ไม่ระบุ')}
|
859 |
+
ระยะเวลา: {funding_data.get('duration', 'ไม่ระบุ')}
|
860 |
+
จำนวนเงินรวม: {funding_data.get('total_amount', 'ไม่ระบุ')}"""
|
861 |
+
|
862 |
+
# Extract and format eligibility requirements
|
863 |
+
eligibility_data = scholarship_data.get('eligibility_requirements', {})
|
864 |
+
academic_req = eligibility_data.get('academic', {})
|
865 |
+
general_req = eligibility_data.get('general', {})
|
866 |
+
|
867 |
+
eligibility_requirements = f"""คุณสมบัติทางวิชาการ:
|
868 |
+
- ระดับการศึกษา: {academic_req.get('level', 'ไม่ระบุ')}
|
869 |
+
- สถานะการลงทะเบียน: {academic_req.get('enrollment_status', 'ไม่ระบุ')}
|
870 |
+
- ข้อกำหนดวิทยานิพนธ์: {academic_req.get('thesis_requirement', 'ไม่ระบุ')}
|
871 |
+
- ข้อกำหนด Manuscript: {academic_req.get('manuscript_requirement', 'ไม่ระบุ')}
|
872 |
+
- เกรดเฉลี่ยขั้นต่ำ: {academic_req.get('minimum_gpa', 'ไม่ระบุ')}
|
873 |
+
|
874 |
+
คุณสมบัติทั่วไป:
|
875 |
+
- สถานะการลงทะเบียน: {general_req.get('enrollment_status', 'ไม่ระบุ')}
|
876 |
+
- ความประพฤติ: {general_req.get('conduct', 'ไม่ระบุ')}"""
|
877 |
+
|
878 |
+
# Extract and format application process
|
879 |
+
app_process_data = scholarship_data.get('application_process', {})
|
880 |
+
application_process = f"""กำหนดส่ง: {app_process_data.get('deadline', 'ไม่ระบุ')}
|
881 |
+
วิธีการส่ง: {app_process_data.get('submission_method', 'ไม่ระบุ')}"""
|
882 |
+
|
883 |
+
# Extract and format required documents
|
884 |
+
docs_data = scholarship_data.get('required_documents', {})
|
885 |
+
mandatory_docs = docs_data.get('mandatory', [])
|
886 |
+
submission_format = docs_data.get('submission_format', '')
|
887 |
+
|
888 |
+
required_documents = f"""เอกสารที่ต้องใช้:
|
889 |
+
{chr(10).join(f'- {doc}' for doc in mandatory_docs)}
|
890 |
+
|
891 |
+
รูปแบบการส่ง: {submission_format}"""
|
892 |
+
|
893 |
+
# Extract and format selection process
|
894 |
+
selection_data = scholarship_data.get('selection_process', {})
|
895 |
+
selection_process = f"""วิธีการคัดเลือก: {selection_data.get('method', 'ไม่ระบุ')}
|
896 |
+
วันสัมภาษณ์: {selection_data.get('interview_date', 'ไม่ระบุ')}
|
897 |
+
เวลาสัมภาษณ์: {selection_data.get('interview_time', 'ไม่ระบุ')}
|
898 |
+
สถานที่: {selection_data.get('location', 'ไม่ระบุ')}
|
899 |
+
ประกาศผล: {selection_data.get('result_announcement', 'ไม่ระบุ')}"""
|
900 |
+
|
901 |
+
# Extract and format authority
|
902 |
+
authority_data = scholarship_data.get('authority', {})
|
903 |
+
authority = f"""ลงนามโดย: {authority_data.get('signed_by', 'ไม่ระบุ')}
|
904 |
+
ตำแหน่ง: {authority_data.get('position', 'ไม่ระบุ')}
|
905 |
+
วันที่: {authority_data.get('date', 'ไม่ระบุ')}"""
|
906 |
+
|
907 |
+
# Create Scholarship object
|
908 |
+
scholarship = Scholarship(
|
909 |
+
title=title,
|
910 |
+
institution=institution,
|
911 |
+
semester=semester,
|
912 |
+
program_type=program_type,
|
913 |
+
funding_details=funding_details,
|
914 |
+
eligibility_requirements=eligibility_requirements,
|
915 |
+
application_process=application_process,
|
916 |
+
required_documents=required_documents,
|
917 |
+
selection_process=selection_process,
|
918 |
+
authority=authority,
|
919 |
+
event_type='scholarship'
|
920 |
+
)
|
921 |
+
|
922 |
+
return [scholarship]
|
923 |
|
924 |
class HybridDocumentStore:
|
925 |
"""Enhanced document store with hybrid retrieval capabilities"""
|
|
|
1019 |
course_structure: Optional[List[CourseStructure]] = None,
|
1020 |
study_plans: Optional[List[StudyPlan]] = None,
|
1021 |
program_details: Optional[List[ProgramDetailInfo]] = None,
|
1022 |
+
tuition_fees: Optional[List[TuitionFee]] = None,
|
1023 |
+
scholarships: Optional[List[Scholarship]] = None):
|
1024 |
+
|
1025 |
"""Add events and additional data with caching"""
|
1026 |
documents = []
|
1027 |
added_events = set() # Track added events to prevent duplicates
|
|
|
1266 |
)
|
1267 |
documents.append(doc)
|
1268 |
|
1269 |
+
# Process scholarships
|
1270 |
+
if scholarships:
|
1271 |
+
for scholarship in scholarships:
|
1272 |
+
scholarship_text = f"""
|
1273 |
+
ทุนการศึกษา: {scholarship.title}
|
1274 |
+
|
1275 |
+
สถาบัน: {scholarship.institution}
|
1276 |
+
ภาคเรียน: {scholarship.semester}
|
1277 |
+
หลักสูตร: {scholarship.program_type}
|
1278 |
+
|
1279 |
+
รายละเอียดทุน:
|
1280 |
+
{scholarship.funding_details}
|
1281 |
+
|
1282 |
+
คุณสมบัติผู้สมัคร:
|
1283 |
+
{scholarship.eligibility_requirements}
|
1284 |
+
|
1285 |
+
กระบวนการสมัคร:
|
1286 |
+
{scholarship.application_process}
|
1287 |
+
|
1288 |
+
เอกสารที่ต้องใช้:
|
1289 |
+
{scholarship.required_documents}
|
1290 |
+
|
1291 |
+
กระบวนการคัดเลือก:
|
1292 |
+
{scholarship.selection_process}
|
1293 |
+
|
1294 |
+
หน่วยงานผู้รับผิดชอบ:
|
1295 |
+
{scholarship.authority}
|
1296 |
+
"""
|
1297 |
+
|
1298 |
+
doc = Document(
|
1299 |
+
id=self._generate_unique_id(),
|
1300 |
+
content=scholarship_text.strip(),
|
1301 |
+
embedding=self._compute_embedding(scholarship_text),
|
1302 |
+
meta={'event_type': 'scholarship'}
|
1303 |
+
)
|
1304 |
+
documents.append(doc)
|
1305 |
+
|
1306 |
batch_size = 10
|
1307 |
for i in range(0, len(documents), batch_size):
|
1308 |
batch = documents[i:i + batch_size]
|
|
|
1347 |
query=query
|
1348 |
)["documents"]
|
1349 |
|
|
|
|
|
|
|
1350 |
# Combine results using score fusion
|
1351 |
combined_results = self._merge_results(
|
1352 |
semantic_results=semantic_results,
|
|
|
1571 |
3. **โครงสร้างหลักสูตร (curriculum)**: รายละเอียดเกี่ยวกับวิชาเรียน หน่วยกิต และแผนการศึกษา
|
1572 |
4. **ค่าเล่าเรียน (fees)**: ข้อมูลเกี่ยวกับค่าใช้จ่ายในการศึกษา ค่าธรรมเนียม และทุนการศึกษา
|
1573 |
5. **แผนการศึกษารายปี (study_plan)**: ข้อมูลแผนการเรียนแบ่งตามชั้นปีและภาคการศึกษา รายละเอียดรายวิชาที่ต้องลงทะเบียนในแต่ละเทอม และจำนวนหน่วยกิตรวม
|
1574 |
+
6. **ทุนการศึกษา (scholarships)**: ข้อมูลเกี่ยวกับทุนการศึกษาที่มีให้สำหรับนักศึกษา รวมถึงคุณสมบัติและวิธีการสมัคร
|
1575 |
+
7. **อื่นๆ (other)**: คำถามที่ไม่เข้าหมวดหมู่ข้างต้น หรือมีความไม่แน่นอนสูงในการจำแนกประเภท
|
1576 |
|
1577 |
**คำถาม**: {{query}}
|
1578 |
|
|
|
1648 |
"response_format": "detailed",
|
1649 |
"uncertainty": "low"
|
1650 |
}
|
1651 |
+
|
1652 |
+
Input: "มีทุนการศึกษาอะไรบ้า"
|
1653 |
+
Output: {
|
1654 |
+
"event_type": "scholarships",
|
1655 |
+
"year": null,
|
1656 |
+
"semester": null,
|
1657 |
+
"key_terms": ["ช่วย", "ทุนการศึกษา", "ทุน"],
|
1658 |
+
"response_format": "detailed",
|
1659 |
+
"uncertainty": "low"
|
1660 |
+
}
|
1661 |
|
1662 |
กรุณาตอบเป็นภาษาไทยและตรวจสอบให้แน่ใจว่า JSON มีโครงสร้างที่ถูกต้อง
|
1663 |
"""
|
|
|
1735 |
analysis['event_type'] = 'fees'
|
1736 |
elif any(keyword in query.lower() for keyword in ['หน่วยกิต', 'วิชา', 'หลักสูตร', 'แผนการเรียน', 'วิชาเลือก', 'วิชาบังคับ', 'วิชาหลัก', 'หมวดวิชา']):
|
1737 |
analysis['event_type'] = 'curriculum'
|
1738 |
+
elif any(keyword in query.lower() for keyword in ['ทุนการศึกษา', 'ทุน', 'scholarship', 'financial', 'aid', 'funding']):
|
1739 |
+
analysis['event_type'] = 'scholarships'
|
1740 |
+
elif any(keyword in query.lower() for keyword in ['ติดต่อ', 'contact', 'สอบถาม', 'ข้อมูลการติดต่อ']):
|
1741 |
+
analysis['event_type'] = 'contact'
|
1742 |
return {
|
1743 |
"original_query": query,
|
1744 |
**analysis
|
|
|
1771 |
self.course_structure = []
|
1772 |
self.study_plans = []
|
1773 |
self.tuition_fees = []
|
1774 |
+
self.scholarships = []
|
1775 |
|
1776 |
def add_to_conversation(self, role: str, content: str):
|
1777 |
"""Add a message to the conversation history"""
|
|
|
1780 |
if len(self.conversation_history) > self.max_history_length * 2: # Each exchange is 2 messages
|
1781 |
self.conversation_history = self.conversation_history[-(self.max_history_length * 2):]
|
1782 |
|
1783 |
+
# Fixed load_data method (added missing comma)
|
1784 |
def load_data(self, json_data: Dict):
|
1785 |
"""Load and process all data sources"""
|
1786 |
try:
|
|
|
1796 |
self.course_structure = self.data_processor.extract_course_structure(json_data)
|
1797 |
self.study_plans = self.data_processor.extract_program_study_plan(json_data)
|
1798 |
self.tuition_fees = self.data_processor.extract_fees(json_data)
|
1799 |
+
self.scholarships = self.data_processor.extract_scholarships(json_data)
|
1800 |
|
1801 |
self.document_store.add_events(
|
1802 |
events=self.calendar_events,
|
|
|
1804 |
contact_details=self.contact_details,
|
1805 |
course_structure=self.course_structure,
|
1806 |
study_plans=self.study_plans,
|
1807 |
+
tuition_fees=self.tuition_fees,
|
1808 |
+
scholarships=self.scholarships
|
1809 |
)
|
1810 |
|
1811 |
except Exception as e:
|
|
|
1908 |
|
1909 |
# pipeline.load_data(raw_data)
|
1910 |
|
1911 |
+
# # # # Test queries with different semantic weights
|
1912 |
+
# # queries = [
|
1913 |
+
# # "วันเปิดเรียนภาคเรียนที่ 1 ปีการศึกษา 2567 คือวันที่เท่าไร?",
|
1914 |
+
# # ]
|
1915 |
+
# queries = [
|
1916 |
+
# "มีทุนกรศึกษาอะไรบ้าง ทั้งหมด",
|
1917 |
+
# # "ภาคเรียนที่ 1/2567 เปิดเรียนวันไหน?",
|
1918 |
+
# # "วันสุดท้ายของการลงทะเบียนเรียนและชำระเงินค่าธรรมเนียม ภาค 1/2567 คือวันไหน?",
|
1919 |
+
# # "กำหนดการสอบปากเปล่าปริญญานิพนธ์ ภาค 1/2567 คือช่วงไหน?",
|
1920 |
+
# # "วันสุดท้ายของการขอถอนรายวิชาเรียน ภาค 1/2567 คือวันไหน?",
|
1921 |
+
# # "วันหยุดชดเชยวันอาสาฬบูชาคือวันไหน?",
|
1922 |
+
# # "วันสุดท้ายที่อาจารย์ต้องส่งผลการสอบ ภาค 1/2567 คือวันไหน?",
|
1923 |
+
# # "กำหนดการยื่นขอแต่งตั้งอาจารย์ที่ปรึกษา (บว.410) ภาคปลายคือวันไหน?",
|
1924 |
+
# # "วันสุดท้ายของการสอบเค้าโครงปริญญานิพนธ์ ภาค 2/2567 คือวันไหน?",
|
1925 |
+
# # "วันหยุดเนื่องในวันปิยมหาราชคือวันไหน?",
|
1926 |
+
# # "วันสุดท้ายของการยื่นแบบขอแต่งตั้งกรรมการสอบปากเปล่าฯ (บว.430) ภาคปลายคือวันไหน?",
|
1927 |
+
# # "นิสิตสามารถยื่นเอกสารขอขยายเวลาการศึกษาได้ถึงวันไหน?",
|
1928 |
+
# # "วันสุดท้ายของการให้บริการคลินิก i-Thesis ภาค 1/2567 คือวันไหน?",
|
1929 |
+
# # "กำหนดการวันสุดท้ายของการสอบวัดคุณสมบัติระดับปริญญาเอก ภาค 2/2567 คือวันไหน?",
|
1930 |
+
# # "วันสิ้นสุดการศึกษา ภาคเรียนที่ 1 ปีการศึกษา 2567 คือวันไหน?",
|
1931 |
+
# # "วันสุดท้ายที่นิสิตประเมิน ปค.003 และ ปค.004 ภาค 2/2567 คือวันไหน?",
|
1932 |
+
# # "วันสุดท้ายที่คณะต้องส่งผลการแก้สัญลักษณ์ I ภาค 1/2567 คือวันไหน?",
|
1933 |
+
# # "กำหนดการยื่นแบบขอแต่งตั้งกรรมการสอบเค้าโครงฯ ปริญญานิพนธ์ ภาคต้นคือวันไหน?",
|
1934 |
+
# # "วันสุดท้ายของการส่งบทความวิจัยที่ตีพิมพ์ของนิสิตที่ประสงค์จะสำเร็จการศึกษา ภาค 2/2567 คือวันไหน?",
|
1935 |
+
# # "ปฐมนิเทศนิสิตใหม่ระดับบัณฑิตศึกษา ภาคปลาย จัดขึ้นวันไหน?",
|
1936 |
+
# # "วันหยุดเนื่องในวันพ่อแห่งชาติคือวันไหน?",
|
1937 |
+
|
1938 |
+
# # "หลักสูตร MSDS ปี 2567 เปิดรับผู้สำเร็จการศึกษาระดับปริญญาตรีสาข���ใด?",
|
1939 |
+
# # "ช่องทางการสมัครหลักสูตร MSDS คือช่องทางไหน?",
|
1940 |
+
# # "อีเมลสำหรับติดต่อสอบถามข้อมูลเกี่ยวกับหลักสูตร MSDS คืออีเมลอะไร?",
|
1941 |
+
# # "ผู้สมัครหลักสูตร MSDS ต้องมีผลคะแนน TOEFL iBT เท่าไหร่จึงจะได้รับการยกเว้นไม่ต้องสอบวิชาภาษาอังกฤษ?",
|
1942 |
+
# # "เอกสารใดบ้างที่ผู้สมัครหลักสูตร MSDS ต้องยื่น?",
|
1943 |
+
# # "ผู้สมัครหลักสูตร MSDS ที่มีผลสอบ SWU-SET ระดับใด จึงจะได้รับการยกเว้นไม่ต้องสอบวิชาภาษาอังกฤษทั่วไป?",
|
1944 |
+
# # "ขั้นตอนการคัดเลือกผู้เข้าศึกษาหลักสูตร MSDS มีอะไรบ้าง?",
|
1945 |
+
# # "ผู้สมัครหลักสูตร MSDS ต้องยื่นเอกสารในรูปแบบไฟล์ใด?",
|
1946 |
+
# # "หากชื่อในเอกสารของผู้สมัครหลักสูตร MSDS ไม่ตรงกัน ต้องยื่นเอกสารอะไรเพิ่มเติม?",
|
1947 |
+
# # "ผู้สมัครชาวไทยที่จบการศึกษาปริญญาโทจากต่างประเทศที่ใช้ภาษาอังกฤษในการเรียนการสอน ต้องยื่นผลคะแนนภาษาอังกฤษหรือไม่?",
|
1948 |
+
|
1949 |
+
# # "ภาควิชาวิทยาการคอมพิวเตอร์ คณะวิทยาศาสตร์ มหาวิทยาลัยศรีนครินทรวิโรฒ ประสานมิตร ตั้งอยู่ที่อาคารใด?",
|
1950 |
+
# # "หมายเลขโทรศัพท์สำหรับติดต่อภาควิชาวิทยาการคอมพิวเตอร์คือหมายเลขอะไร?",
|
1951 |
+
# # "หากต้องการเดินทางไปภาควิชาวิทยาการคอมพิวเตอร์ โดยใช้บริการเรือโดยสารคลองแสนแสบ ต้องลงที่ท่าเรือใด?",
|
1952 |
+
# # "Facebook Page ของหลักสูตร MSDS คือ Page ไหน?",
|
1953 |
+
# # "หากเดินทางโดย BTS ไปภาควิชาวิทยาการคอมพิวเตอร์ ควรลงสถานีใด?",
|
1954 |
+
|
1955 |
+
# # "หลักสูตร MSDS 2567 มีจำนวนหน่วยกิตรวมทั้งหมดกี่หน่วยกิต?",
|
1956 |
+
# # "วิชา DS501 คือวิชาอะไร?",
|
1957 |
+
# # "วิชา DS510 และ DS511 อยู่ในหมวดวิชาใด?",
|
1958 |
+
# # "วิชา GRI682 มีจำนวนกี่หน่วยกิต?",
|
1959 |
+
# # "วิชาบังคับของหลักสูตร MSDS 2567 มีจำนวนกี่หน่วยกิต?",
|
1960 |
+
# # "วิชา DS521 เกี่ยวข้องกับหัวข้อใด?",
|
1961 |
+
# # "วิชาพื้นฐานของหลักสูตร MSDS 2567 มีเกรดการประเมินผลเป็นอย่างไร?",
|
1962 |
+
# # "วิชา DS660 คือวิชาอะไร?",
|
1963 |
+
# # "วิชา GRI682 มีวิชาบังคับก่อนหน้าคือวิชาอะไร?",
|
1964 |
+
# # "นิสิตหลักสูตร MSDS 2567 ต้องเรียนวิชาเลือกอย่างน้อยกี่หน่วยกิต?",
|
1965 |
+
# # "วิชา DS502 คือวิชาอะไร?",
|
1966 |
+
# # "หลักสูตร MSDS 2567 มีชื่อเต็มภาษาอังกฤษว่าอะไร?",
|
1967 |
+
|
1968 |
+
# # "หลักสูตร MSDS 2567 แผน 2 แบบวิชาชีพ มีระยะเวลาเรียนกี่ปี?",
|
1969 |
+
# # "วิชา DS514 และ DS515 เรียนในปีที่เท่าไหร่ ภาคเรียนที่เท่าไหร่?",
|
1970 |
+
# # "วิชา DS518 มีจำนวนกี่หน่วยกิต?",
|
1971 |
+
# # "วิชา DS610 และ DS611 เรียนเกี่ยวกับอะไร?",
|
1972 |
+
# # "ในปีที่ 2 ภาคเรียนที่ 2 นิสิตต้องเรียนวิชาอะไรบ้าง?",
|
1973 |
+
# # "วิชา DS516 และ DS517 เรียนเกี่ยวกับอะไร?",
|
1974 |
+
# # "วิชา GRI682 เรียนในปีที่เท่าไ��ร่ ภาคเรียนที่เท่าไหร่?",
|
1975 |
+
# # "ในแต่ละภาคเรียนของปีที่ 1 นิสิตต้องเรียนวิชาหลักทั้งหมดกี่หน่วยกิต?",
|
1976 |
+
# # "วิชา DS510 มีจำนวนกี่หน่วยกิต?",
|
1977 |
+
# # "วิชา DS519 มีรูปแบบการเรียนเป็นแบบใด?",
|
1978 |
+
|
1979 |
+
# # "ค่าเล่าเรียนหลักสูตร MSDS 2567 ต่อภาคการศึกษาคือเท่าไหร่?",
|
1980 |
+
# # "หากชำระค่าเล่าเรียนล่าช้า จะมีค่าปรับเท่าไหร่?",
|
1981 |
+
# # "ค่าปรับชำระล่าช้า มีเงื่อนไขอย่างไร?",
|
1982 |
+
# ]
|
1983 |
# print("=" * 80)
|
1984 |
|
1985 |
# for query in queries:
|