Spaces:
Running
Running
Upload 16 files
Browse files- core/callbacks.py +3 -4
core/callbacks.py
CHANGED
|
@@ -6,7 +6,6 @@ from datetime import datetime
|
|
| 6 |
import pytz
|
| 7 |
import difflib
|
| 8 |
|
| 9 |
-
# --- ✨ 1. 匯入所有外部服務的函式 ---
|
| 10 |
from services import cwa_service, news_service, pws_service, usgs_service
|
| 11 |
from core.visits import get_current_visit_count
|
| 12 |
from core.notifications import send_line_notification_in_background
|
|
@@ -53,14 +52,15 @@ def execute_user_code(code_string, source_lab):
|
|
| 53 |
notification_text += f"\n錯誤類型: {error_type}"
|
| 54 |
send_line_notification_in_background(notification_text)
|
| 55 |
|
| 56 |
-
# --- ✨
|
| 57 |
LIVE_TOOLS = [
|
| 58 |
{"keywords": ["新聞", "今日新聞", "news"], "function": news_service.fetch_today_news, "name": "今日新聞"},
|
| 59 |
{"keywords": ["cwa地震", "顯著地震", "有感地震"], "function": cwa_service.fetch_significant_earthquakes, "name": "CWA 顯著有感地震"},
|
| 60 |
{"keywords": ["地震預警", "cwa alarm"], "function": cwa_service.fetch_cwa_alarm_list, "name": "CWA 地震預警"},
|
| 61 |
{"keywords": ["全球地震", "usgs"], "function": usgs_service.fetch_global_last24h_text, "name": "全球顯著地震"},
|
| 62 |
{"keywords": ["pws發布", "pws info"], "function": pws_service.fetch_latest_pws_info, "name": "PWS 發布情形"},
|
| 63 |
-
|
|
|
|
| 64 |
]
|
| 65 |
|
| 66 |
def find_best_match_from_kb(user_input, knowledge_base, threshold=0.6):
|
|
@@ -83,7 +83,6 @@ def find_best_match_from_kb(user_input, knowledge_base, threshold=0.6):
|
|
| 83 |
else:
|
| 84 |
return best_answer
|
| 85 |
|
| 86 |
-
# --- ✨ 3. 更新主函式,優先檢查是否觸發工具,再查詢知識庫 ---
|
| 87 |
def ai_chatbot_with_kb(message, history):
|
| 88 |
"""
|
| 89 |
處理聊天機器人互動的主函式。
|
|
|
|
| 6 |
import pytz
|
| 7 |
import difflib
|
| 8 |
|
|
|
|
| 9 |
from services import cwa_service, news_service, pws_service, usgs_service
|
| 10 |
from core.visits import get_current_visit_count
|
| 11 |
from core.notifications import send_line_notification_in_background
|
|
|
|
| 52 |
notification_text += f"\n錯誤類型: {error_type}"
|
| 53 |
send_line_notification_in_background(notification_text)
|
| 54 |
|
| 55 |
+
# --- ✨ UPDATED: Added specific keywords for direct tool invocation ---
|
| 56 |
LIVE_TOOLS = [
|
| 57 |
{"keywords": ["新聞", "今日新聞", "news"], "function": news_service.fetch_today_news, "name": "今日新聞"},
|
| 58 |
{"keywords": ["cwa地震", "顯著地震", "有感地震"], "function": cwa_service.fetch_significant_earthquakes, "name": "CWA 顯著有感地震"},
|
| 59 |
{"keywords": ["地震預警", "cwa alarm"], "function": cwa_service.fetch_cwa_alarm_list, "name": "CWA 地震預警"},
|
| 60 |
{"keywords": ["全球地震", "usgs"], "function": usgs_service.fetch_global_last24h_text, "name": "全球顯著地震"},
|
| 61 |
{"keywords": ["pws發布", "pws info"], "function": pws_service.fetch_latest_pws_info, "name": "PWS 發布情形"},
|
| 62 |
+
# --- ✨ 在這裡新增了 "pws" 和 "最新的 pws 地震警報" ---
|
| 63 |
+
{"keywords": ["pws地震", "pws alert", "pws", "最新的 pws 地震警報"], "function": pws_service.fetch_cwa_pws_earthquake_info, "name": "PWS 地震警報"},
|
| 64 |
]
|
| 65 |
|
| 66 |
def find_best_match_from_kb(user_input, knowledge_base, threshold=0.6):
|
|
|
|
| 83 |
else:
|
| 84 |
return best_answer
|
| 85 |
|
|
|
|
| 86 |
def ai_chatbot_with_kb(message, history):
|
| 87 |
"""
|
| 88 |
處理聊天機器人互動的主函式。
|