瀏覽代碼

Update dialogue service: change limit to recent minutes

StrayWarrior 1 月之前
父節點
當前提交
2907eaafab
共有 2 個文件被更改,包括 8 次插入5 次删除
  1. 3 3
      dialogue_manager.py
  2. 5 2
      history_dialogue_service.py

+ 3 - 3
dialogue_manager.py

@@ -111,7 +111,7 @@ class DialogueManager:
         self.current_state, self.previous_state = self.state_cache.get_state(self.staff_id, self.user_id)
 
         # 从数据库恢复对话状态
-        last_message = self.history_dialogue_service.get_dialogue_history(self.staff_id, self.user_id, 10)
+        last_message = self.history_dialogue_service.get_dialogue_history(self.staff_id, self.user_id)
         if last_message:
             self.last_interaction_time = last_message[-1]['timestamp']
         else:
@@ -282,7 +282,7 @@ class DialogueManager:
             event = {
                 "timestamp": int(time.time() * 1000),
                 "reason": reason,
-                "dialogue_context": self.history_dialogue_service.get_dialogue_history(self.staff_id, self.user_id, 5)
+                "dialogue_context": self.history_dialogue_service.get_dialogue_history(self.staff_id, self.user_id, 60)
             }
 
             # 更新用户资料中的人工介入历史
@@ -306,7 +306,7 @@ class DialogueManager:
         """
 
         # 添加最近的对话记录
-        recent_dialogues = self.history_dialogue_service.get_dialogue_history(self.staff_id, self.user_id, 5)
+        recent_dialogues = self.history_dialogue_service.get_dialogue_history(self.staff_id, self.user_id, 10)
         for dialogue in recent_dialogues:
             alert_message += f"\n{dialogue['role']}: {dialogue['content']}"
 

+ 5 - 2
history_dialogue_service.py

@@ -4,6 +4,7 @@
 
 import requests
 from logging_service import logger
+import time
 
 import configs
 
@@ -12,8 +13,10 @@ class HistoryDialogueService:
     def __init__(self, base_url: str):
         self.base_url = base_url
 
-    def get_dialogue_history(self, staff_id: str, user_id: str, max_count: int = 100):
-        url = f"{self.base_url}?sender={staff_id}&receiver={user_id}&limit={max_count}"
+    def get_dialogue_history(self, staff_id: str, user_id: str, recent_minutes: int = 1440):
+        recent_minutes = min(recent_minutes, 24 * 60)
+        time_begin = int(time.time() * 1000) - recent_minutes * 60 * 1000
+        url = f"{self.base_url}?sender={staff_id}&receiver={user_id}&time={time_begin}"
         response = requests.post(url, headers={
             'Content-Type': 'application/json'
         })