fix: bypass academic guard for reminder-related questions

This commit is contained in:
Power BI Dev
2026-06-04 11:06:09 +07:00
parent 7acdd5347c
commit d0d3d1a95b
+8 -3
View File
@@ -14,6 +14,7 @@ from guard import is_academic_topic, REJECT_MESSAGE
_pending_confirmations: dict = {} _pending_confirmations: dict = {}
REMINDER_KEYWORDS = ["ingatkan", "pengingat", "remind", "jadwalkan", "tolong ingat"] REMINDER_KEYWORDS = ["ingatkan", "pengingat", "remind", "jadwalkan", "tolong ingat"]
REMINDER_BYPASS_KEYWORDS = ["ingatkan", "pengingat", "remind", "diingatkan", "jadwalkan", "kapan diingat"]
_client = AsyncOpenAI(api_key=DEEPSEEK_API_KEY, base_url=DEEPSEEK_BASE_URL) _client = AsyncOpenAI(api_key=DEEPSEEK_API_KEY, base_url=DEEPSEEK_BASE_URL)
@@ -316,6 +317,8 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
# Deteksi intent reminder dari plain text # Deteksi intent reminder dari plain text
text_lower = text.lower() text_lower = text.lower()
is_reminder_related = any(kw in text_lower for kw in REMINDER_BYPASS_KEYWORDS)
if any(kw in text_lower for kw in REMINDER_KEYWORDS): if any(kw in text_lower for kw in REMINDER_KEYWORDS):
await update.message.chat.send_action("typing") await update.message.chat.send_action("typing")
parsed = await reminder_module.parse_reminder_intent(text, _client, DEEPSEEK_MODEL) parsed = await reminder_module.parse_reminder_intent(text, _client, DEEPSEEK_MODEL)
@@ -327,9 +330,11 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
question = text question = text
await update.message.chat.send_action("typing") await update.message.chat.send_action("typing")
if not await is_academic_topic(question, _client, DEEPSEEK_MODEL): # Skip guard untuk pertanyaan tentang fitur bot sendiri
await update.message.reply_text(REJECT_MESSAGE) if not is_reminder_related:
return if not await is_academic_topic(question, _client, DEEPSEEK_MODEL):
await update.message.reply_text(REJECT_MESSAGE)
return
relevant = await rag.search(user_data["id"], question, n_results=5) relevant = await rag.search(user_data["id"], question, n_results=5)
context_text = "" context_text = ""