ruff
This commit is contained in:
committed by
Windpicker-owo
parent
e65ab14f94
commit
950b086063
@@ -8,8 +8,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="MoFox",
|
||||
keywords=["chatter", "affinity", "conversation"],
|
||||
categories=["Chat", "AI"],
|
||||
extra={
|
||||
"is_built_in": True
|
||||
}
|
||||
extra={"is_built_in": True},
|
||||
)
|
||||
|
||||
|
||||
@@ -149,7 +149,6 @@ class AffinityChatter(BaseChatter):
|
||||
"""
|
||||
return self.planner.get_mood_stats()
|
||||
|
||||
|
||||
def reset_stats(self):
|
||||
"""重置统计信息"""
|
||||
self.stats = {
|
||||
|
||||
@@ -111,9 +111,11 @@ class AffinityInterestCalculator(BaseInterestCalculator):
|
||||
+ mentioned_score * self.score_weights["mentioned"]
|
||||
)
|
||||
|
||||
logger.debug(f"[Affinity兴趣计算] 综合得分计算: {interest_match_score:.3f}*{self.score_weights['interest_match']} + "
|
||||
f"{relationship_score:.3f}*{self.score_weights['relationship']} + "
|
||||
f"{mentioned_score:.3f}*{self.score_weights['mentioned']} = {total_score:.3f}")
|
||||
logger.debug(
|
||||
f"[Affinity兴趣计算] 综合得分计算: {interest_match_score:.3f}*{self.score_weights['interest_match']} + "
|
||||
f"{relationship_score:.3f}*{self.score_weights['relationship']} + "
|
||||
f"{mentioned_score:.3f}*{self.score_weights['mentioned']} = {total_score:.3f}"
|
||||
)
|
||||
|
||||
# 5. 考虑连续不回复的概率提升
|
||||
adjusted_score = self._apply_no_reply_boost(total_score)
|
||||
@@ -135,8 +137,10 @@ class AffinityInterestCalculator(BaseInterestCalculator):
|
||||
|
||||
calculation_time = time.time() - start_time
|
||||
|
||||
logger.debug(f"Affinity兴趣值计算完成 - 消息 {message_id}: {adjusted_score:.3f} "
|
||||
f"(匹配:{interest_match_score:.2f}, 关系:{relationship_score:.2f}, 提及:{mentioned_score:.2f})")
|
||||
logger.debug(
|
||||
f"Affinity兴趣值计算完成 - 消息 {message_id}: {adjusted_score:.3f} "
|
||||
f"(匹配:{interest_match_score:.2f}, 关系:{relationship_score:.2f}, 提及:{mentioned_score:.2f})"
|
||||
)
|
||||
|
||||
return InterestCalculationResult(
|
||||
success=True,
|
||||
@@ -145,16 +149,13 @@ class AffinityInterestCalculator(BaseInterestCalculator):
|
||||
should_take_action=should_take_action,
|
||||
should_reply=should_reply,
|
||||
should_act=should_take_action,
|
||||
calculation_time=calculation_time
|
||||
calculation_time=calculation_time,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Affinity兴趣值计算失败: {e}", exc_info=True)
|
||||
return InterestCalculationResult(
|
||||
success=False,
|
||||
message_id=getattr(message, "message_id", ""),
|
||||
interest_value=0.0,
|
||||
error_message=str(e)
|
||||
success=False, message_id=getattr(message, "message_id", ""), interest_value=0.0, error_message=str(e)
|
||||
)
|
||||
|
||||
async def _calculate_interest_match_score(self, content: str, keywords: list[str] | None = None) -> float:
|
||||
|
||||
@@ -405,7 +405,6 @@ class ChatterPlanExecutor:
|
||||
# 移除执行时间列表以避免返回过大数据
|
||||
stats.pop("execution_times", None)
|
||||
|
||||
|
||||
return stats
|
||||
|
||||
def reset_stats(self):
|
||||
@@ -434,12 +433,12 @@ class ChatterPlanExecutor:
|
||||
for i, time_val in enumerate(recent_times)
|
||||
]
|
||||
|
||||
|
||||
async def _flush_action_manager_batch_storage(self, plan: Plan):
|
||||
"""使用 action_manager 的批量存储功能存储所有待处理的动作"""
|
||||
try:
|
||||
# 通过 chat_id 获取真实的 chat_stream 对象
|
||||
from src.plugin_system.apis.chat_api import get_chat_manager
|
||||
|
||||
chat_manager = get_chat_manager()
|
||||
chat_stream = await chat_manager.get_stream(plan.chat_id)
|
||||
|
||||
@@ -455,4 +454,3 @@ class ChatterPlanExecutor:
|
||||
logger.error(f"批量存储动作记录时发生错误: {e}")
|
||||
# 确保在出错时也禁用批量存储模式
|
||||
self.action_manager.disable_batch_storage()
|
||||
|
||||
|
||||
@@ -64,7 +64,6 @@ class ChatterPlanFilter:
|
||||
|
||||
llm_content, _ = await self.planner_llm.generate_response_async(prompt=prompt)
|
||||
|
||||
|
||||
if llm_content:
|
||||
if global_config.debug.show_prompt:
|
||||
logger.info(f"LLM规划器原始响应:{llm_content}")
|
||||
|
||||
@@ -132,7 +132,6 @@ class ChatterActionPlanner:
|
||||
if message_should_act:
|
||||
aggregate_should_act = True
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"处理消息 {message.message_id} 失败: {e}")
|
||||
message.interest_value = 0.0
|
||||
|
||||
@@ -39,6 +39,7 @@ class AffinityChatterPlugin(BasePlugin):
|
||||
try:
|
||||
# 延迟导入 AffinityChatter
|
||||
from .affinity_chatter import AffinityChatter
|
||||
|
||||
components.append((AffinityChatter.get_chatter_info(), AffinityChatter))
|
||||
except Exception as e:
|
||||
logger.error(f"加载 AffinityChatter 时出错: {e}")
|
||||
@@ -46,9 +47,9 @@ class AffinityChatterPlugin(BasePlugin):
|
||||
try:
|
||||
# 延迟导入 AffinityInterestCalculator
|
||||
from .affinity_interest_calculator import AffinityInterestCalculator
|
||||
|
||||
components.append((AffinityInterestCalculator.get_interest_calculator_info(), AffinityInterestCalculator))
|
||||
except Exception as e:
|
||||
logger.error(f"加载 AffinityInterestCalculator 时出错: {e}")
|
||||
|
||||
return components
|
||||
|
||||
|
||||
@@ -13,5 +13,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
extra={
|
||||
"is_built_in": True,
|
||||
"plugin_type": "action_provider",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -13,5 +13,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
extra={
|
||||
"is_built_in": False,
|
||||
"plugin_type": "social",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -12,5 +12,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
categories=["protocol"],
|
||||
extra={
|
||||
"is_built_in": False,
|
||||
}
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -13,8 +13,8 @@ def create_router(plugin_config: dict):
|
||||
"""创建路由器实例"""
|
||||
global router
|
||||
platform_name = config_api.get_plugin_config(plugin_config, "maibot_server.platform_name", "qq")
|
||||
host = os.getenv("HOST","127.0.0.1")
|
||||
port = os.getenv("PORT","8000")
|
||||
host = os.getenv("HOST", "127.0.0.1")
|
||||
port = os.getenv("PORT", "8000")
|
||||
logger.debug(f"初始化MaiBot连接,使用地址:{host}:{port}")
|
||||
route_config = RouteConfig(
|
||||
route_config={
|
||||
|
||||
@@ -12,5 +12,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
extra={
|
||||
"is_built_in": True,
|
||||
"plugin_type": "permission",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -13,5 +13,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
extra={
|
||||
"is_built_in": True,
|
||||
"plugin_type": "plugin_management",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -8,10 +8,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
author="MoFox-Studio",
|
||||
license="GPL-v3.0-or-later",
|
||||
repository_url="https://github.com/MoFox-Studio",
|
||||
keywords=["主动思考","自己发消息"],
|
||||
keywords=["主动思考", "自己发消息"],
|
||||
categories=["Chat", "Integration"],
|
||||
extra={
|
||||
"is_built_in": True,
|
||||
"plugin_type": "functional"
|
||||
}
|
||||
extra={"is_built_in": True, "plugin_type": "functional"},
|
||||
)
|
||||
|
||||
@@ -63,7 +63,9 @@ class ColdStartTask(AsyncTask):
|
||||
logger.info(f"【冷启动】发现全新用户 {chat_id},准备发起第一次问候。")
|
||||
elif stream.last_active_time < self.bot_start_time:
|
||||
should_wake_up = True
|
||||
logger.info(f"【冷启动】发现沉睡的聊天流 {chat_id} (最后活跃于 {datetime.fromtimestamp(stream.last_active_time)}),准备唤醒。")
|
||||
logger.info(
|
||||
f"【冷启动】发现沉睡的聊天流 {chat_id} (最后活跃于 {datetime.fromtimestamp(stream.last_active_time)}),准备唤醒。"
|
||||
)
|
||||
|
||||
if should_wake_up:
|
||||
person_id = person_api.get_person_id(platform, user_id)
|
||||
@@ -166,7 +168,9 @@ class ProactiveThinkingTask(AsyncTask):
|
||||
continue
|
||||
|
||||
# 检查冷却时间
|
||||
recent_messages = await message_api.get_recent_messages(chat_id=stream.stream_id, limit=1,limit_mode="latest")
|
||||
recent_messages = await message_api.get_recent_messages(
|
||||
chat_id=stream.stream_id, limit=1, limit_mode="latest"
|
||||
)
|
||||
last_message_time = recent_messages[0]["time"] if recent_messages else stream.create_time
|
||||
time_since_last_active = time.time() - last_message_time
|
||||
if time_since_last_active > next_interval:
|
||||
@@ -209,7 +213,7 @@ class ProactiveThinkingTask(AsyncTask):
|
||||
logger.info("日常唤醒任务被正常取消。")
|
||||
break
|
||||
except Exception as e:
|
||||
traceback.print_exc() # 打印完整的堆栈跟踪
|
||||
traceback.print_exc() # 打印完整的堆栈跟踪
|
||||
logger.error(f"【日常唤醒】任务出现错误,将在60秒后重试: {e}", exc_info=True)
|
||||
await asyncio.sleep(60)
|
||||
|
||||
|
||||
@@ -143,14 +143,16 @@ class ProactiveThinkerExecutor:
|
||||
else "今天没有日程安排。"
|
||||
)
|
||||
|
||||
recent_messages = await message_api.get_recent_messages(stream.stream_id,limit=50,limit_mode="latest",hours=12)
|
||||
recent_messages = await message_api.get_recent_messages(
|
||||
stream.stream_id, limit=50, limit_mode="latest", hours=12
|
||||
)
|
||||
recent_chat_history = (
|
||||
await message_api.build_readable_messages_to_str(recent_messages) if recent_messages else "无"
|
||||
)
|
||||
|
||||
action_history_list = await get_actions_by_timestamp_with_chat(
|
||||
chat_id=stream.stream_id,
|
||||
timestamp_start=time.time() - 3600 * 24, #过去24小时
|
||||
timestamp_start=time.time() - 3600 * 24, # 过去24小时
|
||||
timestamp_end=time.time(),
|
||||
limit=7,
|
||||
)
|
||||
@@ -195,11 +197,9 @@ class ProactiveThinkerExecutor:
|
||||
person_id = person_api.get_person_id(user_info.platform, int(user_info.user_id))
|
||||
person_info_manager = get_person_info_manager()
|
||||
person_info = await person_info_manager.get_values(person_id, ["user_id", "platform", "person_name"])
|
||||
cross_context_block = await Prompt.build_cross_context(
|
||||
stream.stream_id, "s4u", person_info
|
||||
)
|
||||
cross_context_block = await Prompt.build_cross_context(stream.stream_id, "s4u", person_info)
|
||||
|
||||
# 获取关系信息
|
||||
# 获取关系信息
|
||||
short_impression = await person_info_manager.get_value(person_id, "short_impression") or "无"
|
||||
impression = await person_info_manager.get_value(person_id, "impression") or "无"
|
||||
attitude = await person_info_manager.get_value(person_id, "attitude") or 50
|
||||
|
||||
@@ -10,8 +10,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
repository_url="https://github.com/MoFox-Studio",
|
||||
keywords=["emoji", "reaction", "like", "表情", "回应", "点赞"],
|
||||
categories=["Chat", "Integration"],
|
||||
extra={
|
||||
"is_built_in": "true",
|
||||
"plugin_type": "functional"
|
||||
}
|
||||
extra={"is_built_in": "true", "plugin_type": "functional"},
|
||||
)
|
||||
|
||||
@@ -548,7 +548,7 @@ class SetEmojiLikePlugin(BasePlugin):
|
||||
config_section_descriptions = {"plugin": "插件基本信息", "components": "插件组件"}
|
||||
|
||||
# 配置Schema定义
|
||||
config_schema: ClassVar[dict ]= {
|
||||
config_schema: ClassVar[dict] = {
|
||||
"plugin": {
|
||||
"name": ConfigField(type=str, default="set_emoji_like", description="插件名称"),
|
||||
"version": ConfigField(type=str, default="1.0.0", description="插件版本"),
|
||||
|
||||
@@ -13,5 +13,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
extra={
|
||||
"is_built_in": True,
|
||||
"plugin_type": "audio_processor",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -12,5 +12,5 @@ __plugin_meta__ = PluginMetadata(
|
||||
categories=["Tools"],
|
||||
extra={
|
||||
"is_built_in": True,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -43,7 +43,9 @@ class SearXNGSearchEngine(BaseSearchEngine):
|
||||
|
||||
api_keys = config_api.get_global_config("web_search.searxng_api_keys", None)
|
||||
if isinstance(api_keys, list):
|
||||
self.api_keys: list[str | None] = [k.strip() if isinstance(k, str) and k.strip() else None for k in api_keys]
|
||||
self.api_keys: list[str | None] = [
|
||||
k.strip() if isinstance(k, str) and k.strip() else None for k in api_keys
|
||||
]
|
||||
else:
|
||||
self.api_keys = []
|
||||
|
||||
@@ -51,9 +53,7 @@ class SearXNGSearchEngine(BaseSearchEngine):
|
||||
if self.api_keys and len(self.api_keys) < len(self.instances):
|
||||
self.api_keys.extend([None] * (len(self.instances) - len(self.api_keys)))
|
||||
|
||||
logger.debug(
|
||||
f"SearXNG 引擎配置: instances={self.instances}, api_keys={'yes' if any(self.api_keys) else 'no'}"
|
||||
)
|
||||
logger.debug(f"SearXNG 引擎配置: instances={self.instances}, api_keys={'yes' if any(self.api_keys) else 'no'}")
|
||||
|
||||
def is_available(self) -> bool:
|
||||
return bool(self.instances)
|
||||
|
||||
Reference in New Issue
Block a user