🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-06-25 09:20:20 +00:00
parent f40194516b
commit 8ba8aa7b2c
7 changed files with 49 additions and 39 deletions

View File

@@ -145,8 +145,10 @@ class ExpressionSelector:
except Exception as e:
logger.error(f"更新表达方式count失败: {e}")
async def select_suitable_expressions_llm(self, chat_id: str, chat_info: str, max_num: int = 10, min_num: int = 5) -> List[Dict[str, str]]:
async def select_suitable_expressions_llm(
self, chat_id: str, chat_info: str, max_num: int = 10, min_num: int = 5
) -> List[Dict[str, str]]:
"""使用LLM选择适合的表达方式"""
# 1. 获取35个随机表达方式现在按权重抽取
@@ -195,7 +197,6 @@ class ExpressionSelector:
max_num=max_num,
)
# 4. 调用LLM
try:
content, (_, _) = await self.llm_model.generate_response_async(prompt=prompt)

View File

@@ -181,7 +181,9 @@ class HeartFCMessageReceiver:
mes_name = chat.group_info.group_name if chat.group_info else "私聊"
# current_time = time.strftime("%H:%M:%S", time.localtime(message.message_info.time))
current_talk_frequency = global_config.chat.get_current_talk_frequency(chat.stream_id)
logger.info(f"[{mes_name}]{userinfo.user_nickname}:{message.processed_plain_text}[当前回复频率: {current_talk_frequency}]")
logger.info(
f"[{mes_name}]{userinfo.user_nickname}:{message.processed_plain_text}[当前回复频率: {current_talk_frequency}]"
)
# 8. 关系处理
if global_config.relationship.enable_relationship:

View File

@@ -71,7 +71,9 @@ class ExpressionSelectorProcessor(BaseProcessor):
try:
# LLM模式调用LLM选择5-10个然后随机选5个
selected_expressions = await expression_selector.select_suitable_expressions_llm(self.subheartflow_id, chat_info, max_num=12, min_num=2)
selected_expressions = await expression_selector.select_suitable_expressions_llm(
self.subheartflow_id, chat_info, max_num=12, min_num=2
)
cache_size = len(selected_expressions) if selected_expressions else 0
mode_desc = f"LLM模式已缓存{cache_size}个)"

View File

@@ -292,8 +292,7 @@ class PersonImpressionpProcessor(BaseProcessor):
"message_count": self._count_messages_in_timerange(potential_start_time, message_time),
}
segments.append(new_segment)
person_name = get_person_info_manager().get_value(person_id, "person_name")
logger.info(
f"{self.log_prefix} 眼熟用户 {person_name}{time.strftime('%H:%M:%S', time.localtime(potential_start_time))} - {time.strftime('%H:%M:%S', time.localtime(message_time))} 之间有 {new_segment['message_count']} 条消息"

View File

@@ -1000,7 +1000,9 @@ class NormalChat:
"""
# --- 1. 定义参数 ---
evaluation_minutes = 10.0
target_replies_per_min = global_config.chat.get_current_talk_frequency(self.stream_id) # 目标频率e.g. 1条/分钟
target_replies_per_min = global_config.chat.get_current_talk_frequency(
self.stream_id
) # 目标频率e.g. 1条/分钟
target_replies_in_window = target_replies_per_min * evaluation_minutes # 10分钟内的目标回复数
if target_replies_in_window <= 0:

View File

@@ -162,8 +162,10 @@ class PromptBuilder:
read_mark=0.0,
show_actions=True,
)
expressions = await expression_selector.select_suitable_expressions_llm(chat_stream.stream_id, chat_talking_prompt_half, max_num=8, min_num=3)
expressions = await expression_selector.select_suitable_expressions_llm(
chat_stream.stream_id, chat_talking_prompt_half, max_num=8, min_num=3
)
style_habbits = []
grammar_habbits = []
if expressions:

View File

@@ -103,10 +103,10 @@ class ChatConfig(ConfigBase):
def get_current_talk_frequency(self, chat_stream_id: str = None) -> float:
"""
根据当前时间和聊天流获取对应的 talk_frequency
Args:
chat_stream_id: 聊天流ID格式为 "platform:chat_id:type"
Returns:
float: 对应的频率值
"""
@@ -115,31 +115,32 @@ class ChatConfig(ConfigBase):
stream_frequency = self._get_stream_specific_frequency(chat_stream_id)
if stream_frequency is not None:
return stream_frequency
# 如果没有聊天流特定配置,检查全局时段配置
if self.time_based_talk_frequency:
global_frequency = self._get_time_based_frequency(self.time_based_talk_frequency)
if global_frequency is not None:
return global_frequency
# 如果都没有匹配,返回默认值
return self.talk_frequency
def _get_time_based_frequency(self, time_freq_list: list[str]) -> float:
"""
根据时间配置列表获取当前时段的频率
Args:
time_freq_list: 时间频率配置列表,格式为 ["HH:MM,frequency", ...]
Returns:
float: 频率值,如果没有配置则返回 None
"""
from datetime import datetime
current_time = datetime.now().strftime("%H:%M")
current_hour, current_minute = map(int, current_time.split(":"))
current_minutes = current_hour * 60 + current_minute
# 解析时间频率配置
time_freq_pairs = []
for time_freq_str in time_freq_list:
@@ -151,13 +152,13 @@ class ChatConfig(ConfigBase):
time_freq_pairs.append((minutes, frequency))
except (ValueError, IndexError):
continue
if not time_freq_pairs:
return None
# 按时间排序
time_freq_pairs.sort(key=lambda x: x[0])
# 查找当前时间对应的频率
current_frequency = None
for minutes, frequency in time_freq_pairs:
@@ -165,20 +166,20 @@ class ChatConfig(ConfigBase):
current_frequency = frequency
else:
break
# 如果当前时间在所有配置时间之前,使用最后一个时间段的频率(跨天逻辑)
if current_frequency is None and time_freq_pairs:
current_frequency = time_freq_pairs[-1][1]
return current_frequency
def _get_stream_specific_frequency(self, chat_stream_id: str) -> float:
"""
获取特定聊天流在当前时间的频率
Args:
chat_stream_id: 聊天流ID哈希值
Returns:
float: 频率值,如果没有配置则返回 None
"""
@@ -186,30 +187,30 @@ class ChatConfig(ConfigBase):
for config_item in self.talk_frequency_adjust:
if not config_item or len(config_item) < 2:
continue
stream_config_str = config_item[0] # 例如 "qq:1026294844:group"
# 解析配置字符串并生成对应的 chat_id
config_chat_id = self._parse_stream_config_to_chat_id(stream_config_str)
if config_chat_id is None:
continue
# 比较生成的 chat_id
if config_chat_id != chat_stream_id:
continue
# 使用通用的时间频率解析方法
return self._get_time_based_frequency(config_item[1:])
return None
def _parse_stream_config_to_chat_id(self, stream_config_str: str) -> str:
"""
解析流配置字符串并生成对应的 chat_id
Args:
stream_config_str: 格式为 "platform:id:type" 的字符串
Returns:
str: 生成的 chat_id如果解析失败则返回 None
"""
@@ -217,23 +218,24 @@ class ChatConfig(ConfigBase):
parts = stream_config_str.split(":")
if len(parts) != 3:
return None
platform = parts[0]
id_str = parts[1]
id_str = parts[1]
stream_type = parts[2]
# 判断是否为群聊
is_group = stream_type == "group"
# 使用与 ChatStream.get_stream_id 相同的逻辑生成 chat_id
import hashlib
if is_group:
components = [platform, str(id_str)]
else:
components = [platform, str(id_str), "private"]
key = "_".join(components)
return hashlib.md5(key.encode()).hexdigest()
except (ValueError, IndexError):
return None