ruff 哥又有新点子
This commit is contained in:
@@ -87,7 +87,7 @@ class ReasoningGUI:
|
||||
self.db = Database.get_instance().db
|
||||
logger.success("数据库初始化成功")
|
||||
except Exception:
|
||||
logger.exception(f"数据库初始化失败")
|
||||
logger.exception("数据库初始化失败")
|
||||
sys.exit(1)
|
||||
|
||||
# 存储群组数据
|
||||
@@ -342,7 +342,7 @@ class ReasoningGUI:
|
||||
'group_id': self.selected_group_id
|
||||
})
|
||||
except Exception:
|
||||
logger.exception(f"自动更新出错")
|
||||
logger.exception("自动更新出错")
|
||||
|
||||
# 每5秒更新一次
|
||||
time.sleep(5)
|
||||
|
||||
@@ -129,7 +129,7 @@ class ChatBot:
|
||||
|
||||
# 如果找不到思考消息,直接返回
|
||||
if not thinking_message:
|
||||
logger.warning(f"未找到对应的思考消息,可能已超时被移除")
|
||||
logger.warning("未找到对应的思考消息,可能已超时被移除")
|
||||
return
|
||||
|
||||
# 记录开始思考的时间,避免从思考到回复的时间太久
|
||||
|
||||
@@ -113,7 +113,7 @@ class BotConfig:
|
||||
|
||||
try:
|
||||
converted = SpecifierSet(value)
|
||||
except InvalidSpecifier as e:
|
||||
except InvalidSpecifier:
|
||||
logger.error(
|
||||
f"{value} 分类使用了错误的版本约束表达式\n",
|
||||
"请阅读 https://semver.org/lang/zh-CN/ 修改代码"
|
||||
@@ -135,7 +135,7 @@ class BotConfig:
|
||||
try:
|
||||
config_version: str = toml["inner"]["version"]
|
||||
except KeyError as e:
|
||||
logger.error(f"配置文件中 inner 段 不存在, 这是错误的配置文件")
|
||||
logger.error("配置文件中 inner 段 不存在, 这是错误的配置文件")
|
||||
raise KeyError(f"配置文件中 inner 段 不存在 {e}, 这是错误的配置文件")
|
||||
else:
|
||||
toml["inner"] = {"version": "0.0.0"}
|
||||
@@ -143,7 +143,7 @@ class BotConfig:
|
||||
|
||||
try:
|
||||
ver = version.parse(config_version)
|
||||
except InvalidVersion as e:
|
||||
except InvalidVersion:
|
||||
logger.error(
|
||||
"配置文件中 inner段 的 version 键是错误的版本描述\n"
|
||||
"请阅读 https://semver.org/lang/zh-CN/ 修改配置,并参考本项目指定的模板进行修改\n"
|
||||
|
||||
@@ -155,8 +155,8 @@ class CQCode:
|
||||
logger.error(f"最终请求失败: {str(e)}")
|
||||
time.sleep(1.5 ** retry) # 指数退避
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"[未知错误]")
|
||||
except Exception:
|
||||
logger.exception("[未知错误]")
|
||||
return None
|
||||
|
||||
return None
|
||||
@@ -281,7 +281,7 @@ class CQCode:
|
||||
logger.debug(f"合并后的转发消息: {combined_messages}")
|
||||
return f"[转发消息:\n{combined_messages}]"
|
||||
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.exception("处理转发消息失败")
|
||||
return '[转发消息]'
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ class EmojiManager:
|
||||
self._initialized = True
|
||||
# 启动时执行一次完整性检查
|
||||
self.check_emoji_file_integrity()
|
||||
except Exception as e:
|
||||
logger.exception(f"初始化表情管理器失败")
|
||||
except Exception:
|
||||
logger.exception("初始化表情管理器失败")
|
||||
|
||||
def _ensure_db(self):
|
||||
"""确保数据库已初始化"""
|
||||
@@ -87,8 +87,8 @@ class EmojiManager:
|
||||
{'_id': emoji_id},
|
||||
{'$inc': {'usage_count': 1}}
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception(f"记录表情使用失败")
|
||||
except Exception:
|
||||
logger.exception("记录表情使用失败")
|
||||
|
||||
async def get_emoji_for_text(self, text: str) -> Optional[str]:
|
||||
"""根据文本内容获取相关表情包
|
||||
@@ -264,8 +264,8 @@ class EmojiManager:
|
||||
else:
|
||||
logger.warning(f"跳过表情包: {filename}")
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"扫描表情包失败")
|
||||
except Exception:
|
||||
logger.exception("扫描表情包失败")
|
||||
|
||||
async def _periodic_scan(self, interval_MINS: int = 10):
|
||||
"""定期扫描新表情包"""
|
||||
|
||||
@@ -94,7 +94,7 @@ class ResponseGenerator:
|
||||
try:
|
||||
content, reasoning_content = await model.generate_response(prompt)
|
||||
except Exception:
|
||||
logger.exception(f"生成回复时出错")
|
||||
logger.exception("生成回复时出错")
|
||||
return None
|
||||
|
||||
# 保存到数据库
|
||||
@@ -146,7 +146,7 @@ class ResponseGenerator:
|
||||
return ["neutral"]
|
||||
|
||||
except Exception:
|
||||
logger.exception(f"获取情感标签时出错")
|
||||
logger.exception("获取情感标签时出错")
|
||||
return ["neutral"]
|
||||
|
||||
async def _process_response(self, content: str) -> Tuple[List[str], List[str]]:
|
||||
|
||||
@@ -61,7 +61,7 @@ class Message_Sender:
|
||||
auto_escape=auto_escape
|
||||
)
|
||||
logger.debug(f"发送消息{message}成功")
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.exception(f"发送消息{message}失败")
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ class MessageContainer:
|
||||
return True
|
||||
return False
|
||||
except Exception:
|
||||
logger.exception(f"移除消息时发生错误")
|
||||
logger.exception("移除消息时发生错误")
|
||||
return False
|
||||
|
||||
def has_messages(self) -> bool:
|
||||
@@ -214,7 +214,7 @@ class MessageManager:
|
||||
if not container.remove_message(msg):
|
||||
logger.warning("尝试删除不存在的消息")
|
||||
except Exception:
|
||||
logger.exception(f"处理超时消息时发生错误")
|
||||
logger.exception("处理超时消息时发生错误")
|
||||
continue
|
||||
|
||||
async def start_processor(self):
|
||||
|
||||
@@ -45,6 +45,6 @@ class MessageStorage:
|
||||
|
||||
self.db.db.messages.insert_one(message_data)
|
||||
except Exception:
|
||||
logger.exception(f"存储消息失败")
|
||||
logger.exception("存储消息失败")
|
||||
|
||||
# 如果需要其他存储相关的函数,可以在这里添加
|
||||
|
||||
@@ -44,8 +44,8 @@ class LLM_request:
|
||||
self.db.db.llm_usage.create_index([("model_name", 1)])
|
||||
self.db.db.llm_usage.create_index([("user_id", 1)])
|
||||
self.db.db.llm_usage.create_index([("request_type", 1)])
|
||||
except Exception as e:
|
||||
logger.error(f"创建数据库索引失败")
|
||||
except Exception:
|
||||
logger.error("创建数据库索引失败")
|
||||
|
||||
def _record_usage(self, prompt_tokens: int, completion_tokens: int, total_tokens: int,
|
||||
user_id: str = "system", request_type: str = "chat",
|
||||
@@ -80,7 +80,7 @@ class LLM_request:
|
||||
f"总计: {total_tokens}"
|
||||
)
|
||||
except Exception:
|
||||
logger.error(f"记录token使用情况失败")
|
||||
logger.error("记录token使用情况失败")
|
||||
|
||||
def _calculate_cost(self, prompt_tokens: int, completion_tokens: int) -> float:
|
||||
"""计算API调用成本
|
||||
@@ -194,7 +194,7 @@ class LLM_request:
|
||||
if hasattr(global_config, 'llm_normal') and global_config.llm_normal.get(
|
||||
'name') == old_model_name:
|
||||
global_config.llm_normal['name'] = self.model_name
|
||||
logger.warning(f"已将全局配置中的 llm_normal 模型降级")
|
||||
logger.warning("已将全局配置中的 llm_normal 模型降级")
|
||||
|
||||
# 更新payload中的模型名
|
||||
if payload and 'model' in payload:
|
||||
@@ -227,7 +227,7 @@ class LLM_request:
|
||||
delta_content = ""
|
||||
accumulated_content += delta_content
|
||||
except Exception:
|
||||
logger.exception(f"解析流式输出错")
|
||||
logger.exception("解析流式输出错")
|
||||
content = accumulated_content
|
||||
reasoning_content = ""
|
||||
think_match = re.search(r'<think>(.*?)</think>', content, re.DOTALL)
|
||||
@@ -355,7 +355,7 @@ class LLM_request:
|
||||
"""构建请求头"""
|
||||
if no_key:
|
||||
return {
|
||||
"Authorization": f"Bearer **********",
|
||||
"Authorization": "Bearer **********",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
else:
|
||||
|
||||
@@ -91,7 +91,7 @@ class ScheduleGenerator:
|
||||
try:
|
||||
schedule_dict = json.loads(schedule_text)
|
||||
return schedule_dict
|
||||
except json.JSONDecodeError as e:
|
||||
except json.JSONDecodeError:
|
||||
logger.exception("解析日程失败: {}".format(schedule_text))
|
||||
return False
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ class LLMStatistics:
|
||||
all_stats = self._collect_all_statistics()
|
||||
self._save_statistics(all_stats)
|
||||
except Exception:
|
||||
logger.exception(f"统计数据处理失败")
|
||||
logger.exception("统计数据处理失败")
|
||||
|
||||
# 等待1分钟
|
||||
for _ in range(60):
|
||||
|
||||
Reference in New Issue
Block a user