Update calendar_rag.py
Browse files- calendar_rag.py +16 -3
calendar_rag.py
CHANGED
@@ -1279,7 +1279,7 @@ class HybridDocumentStore:
|
|
1279 |
return sorted_docs[:top_k]
|
1280 |
|
1281 |
class ResponseGenerator:
|
1282 |
-
"""Generate responses with conversation context awareness"""
|
1283 |
|
1284 |
def __init__(self, config: PipelineConfig):
|
1285 |
self.generator = OpenAIGenerator(
|
@@ -1319,9 +1319,11 @@ class ResponseGenerator:
|
|
1319 |
5. สำหรับคำถามเกี่ยวกับข้อกำหนดภาษาอังกฤษหรือขั้นตอนการสมัคร ให้อธิบายข้อมูลอย่างละเอียด
|
1320 |
6. ใส่ข้อความ "หากมีข้อสงสัยเพิ่มเติม สามารถสอบถามได้" ท้ายคำตอบเสมอ
|
1321 |
7. คำนึงถึงประวัติการสนทนาและให้คำตอบที่ต่อเนื่องกับบทสนทนาก่อนหน้า
|
1322 |
-
8. หากคำถามอ้างอิงถึงข้อมูลในบทสนทนาก่อนหน้า (เช่น "แล้วอันนั้นล่ะ", "มีอะไรอีกบ้าง") ให้พิจารณาบริบทและตอบคำถามอย่างตรงประเด็น
|
1323 |
9. กรณีคำถามมีความไม่ชัดเจน ใช้ประวัติการสนทนาเพื่อเข้าใจบริบทของคำถาม
|
1324 |
|
|
|
|
|
1325 |
กรุณาตอบเป็นภาษาไทย:
|
1326 |
"""
|
1327 |
)
|
@@ -1333,12 +1335,23 @@ class ResponseGenerator:
|
|
1333 |
conversation_history: List[Dict[str, str]] = None) -> str:
|
1334 |
"""Generate response using retrieved documents and conversation history"""
|
1335 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1336 |
result = self.prompt_builder.run(
|
1337 |
query=query,
|
1338 |
context=documents,
|
1339 |
format=query_info.get("response_format", "detailed"),
|
1340 |
-
conversation_history=
|
|
|
1341 |
)
|
|
|
1342 |
response = self.generator.run(prompt=result["prompt"])
|
1343 |
return response["replies"][0]
|
1344 |
|
|
|
1279 |
return sorted_docs[:top_k]
|
1280 |
|
1281 |
class ResponseGenerator:
|
1282 |
+
"""Generate responses with enhanced conversation context awareness"""
|
1283 |
|
1284 |
def __init__(self, config: PipelineConfig):
|
1285 |
self.generator = OpenAIGenerator(
|
|
|
1319 |
5. สำหรับคำถามเกี่ยวกับข้อกำหนดภาษาอังกฤษหรือขั้นตอนการสมัคร ให้อธิบายข้อมูลอย่างละเอียด
|
1320 |
6. ใส่ข้อความ "หากมีข้อสงสัยเพิ่มเติม สามารถสอบถามได้" ท้ายคำตอบเสมอ
|
1321 |
7. คำนึงถึงประวัติการสนทนาและให้คำตอบที่ต่อเนื่องกับบทสนทนาก่อนหน้า
|
1322 |
+
8. หากคำถามอ้างอิงถึงข้อมูลในบทสนทนาก่อนหน้า (เช่น "แล้วอันนั้นล่ะ", "มีอะไรอีกบ้าง", "คำถามก่อนหน้า") ให้พิจารณาบริบทและตอบคำถามอย่างตรงประเด็น
|
1323 |
9. กรณีคำถามมีความไม่ชัดเจน ใช้ประวัติการสนทนาเพื่อเข้าใจบริบทของคำถาม
|
1324 |
|
1325 |
+
สิ่งสำคัญพิเศษ: หากคำถามอ้างอิงถึงคำถามก่อนหน้า ให้แสดงคำถามก่อนหน้านั้นในคำตอบด้วย เช่น "คำถามก่อนหน้าคือ [คำถามก่อนหน้า] และคำตอบคือ..."
|
1326 |
+
|
1327 |
กรุณาตอบเป็นภาษาไทย:
|
1328 |
"""
|
1329 |
)
|
|
|
1335 |
conversation_history: List[Dict[str, str]] = None) -> str:
|
1336 |
"""Generate response using retrieved documents and conversation history"""
|
1337 |
try:
|
1338 |
+
# Enhanced handling of reference questions
|
1339 |
+
reference_keywords = ["ก่อนหน้านี้", "ก่อนหน้า", "ที่ผ่านมา", "คำถามก่อนหน้า", "คำถามที่แล้ว",
|
1340 |
+
"previous", "earlier", "before", "last time", "last question"]
|
1341 |
+
|
1342 |
+
is_reference_question = any(keyword in query.lower() for keyword in reference_keywords)
|
1343 |
+
|
1344 |
+
# For reference questions, we'll add additional prompting
|
1345 |
+
enhanced_context = conversation_history or []
|
1346 |
+
|
1347 |
result = self.prompt_builder.run(
|
1348 |
query=query,
|
1349 |
context=documents,
|
1350 |
format=query_info.get("response_format", "detailed"),
|
1351 |
+
conversation_history=enhanced_context,
|
1352 |
+
is_reference_question=is_reference_question
|
1353 |
)
|
1354 |
+
|
1355 |
response = self.generator.run(prompt=result["prompt"])
|
1356 |
return response["replies"][0]
|
1357 |
|