mirror of https://github.com/Mai-with-u/MaiBot.git
Merge branch 'groupnickname' of https://github.com/Dax233/MaiMBot into PFC-config-huge-update
commit
7142ad3761
|
|
@ -330,6 +330,7 @@ class BotConfig:
|
|||
nickname_queue_max_size: int = 100 # 绰号处理队列最大容量
|
||||
nickname_process_sleep_interval: float = 5 # 绰号处理进程休眠间隔(秒)
|
||||
nickname_analysis_history_limit: int = 30 # 绰号处理可见最大上下文
|
||||
nickname_analysis_probability: float = 0.1 # 绰号随机概率命中,该值越大,绰号分析越频繁
|
||||
|
||||
# 模型配置
|
||||
llm_reasoning: dict[str, str] = field(default_factory=lambda: {})
|
||||
|
|
@ -487,6 +488,9 @@ class BotConfig:
|
|||
config.nickname_analysis_history_limit = group_nickname_config.get(
|
||||
"nickname_analysis_history_limit", config.nickname_analysis_history_limit
|
||||
)
|
||||
config.nickname_analysis_probability = group_nickname_config.get(
|
||||
"nickname_analysis_probability", config.nickname_analysis_probability
|
||||
)
|
||||
|
||||
def bot(parent: dict):
|
||||
# 机器人基础配置
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ class NicknameManager:
|
|||
self.nickname_queue: asyncio.Queue = asyncio.Queue(maxsize=self.queue_max_size)
|
||||
self._stop_event = threading.Event() # stop_event 仍然使用 threading.Event,因为它是由另一个线程设置的
|
||||
self._nickname_thread: Optional[threading.Thread] = None
|
||||
self.sleep_interval = getattr(self.config, "nickname_process_sleep_interval", 60) # 超时时间
|
||||
self.sleep_interval = getattr(self.config, "nickname_process_sleep_interval", 5) # 超时时间
|
||||
|
||||
self._initialized = True
|
||||
logger.info("NicknameManager 初始化完成。")
|
||||
|
|
@ -177,6 +177,7 @@ class NicknameManager:
|
|||
self._stop_event.set() # 设置停止事件,_processing_loop 会检测到
|
||||
try:
|
||||
# 不需要清空 asyncio.Queue,让循环自然结束或被取消
|
||||
# self.empty_queue(self.nickname_queue)
|
||||
self._nickname_thread.join(timeout=10) # 等待线程结束
|
||||
if self._nickname_thread.is_alive():
|
||||
logger.warning("绰号处理器线程在超时后仍未停止。")
|
||||
|
|
@ -189,6 +190,13 @@ class NicknameManager:
|
|||
else:
|
||||
logger.info("绰号处理器线程未在运行或已被清理。")
|
||||
|
||||
# def empty_queue(self, q: asyncio.Queue):
|
||||
# while not q.empty():
|
||||
# # Depending on your program, you may want to
|
||||
# # catch QueueEmpty
|
||||
# q.get_nowait()
|
||||
# q.task_done()
|
||||
|
||||
async def trigger_nickname_analysis(
|
||||
self,
|
||||
anchor_message: MessageRecv,
|
||||
|
|
@ -202,7 +210,7 @@ class NicknameManager:
|
|||
if not self.is_enabled:
|
||||
return
|
||||
|
||||
if random.random() > 0.9:
|
||||
if random.random() < global_config.nickname_analysis_probability:
|
||||
logger.debug("跳过绰号分析:随机概率未命中。")
|
||||
return
|
||||
|
||||
|
|
@ -358,7 +366,6 @@ class NicknameManager:
|
|||
logger.info(f"{log_prefix} LLM 找到绰号映射,准备更新数据库: {nickname_map_to_update}")
|
||||
|
||||
for user_id_str, nickname in nickname_map_to_update.items():
|
||||
# ... (验证和数据库更新逻辑保持不变) ...
|
||||
if not user_id_str or not nickname:
|
||||
logger.warning(f"{log_prefix} 跳过无效条目: user_id='{user_id_str}', nickname='{nickname}'")
|
||||
continue
|
||||
|
|
@ -394,7 +401,6 @@ class NicknameManager:
|
|||
"""
|
||||
内部方法:调用 LLM 分析聊天记录和 Bot 回复,提取可靠的 用户ID-绰号 映射。
|
||||
"""
|
||||
# ... (此方法内部逻辑保持不变) ...
|
||||
if not self.llm_mapper:
|
||||
logger.error("LLM 映射器未初始化,无法执行分析。")
|
||||
return {"is_exist": False}
|
||||
|
|
|
|||
|
|
@ -130,8 +130,9 @@ enable_nickname_mapping = false # 绰号映射功能总开关(默认关闭,
|
|||
max_nicknames_in_prompt = 10 # Prompt 中最多注入的绰号数量(防止token数量爆炸)
|
||||
nickname_probability_smoothing = 1 # 绰号加权随机选择的平滑因子
|
||||
nickname_queue_max_size = 100 # 绰号处理队列最大容量
|
||||
nickname_process_sleep_interval = 5 # 绰号处理进程休眠间隔(秒)
|
||||
nickname_process_sleep_interval = 5 # 绰号处理进程休眠间隔(秒),不建议超过5,否则大概率导致结束过程中超时
|
||||
nickname_analysis_history_limit = 30 # 绰号处理可见最大上下文
|
||||
nickname_analysis_probability = 0.1 # 绰号随机概率命中,该值越大,绰号分析越频繁
|
||||
|
||||
[memory]
|
||||
build_memory_interval = 2000 # 记忆构建间隔 单位秒 间隔越低,麦麦学习越多,但是冗余信息也会增多
|
||||
|
|
|
|||
Loading…
Reference in New Issue