JirasakJo commited on
Commit
e8c1215
·
verified ·
1 Parent(s): 725eaa7

Update calendar_rag.py

Browse files
Files changed (1) hide show
  1. calendar_rag.py +40 -5
calendar_rag.py CHANGED
@@ -914,7 +914,7 @@ class HybridDocumentStore:
914
 
915
  def _format_selection_steps(self, steps: List[SelectionStep]) -> str:
916
  """Format selection process steps"""
917
- return "\n".join("{0}. {1}".format(step.step_number, step.description) for step in steps)
918
 
919
  def add_events(self,
920
  events: List[CalendarEvent],
@@ -1014,7 +1014,7 @@ class HybridDocumentStore:
1014
  for c in course.structure['หมวดวิชาปรับพื้นฐาน'].courses:
1015
  foundation_courses.append(f"- {c.code}: {c.title_th} ({c.title_en}) - {c.credits} หน่วยกิต")
1016
  text += "\n".join(foundation_courses)
1017
-
1018
  text += f"""
1019
 
1020
  หมวดวิชาบังคับ/วิชาหลัก:
@@ -1026,7 +1026,7 @@ class HybridDocumentStore:
1026
  for c in course.structure['หมวดวิชาบังคับ'].courses:
1027
  core_courses.append(f"- {c.code}: {c.title_th} ({c.title_en}) - {c.credits} หน่วยกิต")
1028
  text += "\n".join(core_courses)
1029
-
1030
  text += f"""
1031
 
1032
  หมวดวิชาเลือก:
@@ -1038,7 +1038,7 @@ class HybridDocumentStore:
1038
  for c in course.structure['หมวดวิชาเลือก'].courses:
1039
  elective_courses.append(f"- {c.code}: {c.title_th} ({c.title_en}) - {c.credits} หน่วยกิต")
1040
  text += "\n".join(elective_courses)
1041
-
1042
  text += f"""
1043
 
1044
  หมวดวิชาการค้นคว้าอิสระ:
@@ -1610,4 +1610,39 @@ class AcademicCalendarRAG:
1610
  "query": query,
1611
  "answer": "ขออภัย ไม่สามารถประมวลผลคำตอบได้ในขณะนี้",
1612
  "error": "Maximum retry attempts reached"
1613
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
914
 
915
  def _format_selection_steps(self, steps: List[SelectionStep]) -> str:
916
  """Format selection process steps"""
917
+ return "\n".join(f"{step.step_number}. {step.description}" for step in steps)
918
 
919
  def add_events(self,
920
  events: List[CalendarEvent],
 
1014
  for c in course.structure['หมวดวิชาปรับพื้นฐาน'].courses:
1015
  foundation_courses.append(f"- {c.code}: {c.title_th} ({c.title_en}) - {c.credits} หน่วยกิต")
1016
  text += "\n".join(foundation_courses)
1017
+
1018
  text += f"""
1019
 
1020
  หมวดวิชาบังคับ/วิชาหลัก:
 
1026
  for c in course.structure['หมวดวิชาบังคับ'].courses:
1027
  core_courses.append(f"- {c.code}: {c.title_th} ({c.title_en}) - {c.credits} หน่วยกิต")
1028
  text += "\n".join(core_courses)
1029
+
1030
  text += f"""
1031
 
1032
  หมวดวิชาเลือก:
 
1038
  for c in course.structure['หมวดวิชาเลือก'].courses:
1039
  elective_courses.append(f"- {c.code}: {c.title_th} ({c.title_en}) - {c.credits} หน่วยกิต")
1040
  text += "\n".join(elective_courses)
1041
+
1042
  text += f"""
1043
 
1044
  หมวดวิชาการค้นคว้าอิสระ:
 
1610
  "query": query,
1611
  "answer": "ขออภัย ไม่สามารถประมวลผลคำตอบได้ในขณะนี้",
1612
  "error": "Maximum retry attempts reached"
1613
+ }
1614
+
1615
+ # def main():
1616
+ # """Main function demonstrating hybrid retrieval"""
1617
+ # try:
1618
+ # # Load API key
1619
+ # with open("key.txt", "r") as f:
1620
+ # openai_api_key = f.read().strip()
1621
+
1622
+ # # Create config with hybrid retrieval settings
1623
+ # config = create_default_config(openai_api_key)
1624
+ # pipeline = AcademicCalendarRAG(config)
1625
+
1626
+ # # Load and process data
1627
+ # with open("raw-data.json", "r", encoding="utf-8") as f:
1628
+ # raw_data = json.load(f)
1629
+
1630
+ # pipeline.load_data(raw_data)
1631
+
1632
+ # # Test queries with different semantic weights
1633
+ # queries = ["ค่าเทอมเท่าไหร่","เปิดเรียนวันไหน","ขั้นตอนการสมัครที่สาขานี้มีอะไรบ้าง","ต้องใช้ระดับภาษาอังกฤษเท่าไหร่ในการสมัครเรียนที่นี้","ถ้าจะไปติดต่อมาหลายต้องลง mrt อะไร","มีวิชาหลักเเละวิชาเลือกออะไรบ้าง", "ปีที่ 1 เทอม 1 ต้องเรียนอะไรบ้าง", "ปีที่ 2 เทอม 1 ต้องเรียนอะไรบ้าง"]
1634
+ # # queries = ["สอบปลายภาควันไหน"]
1635
+ # print("=" * 80)
1636
+
1637
+ # for query in queries:
1638
+ # print(f"\nQuery: {query}")
1639
+ # result = pipeline.process_query(query)
1640
+ # print(f"Answer: {result['answer']}")
1641
+ # print("-" * 40)
1642
+
1643
+ # except Exception as e:
1644
+ # logger.error(f"Pipeline execution failed: {str(e)}")
1645
+ # raise
1646
+
1647
+ # if __name__ == "__main__":
1648
+ # main()