5
This commit is contained in:
@@ -39,6 +39,7 @@ class HeartFChatting:
|
|||||||
- 初始化聊天模式并记录初始化完成日志
|
- 初始化聊天模式并记录初始化完成日志
|
||||||
"""
|
"""
|
||||||
self.context = HfcContext(chat_id)
|
self.context = HfcContext(chat_id)
|
||||||
|
self.context.new_message_queue = asyncio.Queue()
|
||||||
|
|
||||||
self.cycle_tracker = CycleTracker(self.context)
|
self.cycle_tracker = CycleTracker(self.context)
|
||||||
self.response_handler = ResponseHandler(self.context)
|
self.response_handler = ResponseHandler(self.context)
|
||||||
@@ -108,6 +109,10 @@ class HeartFChatting:
|
|||||||
self._loop_task.add_done_callback(self._handle_loop_completion)
|
self._loop_task.add_done_callback(self._handle_loop_completion)
|
||||||
logger.info(f"{self.context.log_prefix} HeartFChatting 启动完成")
|
logger.info(f"{self.context.log_prefix} HeartFChatting 启动完成")
|
||||||
|
|
||||||
|
async def add_message(self, message: Dict[str, Any]):
|
||||||
|
"""从外部接收新消息并放入队列"""
|
||||||
|
await self.context.new_message_queue.put(message)
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
"""
|
"""
|
||||||
停止心跳聊天系统
|
停止心跳聊天系统
|
||||||
@@ -362,15 +367,10 @@ class HeartFChatting:
|
|||||||
# 核心修复:在睡眠模式(包括失眠)下获取消息时,不过滤命令消息,以确保@消息能被接收
|
# 核心修复:在睡眠模式(包括失眠)下获取消息时,不过滤命令消息,以确保@消息能被接收
|
||||||
filter_command_flag = not (is_sleeping or is_in_insomnia)
|
filter_command_flag = not (is_sleeping or is_in_insomnia)
|
||||||
|
|
||||||
recent_messages = await message_api.get_messages_by_time_in_chat(
|
# 从队列中获取所有待处理的新消息
|
||||||
chat_id=self.context.stream_id,
|
recent_messages = []
|
||||||
start_time=self.context.last_read_time,
|
while not self.context.new_message_queue.empty():
|
||||||
end_time=time.time(),
|
recent_messages.append(await self.context.new_message_queue.get())
|
||||||
limit=10,
|
|
||||||
limit_mode="latest",
|
|
||||||
filter_mai=True,
|
|
||||||
filter_command=filter_command_flag,
|
|
||||||
)
|
|
||||||
|
|
||||||
has_new_messages = bool(recent_messages)
|
has_new_messages = bool(recent_messages)
|
||||||
new_message_count = len(recent_messages)
|
new_message_count = len(recent_messages)
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class HeartFCMessageReceiver:
|
|||||||
|
|
||||||
subheartflow: SubHeartflow = await heartflow.get_or_create_subheartflow(chat.stream_id) # type: ignore
|
subheartflow: SubHeartflow = await heartflow.get_or_create_subheartflow(chat.stream_id) # type: ignore
|
||||||
|
|
||||||
# subheartflow.add_message_to_normal_chat_cache(message, interested_rate, is_mentioned)
|
await subheartflow.heart_fc_instance.add_message(message.to_dict())
|
||||||
if global_config.mood.enable_mood:
|
if global_config.mood.enable_mood:
|
||||||
chat_mood = mood_manager.get_mood_by_chat_id(subheartflow.chat_id)
|
chat_mood = mood_manager.get_mood_by_chat_id(subheartflow.chat_id)
|
||||||
asyncio.create_task(chat_mood.update_mood_by_message(message, interested_rate))
|
asyncio.create_task(chat_mood.update_mood_by_message(message, interested_rate))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from typing import Any, Dict, List, Optional
|
|||||||
|
|
||||||
from json_repair import repair_json
|
from json_repair import repair_json
|
||||||
|
|
||||||
|
from . import planner_prompts
|
||||||
from src.chat.memory_system.Hippocampus import hippocampus_manager
|
from src.chat.memory_system.Hippocampus import hippocampus_manager
|
||||||
from src.chat.utils.chat_message_builder import (
|
from src.chat.utils.chat_message_builder import (
|
||||||
build_readable_actions,
|
build_readable_actions,
|
||||||
@@ -167,7 +168,7 @@ class PlanFilter:
|
|||||||
limit=5,
|
limit=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
actions_before_now_block = build_readable_actions(actions=await actions_before_now)
|
actions_before_now_block = build_readable_actions(actions=actions_before_now)
|
||||||
actions_before_now_block = f"你刚刚选择并执行过的action是:\n{actions_before_now_block}"
|
actions_before_now_block = f"你刚刚选择并执行过的action是:\n{actions_before_now_block}"
|
||||||
|
|
||||||
self.last_obs_time_mark = time.time()
|
self.last_obs_time_mark = time.time()
|
||||||
|
|||||||
Reference in New Issue
Block a user