Skip to content

Commit 8d9a88a

Browse files
committed
ruff
1 parent 440e8bf commit 8d9a88a

70 files changed

Lines changed: 1597 additions & 1641 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/chat/actions/base_action.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@
88
_ACTION_REGISTRY: Dict[str, Type["BaseAction"]] = {}
99
_DEFAULT_ACTIONS: Dict[str, str] = {}
1010

11+
1112
# 动作激活类型枚举
1213
class ActionActivationType:
1314
ALWAYS = "always" # 默认参与到planner
14-
LLM_JUDGE = "llm_judge" # LLM判定是否启动该action到planner
15+
LLM_JUDGE = "llm_judge" # LLM判定是否启动该action到planner
1516
RANDOM = "random" # 随机启用action到planner
1617
KEYWORD = "keyword" # 关键词触发启用action到planner
1718

19+
1820
# 聊天模式枚举
1921
class ChatMode:
2022
FOCUS = "focus" # Focus聊天模式
2123
NORMAL = "normal" # Normal聊天模式
2224
ALL = "all" # 所有聊天模式
2325

26+
2427
def register_action(cls):
2528
"""
2629
动作注册装饰器
@@ -81,13 +84,13 @@ def __init__(self, action_data: dict, reasoning: str, cycle_timers: dict, thinki
8184
self.action_description: str = "基础动作"
8285
self.action_parameters: dict = {}
8386
self.action_require: list[str] = []
84-
87+
8588
# 动作激活类型设置
8689
# Focus模式下的激活类型,默认为always
8790
self.focus_activation_type: str = ActionActivationType.ALWAYS
88-
# Normal模式下的激活类型,默认为always
91+
# Normal模式下的激活类型,默认为always
8992
self.normal_activation_type: str = ActionActivationType.ALWAYS
90-
93+
9194
# 随机激活的概率(0.0-1.0),用于RANDOM激活类型
9295
self.random_activation_probability: float = 0.3
9396
# LLM判定的提示词,用于LLM_JUDGE激活类型

src/chat/actions/default_actions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from . import exit_focus_chat_action # noqa
55
from . import emoji_action # noqa
66

7-
# 在此处添加更多动作模块导入
7+
# 在此处添加更多动作模块导入

src/chat/actions/default_actions/emoji_action.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,26 @@ class EmojiAction(BaseAction):
2222
action_parameters: dict[str:str] = {
2323
"description": "文字描述你想要发送的表情包内容",
2424
}
25-
action_require: list[str] = [
26-
"表达情绪时可以选择使用",
27-
"重点:不要连续发,如果你已经发过[表情包],就不要选择此动作"]
25+
action_require: list[str] = ["表达情绪时可以选择使用", "重点:不要连续发,如果你已经发过[表情包],就不要选择此动作"]
2826

2927
associated_types: list[str] = ["emoji"]
3028

3129
enable_plugin = True
32-
30+
3331
focus_activation_type = ActionActivationType.LLM_JUDGE
3432
normal_activation_type = ActionActivationType.RANDOM
35-
33+
3634
random_activation_probability = global_config.normal_chat.emoji_chance
37-
35+
3836
parallel_action = True
39-
40-
37+
4138
llm_judge_prompt = """
4239
判定是否需要使用表情动作的条件:
4340
1. 用户明确要求使用表情包
4441
2. 这是一个适合表达强烈情绪的场合
4542
3. 不要发送太多表情包,如果你已经发送过多个表情包
4643
"""
47-
44+
4845
# 模式启用设置 - 表情动作只在Focus模式下使用
4946
mode_enable = ChatMode.ALL
5047

@@ -147,4 +144,4 @@ async def _handle_reply(
147144
elif type == "emoji":
148145
reply_text += data
149146

150-
return success, reply_text
147+
return success, reply_text

src/chat/actions/default_actions/exit_focus_chat_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ExitFocusChatAction(BaseAction):
2727
]
2828
# 退出专注聊天是系统核心功能,不是插件,但默认不启用(需要特定条件触发)
2929
enable_plugin = False
30-
30+
3131
# 模式启用设置 - 退出专注聊天动作只在Focus模式下使用
3232
mode_enable = ChatMode.FOCUS
3333

src/chat/actions/default_actions/no_reply_action.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class NoReplyAction(BaseAction):
2929
"想要休息一下",
3030
]
3131
enable_plugin = True
32-
32+
3333
# 激活类型设置
3434
focus_activation_type = ActionActivationType.ALWAYS
35-
35+
3636
# 模式启用设置 - no_reply动作只在Focus模式下使用
3737
mode_enable = ChatMode.FOCUS
3838

src/chat/actions/default_actions/reply_action.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ class ReplyAction(BaseAction):
3131
action_require: list[str] = [
3232
"你想要闲聊或者随便附和",
3333
"有人提到你",
34-
"如果你刚刚进行了回复,不要对同一个话题重复回应"
34+
"如果你刚刚进行了回复,不要对同一个话题重复回应",
3535
]
3636

3737
associated_types: list[str] = ["text"]
3838

3939
enable_plugin = True
40-
40+
4141
# 激活类型设置
4242
focus_activation_type = ActionActivationType.ALWAYS
43-
43+
4444
# 模式启用设置 - 回复动作只在Focus模式下使用
4545
mode_enable = ChatMode.FOCUS
4646

@@ -89,12 +89,12 @@ async def handle_action(self) -> Tuple[bool, str]:
8989
cycle_timers=self.cycle_timers,
9090
thinking_id=self.thinking_id,
9191
)
92-
92+
9393
await self.store_action_info(
9494
action_build_into_prompt=False,
9595
action_prompt_display=f"{reply_text}",
9696
)
97-
97+
9898
return success, reply_text
9999

100100
async def _handle_reply(
@@ -115,30 +115,29 @@ async def _handle_reply(
115115
chatting_observation: ChattingObservation = next(
116116
obs for obs in self.observations if isinstance(obs, ChattingObservation)
117117
)
118-
118+
119119
reply_to = reply_data.get("reply_to", "none")
120-
120+
121121
# sender = ""
122122
target = ""
123123
if ":" in reply_to or ":" in reply_to:
124124
# 使用正则表达式匹配中文或英文冒号
125-
parts = re.split(pattern=r'[::]', string=reply_to, maxsplit=1)
125+
parts = re.split(pattern=r"[::]", string=reply_to, maxsplit=1)
126126
if len(parts) == 2:
127127
# sender = parts[0].strip()
128128
target = parts[1].strip()
129129
anchor_message = chatting_observation.search_message_by_text(target)
130130
else:
131131
anchor_message = None
132-
133-
if anchor_message:
132+
133+
if anchor_message:
134134
anchor_message.update_chat_stream(self.chat_stream)
135135
else:
136136
logger.info(f"{self.log_prefix} 未找到锚点消息,创建占位符")
137137
anchor_message = await create_empty_anchor_message(
138138
self.chat_stream.platform, self.chat_stream.group_info, self.chat_stream
139139
)
140140

141-
142141
success, reply_set = await self.replyer.deal_reply(
143142
cycle_timers=cycle_timers,
144143
action_data=reply_data,
@@ -158,8 +157,9 @@ async def _handle_reply(
158157

159158
return success, reply_text
160159

161-
162-
async def store_action_info(self, action_build_into_prompt: bool = False, action_prompt_display: str = "", action_done: bool = True) -> None:
160+
async def store_action_info(
161+
self, action_build_into_prompt: bool = False, action_prompt_display: str = "", action_done: bool = True
162+
) -> None:
163163
"""存储action执行信息到数据库
164164
165165
Args:
@@ -188,9 +188,9 @@ async def store_action_info(self, action_build_into_prompt: bool = False, action
188188
chat_info_platform=chat_stream.platform,
189189
user_id=chat_stream.user_info.user_id if chat_stream.user_info else "",
190190
user_nickname=chat_stream.user_info.user_nickname if chat_stream.user_info else "",
191-
user_cardname=chat_stream.user_info.user_cardname if chat_stream.user_info else ""
191+
user_cardname=chat_stream.user_info.user_cardname if chat_stream.user_info else "",
192192
)
193193
logger.debug(f"{self.log_prefix} 已存储action信息: {action_prompt_display}")
194194
except Exception as e:
195195
logger.error(f"{self.log_prefix} 存储action信息时出错: {e}")
196-
traceback.print_exc()
196+
traceback.print_exc()

src/chat/actions/plugin_action.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import traceback
2-
from typing import Tuple, Dict, List, Any, Optional, Union, Type
1+
from typing import Tuple, Dict, Any, Optional
32
from src.chat.actions.base_action import BaseAction, register_action, ActionActivationType, ChatMode # noqa F401
4-
from src.chat.heart_flow.observation.chatting_observation import ChattingObservation
5-
from src.chat.focus_chat.hfc_utils import create_empty_anchor_message
63
from src.common.logger_manager import get_logger
7-
from src.config.config import global_config
84
import os
95
import inspect
106
import toml # 导入 toml 库
@@ -20,10 +16,10 @@
2016
from src.chat.actions.plugin_api.hearflow_api import HearflowAPI
2117

2218
# 以下为类型注解需要
23-
from src.chat.message_receive.chat_stream import ChatStream # noqa
24-
from src.chat.focus_chat.expressors.default_expressor import DefaultExpressor # noqa
25-
from src.chat.focus_chat.replyer.default_replyer import DefaultReplyer # noqa
26-
from src.chat.focus_chat.info.obs_info import ObsInfo # noqa
19+
from src.chat.message_receive.chat_stream import ChatStream # noqa
20+
from src.chat.focus_chat.expressors.default_expressor import DefaultExpressor # noqa
21+
from src.chat.focus_chat.replyer.default_replyer import DefaultReplyer # noqa
22+
from src.chat.focus_chat.info.obs_info import ObsInfo # noqa
2723

2824
logger = get_logger("plugin_action")
2925

@@ -35,15 +31,15 @@ class PluginAction(BaseAction, MessageAPI, LLMAPI, DatabaseAPI, ConfigAPI, Utils
3531
"""
3632

3733
action_config_file_name: Optional[str] = None # 插件可以覆盖此属性来指定配置文件名
38-
34+
3935
# 默认激活类型设置,插件可以覆盖
4036
focus_activation_type = ActionActivationType.ALWAYS
4137
normal_activation_type = ActionActivationType.ALWAYS
4238
random_activation_probability: float = 0.3
4339
llm_judge_prompt: str = ""
4440
activation_keywords: list[str] = []
4541
keyword_case_sensitive: bool = False
46-
42+
4743
# 默认模式启用设置 - 插件动作默认在所有模式下可用,插件可以覆盖
4844
mode_enable = ChatMode.ALL
4945

src/chat/actions/plugin_api/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from src.chat.actions.plugin_api.hearflow_api import HearflowAPI
88

99
__all__ = [
10-
'MessageAPI',
11-
'LLMAPI',
12-
'DatabaseAPI',
13-
'ConfigAPI',
14-
'UtilsAPI',
15-
'StreamAPI',
16-
'HearflowAPI',
17-
]
10+
"MessageAPI",
11+
"LLMAPI",
12+
"DatabaseAPI",
13+
"ConfigAPI",
14+
"UtilsAPI",
15+
"StreamAPI",
16+
"HearflowAPI",
17+
]

src/chat/actions/plugin_api/config_api.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,50 @@
55

66
logger = get_logger("config_api")
77

8+
89
class ConfigAPI:
910
"""配置API模块
10-
11+
1112
提供了配置读取和用户信息获取等功能
1213
"""
13-
14+
1415
def get_global_config(self, key: str, default: Any = None) -> Any:
1516
"""
1617
安全地从全局配置中获取一个值。
1718
插件应使用此方法读取全局配置,以保证只读和隔离性。
18-
19+
1920
Args:
2021
key: 配置键名
2122
default: 如果配置不存在时返回的默认值
22-
23+
2324
Returns:
2425
Any: 配置值或默认值
2526
"""
2627
return global_config.get(key, default)
27-
28+
2829
async def get_user_id_by_person_name(self, person_name: str) -> tuple[str, str]:
2930
"""根据用户名获取用户ID
30-
31+
3132
Args:
3233
person_name: 用户名
33-
34+
3435
Returns:
3536
tuple[str, str]: (平台, 用户ID)
3637
"""
3738
person_id = person_info_manager.get_person_id_by_person_name(person_name)
3839
user_id = await person_info_manager.get_value(person_id, "user_id")
3940
platform = await person_info_manager.get_value(person_id, "platform")
4041
return platform, user_id
41-
42+
4243
async def get_person_info(self, person_id: str, key: str, default: Any = None) -> Any:
4344
"""获取用户信息
44-
45+
4546
Args:
4647
person_id: 用户ID
4748
key: 信息键名
4849
default: 默认值
49-
50+
5051
Returns:
5152
Any: 用户信息值或默认值
5253
"""
53-
return await person_info_manager.get_value(person_id, key, default)
54+
return await person_info_manager.get_value(person_id, key, default)

0 commit comments

Comments
 (0)