🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -170,7 +170,7 @@ class ExpressionSelector:
|
||||
"""使用LLM选择适合的表达方式"""
|
||||
|
||||
# 1. 获取35个随机表达方式(现在按权重抽取)
|
||||
style_exprs, grammar_exprs= self.get_random_expressions(chat_id, 50, 0.5, 0.5)
|
||||
style_exprs, grammar_exprs = self.get_random_expressions(chat_id, 50, 0.5, 0.5)
|
||||
|
||||
# 2. 构建所有表达方式的索引和情境列表
|
||||
all_expressions = []
|
||||
@@ -192,7 +192,6 @@ class ExpressionSelector:
|
||||
all_expressions.append(expr_with_type)
|
||||
all_situations.append(f"{len(all_expressions)}.{expr['situation']}")
|
||||
|
||||
|
||||
if not all_expressions:
|
||||
logger.warning("没有找到可用的表达方式")
|
||||
return []
|
||||
|
||||
@@ -74,9 +74,7 @@ class ExpressionLearner:
|
||||
)
|
||||
self.llm_model = None
|
||||
|
||||
def get_expression_by_chat_id(
|
||||
self, chat_id: str
|
||||
) -> Tuple[List[Dict[str, str]], List[Dict[str, str]]]:
|
||||
def get_expression_by_chat_id(self, chat_id: str) -> Tuple[List[Dict[str, str]], List[Dict[str, str]]]:
|
||||
"""
|
||||
获取指定chat_id的style和grammar表达方式
|
||||
返回的每个表达方式字典中都包含了source_id, 用于后续的更新操作
|
||||
@@ -110,7 +108,6 @@ class ExpressionLearner:
|
||||
except Exception as e:
|
||||
logger.error(f"读取grammar表达方式失败: {e}")
|
||||
|
||||
|
||||
return learnt_style_expressions, learnt_grammar_expressions
|
||||
|
||||
def is_similar(self, s1: str, s2: str) -> bool:
|
||||
|
||||
@@ -88,9 +88,6 @@ async def _calculate_interest(message: MessageRecv) -> Tuple[float, bool]:
|
||||
return interested_rate, is_mentioned
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class HeartFCMessageReceiver:
|
||||
"""心流处理器,负责处理接收到的消息并计算兴趣度"""
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ if ENABLE_S4U_CHAT:
|
||||
# 配置主程序日志格式
|
||||
logger = get_logger("chat")
|
||||
|
||||
|
||||
def _check_ban_words(text: str, chat: ChatStream, userinfo: UserInfo) -> bool:
|
||||
"""检查消息是否包含过滤词
|
||||
|
||||
@@ -71,6 +72,7 @@ def _check_ban_regex(text: str, chat: ChatStream, userinfo: UserInfo) -> bool:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class ChatBot:
|
||||
def __init__(self):
|
||||
self.bot = None # bot 实例引用
|
||||
@@ -179,15 +181,15 @@ class ChatBot:
|
||||
return
|
||||
|
||||
get_chat_manager().register_message(message)
|
||||
|
||||
|
||||
chat = await get_chat_manager().get_or_create_stream(
|
||||
platform=message.message_info.platform,
|
||||
user_info=user_info,
|
||||
group_info=group_info,
|
||||
)
|
||||
|
||||
|
||||
message.update_chat_stream(chat)
|
||||
|
||||
|
||||
# 过滤检查
|
||||
if _check_ban_words(message.processed_plain_text, chat, user_info) or _check_ban_regex(
|
||||
message.raw_message, chat, user_info
|
||||
|
||||
@@ -424,7 +424,7 @@ class DefaultReplyer:
|
||||
Returns:
|
||||
str: 工具信息字符串
|
||||
"""
|
||||
|
||||
|
||||
if not reply_data:
|
||||
return ""
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ class ExpressionConfig(ConfigBase):
|
||||
|
||||
enable_expression: bool = True
|
||||
"""是否启用表达方式"""
|
||||
|
||||
|
||||
expression_style: str = ""
|
||||
"""表达风格"""
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ class S4UChat:
|
||||
f"@{alias}" in message.processed_plain_text for alias in global_config.bot.alias_names
|
||||
):
|
||||
score += self.at_bot_priority_bonus
|
||||
|
||||
|
||||
# 加上用户的固有兴趣分
|
||||
score += self._get_interest_score(message.message_info.user_info.user_id)
|
||||
return score
|
||||
@@ -196,7 +196,7 @@ class S4UChat:
|
||||
async def add_message(self, message: MessageRecv) -> None:
|
||||
"""根据VIP状态和中断逻辑将消息放入相应队列。"""
|
||||
is_vip = self._is_vip(message)
|
||||
new_priority = self._get_message_priority(message)
|
||||
self._get_message_priority(message)
|
||||
|
||||
should_interrupt = False
|
||||
if self._current_generation_task and not self._current_generation_task.done():
|
||||
@@ -236,7 +236,7 @@ class S4UChat:
|
||||
# asyncio.PriorityQueue 是最小堆,所以我们存入分数的相反数
|
||||
# 这样,原始分数越高的消息,在队列中的优先级数字越小,越靠前
|
||||
item = (-new_priority_score, self._entry_counter, time.time(), message)
|
||||
|
||||
|
||||
if is_vip:
|
||||
await self._vip_queue.put(item)
|
||||
logger.info(f"[{self.stream_name}] VIP message added to queue.")
|
||||
@@ -245,7 +245,9 @@ class S4UChat:
|
||||
if self._normal_queue.qsize() >= self.normal_queue_max_size:
|
||||
# 队列已满,简单忽略新消息
|
||||
# 更复杂的逻辑(如替换掉队列中优先级最低的)对于 asyncio.PriorityQueue 来说实现复杂
|
||||
logger.debug(f"[{self.stream_name}] Normal queue is full, ignoring new message from {message.message_info.user_info.user_id}")
|
||||
logger.debug(
|
||||
f"[{self.stream_name}] Normal queue is full, ignoring new message from {message.message_info.user_info.user_id}"
|
||||
)
|
||||
return
|
||||
|
||||
await self._normal_queue.put(item)
|
||||
|
||||
Reference in New Issue
Block a user