QA: Update requirements and refactor message handling logic etc.

This commit is contained in:
晴猫
2025-05-01 05:58:18 +09:00
parent 410c02e7ee
commit 2f669c7055
25 changed files with 578 additions and 581 deletions

View File

@@ -37,6 +37,10 @@ class ChatObserver:
Args:
stream_id: 聊天流ID
"""
self.last_check_time = None
self.last_check_time = None
self.last_bot_speak_time = None
self.last_user_speak_time = None
if stream_id in self._instances:
raise RuntimeError(f"ChatObserver for {stream_id} already exists. Use get_instance() instead.")

View File

@@ -51,11 +51,9 @@ class MongoDBMessageStorage(MessageStorage):
"""MongoDB消息存储实现"""
async def get_messages_after(self, chat_id: str, message_time: float) -> List[Dict[str, Any]]:
query = {"chat_id": chat_id}
query = {"chat_id": chat_id, "time": {"$gt": message_time}}
# print(f"storage_check_message: {message_time}")
query["time"] = {"$gt": message_time}
return list(db.messages.find(query).sort("time", 1))
async def get_messages_before(self, chat_id: str, time_point: float, limit: int = 5) -> List[Dict[str, Any]]:

View File

@@ -158,6 +158,10 @@ class ObservationInfo:
# meta_plan_trigger: bool = False
# --- 修改:移除 __post_init__ 的参数 ---
def __init__(self):
self.chat_observer = None
self.chat_observer = None
def __post_init__(self):
"""初始化后创建handler并进行必要的设置"""
self.chat_observer: Optional[ChatObserver] = None # 添加类型提示

View File

@@ -147,14 +147,14 @@ class GoalAnalyzer:
# 返回第一个目标作为当前主要目标(如果有)
if result:
first_goal = result[0]
return (first_goal.get("goal", ""), "", first_goal.get("reasoning", ""))
return first_goal.get("goal", ""), "", first_goal.get("reasoning", "")
else:
# 单个目标的情况
conversation_info.goal_list.append(result)
return (goal, "", reasoning)
return goal, "", reasoning
# 如果解析失败,返回默认值
return ("", "", "")
return "", "", ""
async def _update_goals(self, new_goal: str, method: str, reasoning: str):
"""更新目标列表