Update calendar_rag.py
Browse files- calendar_rag.py +16 -27
calendar_rag.py
CHANGED
|
@@ -517,28 +517,18 @@ class PipelineConfig:
|
|
| 517 |
)
|
| 518 |
|
| 519 |
def create_default_config(api_key: str) -> PipelineConfig:
|
| 520 |
-
"""Create default
|
| 521 |
-
model_config = ModelConfig(
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
cache_config = CacheConfig()
|
| 526 |
-
processing_config = ProcessingConfig()
|
| 527 |
-
monitoring_config = MonitoringConfig()
|
| 528 |
-
localization_config = LocalizationConfig()
|
| 529 |
-
|
| 530 |
-
# Return complete pipeline configuration
|
| 531 |
return PipelineConfig(
|
| 532 |
model=model_config,
|
| 533 |
-
retriever=
|
| 534 |
-
cache=
|
| 535 |
-
processing=
|
| 536 |
-
monitoring=
|
| 537 |
-
localization=
|
| 538 |
-
rate_limit_enabled=True,
|
| 539 |
-
requests_per_minute=60,
|
| 540 |
-
debug_mode=False,
|
| 541 |
-
development_mode=False
|
| 542 |
)
|
| 543 |
|
| 544 |
class CalendarDataProcessor:
|
|
@@ -603,9 +593,9 @@ class EnhancedDocumentStore:
|
|
| 603 |
|
| 604 |
def __init__(self, config: PipelineConfig):
|
| 605 |
self.store = InMemoryDocumentStore()
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
self.cache_manager = CacheManager(
|
| 610 |
cache_dir=config.cache.cache_dir,
|
| 611 |
ttl=config.cache.embeddings_cache_ttl
|
|
@@ -929,10 +919,9 @@ class ResponseGenerator:
|
|
| 929 |
return "ขออภัย ไม่สามารถประมวลผลคำตอบได้ในขณะนี้"
|
| 930 |
|
| 931 |
class AcademicCalendarRAG:
|
| 932 |
-
"""Main RAG pipeline
|
| 933 |
|
| 934 |
def __init__(self, config: PipelineConfig):
|
| 935 |
-
"""Initialize pipeline with configurations"""
|
| 936 |
self.config = config
|
| 937 |
self.document_store = EnhancedDocumentStore(config)
|
| 938 |
self.query_processor = AdvancedQueryProcessor(config)
|
|
@@ -978,7 +967,7 @@ class AcademicCalendarRAG:
|
|
| 978 |
"documents": [],
|
| 979 |
"query_info": {}
|
| 980 |
}
|
| 981 |
-
|
| 982 |
# def main():
|
| 983 |
# """Main function for processing real calendar queries"""
|
| 984 |
# try:
|
|
@@ -1003,7 +992,7 @@ class AcademicCalendarRAG:
|
|
| 1003 |
# pipeline.load_data(calendar_data)
|
| 1004 |
|
| 1005 |
# # Real queries to process
|
| 1006 |
-
# queries =
|
| 1007 |
|
| 1008 |
# print("Processing calendar queries...")
|
| 1009 |
# print("=" * 80)
|
|
|
|
| 517 |
)
|
| 518 |
|
| 519 |
def create_default_config(api_key: str) -> PipelineConfig:
|
| 520 |
+
"""Create a default configuration with the given API key"""
|
| 521 |
+
model_config = ModelConfig(
|
| 522 |
+
openai_api_key=api_key,
|
| 523 |
+
embedder_model="sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
|
| 524 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
return PipelineConfig(
|
| 526 |
model=model_config,
|
| 527 |
+
retriever=RetrieverConfig(),
|
| 528 |
+
cache=CacheConfig(),
|
| 529 |
+
processing=ProcessingConfig(),
|
| 530 |
+
monitoring=MonitoringConfig(),
|
| 531 |
+
localization=LocalizationConfig()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
)
|
| 533 |
|
| 534 |
class CalendarDataProcessor:
|
|
|
|
| 593 |
|
| 594 |
def __init__(self, config: PipelineConfig):
|
| 595 |
self.store = InMemoryDocumentStore()
|
| 596 |
+
self.embedder = SentenceTransformersDocumentEmbedder(
|
| 597 |
+
model=config.model.embedder_model
|
| 598 |
+
)
|
| 599 |
self.cache_manager = CacheManager(
|
| 600 |
cache_dir=config.cache.cache_dir,
|
| 601 |
ttl=config.cache.embeddings_cache_ttl
|
|
|
|
| 919 |
return "ขออภัย ไม่สามารถประมวลผลคำตอบได้ในขณะนี้"
|
| 920 |
|
| 921 |
class AcademicCalendarRAG:
|
| 922 |
+
"""Main RAG pipeline for academic calendar queries"""
|
| 923 |
|
| 924 |
def __init__(self, config: PipelineConfig):
|
|
|
|
| 925 |
self.config = config
|
| 926 |
self.document_store = EnhancedDocumentStore(config)
|
| 927 |
self.query_processor = AdvancedQueryProcessor(config)
|
|
|
|
| 967 |
"documents": [],
|
| 968 |
"query_info": {}
|
| 969 |
}
|
| 970 |
+
|
| 971 |
# def main():
|
| 972 |
# """Main function for processing real calendar queries"""
|
| 973 |
# try:
|
|
|
|
| 992 |
# pipeline.load_data(calendar_data)
|
| 993 |
|
| 994 |
# # Real queries to process
|
| 995 |
+
# queries = ["นิสิตที่เข้าศึกษาในภาคเรียนที่ 1 ปีการศึกษา 2567 สามารถถอนรายวิชาได้หรือไม่? เพราะเหตุใด?"]
|
| 996 |
|
| 997 |
# print("Processing calendar queries...")
|
| 998 |
# print("=" * 80)
|