Pārlūkot izejas kodu

Update dialogue_manager: recover unprocessed messages

StrayWarrior 4 dienas atpakaļ
vecāks
revīzija
f99329cf2a
1 mainītis faili ar 7 papildinājumiem un 0 dzēšanām
  1. 7 0
      dialogue_manager.py

+ 7 - 0
dialogue_manager.py

@@ -152,6 +152,12 @@ class DialogueManager:
         self.dialogue_history = self.history_dialogue_service.get_dialogue_history(self.staff_id, self.user_id)
         if self.dialogue_history:
             self.last_interaction_time = self.dialogue_history[-1]['timestamp']
+            if self.current_state == DialogueState.MESSAGE_AGGREGATING:
+                # 需要恢复未处理对话,找到dialogue_history中最后未处理的user消息
+                for entry in reversed(self.dialogue_history):
+                    if entry['role'] == 'user':
+                        self.unprocessed_messages.append(entry['content'])
+                        break
         else:
             # 默认设置为24小时前
             self.last_interaction_time = int(time.time() * 1000) - 24 * 3600 * 1000
@@ -262,6 +268,7 @@ class DialogueManager:
         if self.unprocessed_messages:
             message_text = '\n'.join(self.unprocessed_messages)
             self.unprocessed_messages.clear()
+        # 实际上这里message_text并不会被最终送入LLM,只是用来做状态判断
 
         # 根据消息内容和当前状态确定新状态
         new_state = self._determine_state_from_message(message_text)