fix:修正系数,正确处理reply——to,优化s4u的prompt
This commit is contained in:
@@ -115,7 +115,7 @@ class HeartFChatting:
|
|||||||
|
|
||||||
logger.info(f"{self.log_prefix} HeartFChatting 初始化完成")
|
logger.info(f"{self.log_prefix} HeartFChatting 初始化完成")
|
||||||
|
|
||||||
self.energy_value = 1
|
self.energy_value = 5
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
"""检查是否需要启动主循环,如果未激活则启动。"""
|
"""检查是否需要启动主循环,如果未激活则启动。"""
|
||||||
@@ -176,11 +176,11 @@ class HeartFChatting:
|
|||||||
|
|
||||||
async def _energy_loop(self):
|
async def _energy_loop(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(10)
|
||||||
if self.loop_mode == ChatMode.NORMAL:
|
if self.loop_mode == ChatMode.NORMAL:
|
||||||
self.energy_value -= 1
|
self.energy_value -= 0.3
|
||||||
if self.energy_value <= 0:
|
if self.energy_value <= 0.3:
|
||||||
self.energy_value = 0
|
self.energy_value = 0.3
|
||||||
|
|
||||||
def print_cycle_info(self, cycle_timers):
|
def print_cycle_info(self, cycle_timers):
|
||||||
# 记录循环信息和计时器结果
|
# 记录循环信息和计时器结果
|
||||||
@@ -202,8 +202,8 @@ class HeartFChatting:
|
|||||||
self.energy_value -= 1 * global_config.chat.focus_value
|
self.energy_value -= 1 * global_config.chat.focus_value
|
||||||
else:
|
else:
|
||||||
self.energy_value -= 3 * global_config.chat.focus_value
|
self.energy_value -= 3 * global_config.chat.focus_value
|
||||||
if self.energy_value <= 0:
|
if self.energy_value <= 1:
|
||||||
self.energy_value = 0
|
self.energy_value = 1
|
||||||
self.loop_mode = ChatMode.NORMAL
|
self.loop_mode = ChatMode.NORMAL
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -233,7 +233,11 @@ class HeartFChatting:
|
|||||||
|
|
||||||
if_think = await self.normal_response(earliest_messages_data)
|
if_think = await self.normal_response(earliest_messages_data)
|
||||||
if if_think:
|
if if_think:
|
||||||
self.energy_value *= 1.1 / (global_config.chat.focus_value + 0.2)
|
if global_config.chat.focus_value <0.1:
|
||||||
|
factor = 0.1
|
||||||
|
else:
|
||||||
|
factor = global_config.chat.focus_value
|
||||||
|
self.energy_value *= 1.1 / factor
|
||||||
logger.info(f"{self.log_prefix} 麦麦进行了思考,能量值增加1,当前能量值:{self.energy_value}")
|
logger.info(f"{self.log_prefix} 麦麦进行了思考,能量值增加1,当前能量值:{self.energy_value}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -325,7 +329,7 @@ class HeartFChatting:
|
|||||||
logger.info(f"[{self.log_prefix}] {global_config.bot.nickname} 决定的回复内容: {content}")
|
logger.info(f"[{self.log_prefix}] {global_config.bot.nickname} 决定的回复内容: {content}")
|
||||||
|
|
||||||
# 发送回复 (不再需要传入 chat)
|
# 发送回复 (不再需要传入 chat)
|
||||||
await self._send_response(response_set, reply_to_str, loop_start_time)
|
await self._send_response(response_set, reply_to_str, loop_start_time,message_data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -526,11 +530,14 @@ class HeartFChatting:
|
|||||||
logger.error(f"[{self.log_prefix}] 回复生成出现错误:{str(e)} {traceback.format_exc()}")
|
logger.error(f"[{self.log_prefix}] 回复生成出现错误:{str(e)} {traceback.format_exc()}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def _send_response(self, reply_set, reply_to, thinking_start_time):
|
async def _send_response(self, reply_set, reply_to, thinking_start_time,message_data):
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
new_message_count = message_api.count_new_messages(
|
new_message_count = message_api.count_new_messages(
|
||||||
chat_id=self.chat_stream.stream_id, start_time=thinking_start_time, end_time=current_time
|
chat_id=self.chat_stream.stream_id, start_time=thinking_start_time, end_time=current_time
|
||||||
)
|
)
|
||||||
|
platform = message_data.get("platform", "")
|
||||||
|
user_id = message_data.get("user_id", "")
|
||||||
|
reply_to_platform_id = f"{platform}:{user_id}"
|
||||||
|
|
||||||
need_reply = new_message_count >= random.randint(2, 4)
|
need_reply = new_message_count >= random.randint(2, 4)
|
||||||
|
|
||||||
@@ -545,13 +552,13 @@ class HeartFChatting:
|
|||||||
if not first_replied:
|
if not first_replied:
|
||||||
if need_reply:
|
if need_reply:
|
||||||
await send_api.text_to_stream(
|
await send_api.text_to_stream(
|
||||||
text=data, stream_id=self.chat_stream.stream_id, reply_to=reply_to, typing=False
|
text=data, stream_id=self.chat_stream.stream_id, reply_to=reply_to, reply_to_platform_id=reply_to_platform_id, typing=False
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await send_api.text_to_stream(text=data, stream_id=self.chat_stream.stream_id, typing=False)
|
await send_api.text_to_stream(text=data, stream_id=self.chat_stream.stream_id, reply_to_platform_id=reply_to_platform_id, typing=False)
|
||||||
first_replied = True
|
first_replied = True
|
||||||
else:
|
else:
|
||||||
await send_api.text_to_stream(text=data, stream_id=self.chat_stream.stream_id, typing=True)
|
await send_api.text_to_stream(text=data, stream_id=self.chat_stream.stream_id, reply_to_platform_id=reply_to_platform_id, typing=True)
|
||||||
reply_text += data
|
reply_text += data
|
||||||
|
|
||||||
return reply_text
|
return reply_text
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ def register_plugin(cls):
|
|||||||
return cls
|
return cls
|
||||||
|
|
||||||
def register_event_plugin(cls, *args, **kwargs):
|
def register_event_plugin(cls, *args, **kwargs):
|
||||||
from src.plugin_system.core.events_manager import events_manager
|
|
||||||
from src.plugin_system.base.component_types import EventType
|
|
||||||
|
|
||||||
"""事件插件注册装饰器
|
"""事件插件注册装饰器
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ async def _send_to_target(
|
|||||||
display_message: str = "",
|
display_message: str = "",
|
||||||
typing: bool = False,
|
typing: bool = False,
|
||||||
reply_to: str = "",
|
reply_to: str = "",
|
||||||
|
reply_to_platform_id: str = "",
|
||||||
storage_message: bool = True,
|
storage_message: bool = True,
|
||||||
show_log: bool = True,
|
show_log: bool = True,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
@@ -110,6 +111,7 @@ async def _send_to_target(
|
|||||||
is_head=True,
|
is_head=True,
|
||||||
is_emoji=(message_type == "emoji"),
|
is_emoji=(message_type == "emoji"),
|
||||||
thinking_start_time=current_time,
|
thinking_start_time=current_time,
|
||||||
|
reply_to = reply_to_platform_id
|
||||||
)
|
)
|
||||||
|
|
||||||
# 发送消息
|
# 发送消息
|
||||||
@@ -279,6 +281,7 @@ async def text_to_stream(
|
|||||||
stream_id: str,
|
stream_id: str,
|
||||||
typing: bool = False,
|
typing: bool = False,
|
||||||
reply_to: str = "",
|
reply_to: str = "",
|
||||||
|
reply_to_platform_id: str = "",
|
||||||
storage_message: bool = True,
|
storage_message: bool = True,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""向指定流发送文本消息
|
"""向指定流发送文本消息
|
||||||
@@ -293,7 +296,7 @@ async def text_to_stream(
|
|||||||
Returns:
|
Returns:
|
||||||
bool: 是否发送成功
|
bool: 是否发送成功
|
||||||
"""
|
"""
|
||||||
return await _send_to_target("text", text, stream_id, "", typing, reply_to, storage_message)
|
return await _send_to_target("text", text, stream_id, "", typing, reply_to, reply_to_platform_id, storage_message)
|
||||||
|
|
||||||
|
|
||||||
async def emoji_to_stream(emoji_base64: str, stream_id: str, storage_message: bool = True) -> bool:
|
async def emoji_to_stream(emoji_base64: str, stream_id: str, storage_message: bool = True) -> bool:
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class BaseAction(ABC):
|
|||||||
logger.error(f"{self.log_prefix} 等待新消息时发生错误: {e}")
|
logger.error(f"{self.log_prefix} 等待新消息时发生错误: {e}")
|
||||||
return False, f"等待新消息失败: {str(e)}"
|
return False, f"等待新消息失败: {str(e)}"
|
||||||
|
|
||||||
async def send_text(self, content: str, reply_to: str = "", typing: bool = False) -> bool:
|
async def send_text(self, content: str, reply_to: str = "", reply_to_platform_id: str = "", typing: bool = False) -> bool:
|
||||||
"""发送文本消息
|
"""发送文本消息
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -213,7 +213,13 @@ class BaseAction(ABC):
|
|||||||
logger.error(f"{self.log_prefix} 缺少聊天ID")
|
logger.error(f"{self.log_prefix} 缺少聊天ID")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return await send_api.text_to_stream(text=content, stream_id=self.chat_id, reply_to=reply_to, typing=typing)
|
return await send_api.text_to_stream(
|
||||||
|
text=content,
|
||||||
|
stream_id=self.chat_id,
|
||||||
|
reply_to=reply_to,
|
||||||
|
reply_to_platform_id=reply_to_platform_id,
|
||||||
|
typing=typing,
|
||||||
|
)
|
||||||
|
|
||||||
async def send_emoji(self, emoji_base64: str) -> bool:
|
async def send_emoji(self, emoji_base64: str) -> bool:
|
||||||
"""发送表情包
|
"""发送表情包
|
||||||
|
|||||||
@@ -115,17 +115,18 @@ class ReplyAction(BaseAction):
|
|||||||
# 构建回复文本
|
# 构建回复文本
|
||||||
reply_text = ""
|
reply_text = ""
|
||||||
first_replied = False
|
first_replied = False
|
||||||
|
reply_to_platform_id = f"{platform}:{user_id}"
|
||||||
for reply_seg in reply_set:
|
for reply_seg in reply_set:
|
||||||
data = reply_seg[1]
|
data = reply_seg[1]
|
||||||
if not first_replied:
|
if not first_replied:
|
||||||
if need_reply:
|
if need_reply:
|
||||||
await self.send_text(content=data, reply_to=reply_to, typing=False)
|
await self.send_text(content=data, reply_to=reply_to, reply_to_platform_id=reply_to_platform_id, typing=False)
|
||||||
first_replied = True
|
first_replied = True
|
||||||
else:
|
else:
|
||||||
await self.send_text(content=data, typing=False)
|
await self.send_text(content=data, reply_to_platform_id=reply_to_platform_id, typing=False)
|
||||||
first_replied = True
|
first_replied = True
|
||||||
else:
|
else:
|
||||||
await self.send_text(content=data, typing=True)
|
await self.send_text(content=data, reply_to_platform_id=reply_to_platform_id, typing=True)
|
||||||
reply_text += data
|
reply_text += data
|
||||||
|
|
||||||
# 存储动作记录
|
# 存储动作记录
|
||||||
|
|||||||
Reference in New Issue
Block a user