Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -333,8 +333,8 @@ def format_references(
|
|
| 333 |
|
| 334 |
def is_academic_query(message: str) -> bool:
|
| 335 |
"""
|
| 336 |
-
|
| 337 |
-
目的:避免像
|
| 338 |
"""
|
| 339 |
if not message:
|
| 340 |
return False
|
|
@@ -343,7 +343,10 @@ def is_academic_query(message: str) -> bool:
|
|
| 343 |
if not m:
|
| 344 |
return False
|
| 345 |
|
| 346 |
-
#
|
|
|
|
|
|
|
|
|
|
| 347 |
smalltalk_tokens = {
|
| 348 |
"hi", "hello", "hey", "yo",
|
| 349 |
"thanks", "thank", "thank you",
|
|
@@ -351,14 +354,33 @@ def is_academic_query(message: str) -> bool:
|
|
| 351 |
"bye", "goodbye", "see you",
|
| 352 |
"haha", "lol"
|
| 353 |
}
|
| 354 |
-
|
| 355 |
tokens = m.split()
|
| 356 |
|
| 357 |
# 如果全是闲聊词而且没有问号 → 视为非学术问题
|
| 358 |
if "?" not in m and all(t in smalltalk_tokens for t in tokens):
|
| 359 |
return False
|
| 360 |
|
| 361 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
if len(tokens) <= 2 and "?" not in m:
|
| 363 |
return False
|
| 364 |
|
|
@@ -369,9 +391,6 @@ def is_academic_query(message: str) -> bool:
|
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
# ================== Gradio App ==================
|
| 376 |
with gr.Blocks(
|
| 377 |
title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
|
|
|
|
| 333 |
|
| 334 |
def is_academic_query(message: str) -> bool:
|
| 335 |
"""
|
| 336 |
+
判断当前学生输入是否是“学术/课程相关”问题。
|
| 337 |
+
目的:避免像 hi、thanks、who are you 这类寒暄或自我介绍请求也触发 RAG 和 reference。
|
| 338 |
"""
|
| 339 |
if not message:
|
| 340 |
return False
|
|
|
|
| 343 |
if not m:
|
| 344 |
return False
|
| 345 |
|
| 346 |
+
# 归一化一下空格
|
| 347 |
+
m = " ".join(m.split())
|
| 348 |
+
|
| 349 |
+
# 1) 典型闲聊词
|
| 350 |
smalltalk_tokens = {
|
| 351 |
"hi", "hello", "hey", "yo",
|
| 352 |
"thanks", "thank", "thank you",
|
|
|
|
| 354 |
"bye", "goodbye", "see you",
|
| 355 |
"haha", "lol"
|
| 356 |
}
|
|
|
|
| 357 |
tokens = m.split()
|
| 358 |
|
| 359 |
# 如果全是闲聊词而且没有问号 → 视为非学术问题
|
| 360 |
if "?" not in m and all(t in smalltalk_tokens for t in tokens):
|
| 361 |
return False
|
| 362 |
|
| 363 |
+
# 2) 典型「自我介绍 / 工具说明」类问题,也视为非学术问题
|
| 364 |
+
meta_phrases = [
|
| 365 |
+
"who are you",
|
| 366 |
+
"what are you",
|
| 367 |
+
"what is your name",
|
| 368 |
+
"introduce yourself",
|
| 369 |
+
"tell me about yourself",
|
| 370 |
+
"what can you do",
|
| 371 |
+
"how can you help",
|
| 372 |
+
"how do you help",
|
| 373 |
+
"how do i use",
|
| 374 |
+
"how to use this",
|
| 375 |
+
"what is this app",
|
| 376 |
+
"what is this tool",
|
| 377 |
+
"what is clare",
|
| 378 |
+
"who is clare"
|
| 379 |
+
]
|
| 380 |
+
if any(p in m for p in meta_phrases):
|
| 381 |
+
return False
|
| 382 |
+
|
| 383 |
+
# 3) 很短、又没有问号的输入,大概率也不是严肃学术问题
|
| 384 |
if len(tokens) <= 2 and "?" not in m:
|
| 385 |
return False
|
| 386 |
|
|
|
|
| 391 |
|
| 392 |
|
| 393 |
|
|
|
|
|
|
|
|
|
|
| 394 |
# ================== Gradio App ==================
|
| 395 |
with gr.Blocks(
|
| 396 |
title="Clare – Hanbridge AI Teaching Assistant", css=CUSTOM_CSS
|