perf(methods): 通过移除不必要的 self 参数优化方法签名

在包括 chat、plugin_system、schedule 和 mais4u 在内的多个模块中,消除冗余的实例引用。此次改动将无需访问实例状态的实用函数转换为静态方法,从而提升了内存效率,并使方法依赖关系更加清晰。
This commit is contained in:
雅诺狐
2025-09-20 10:55:06 +08:00
parent 0cc4f5bb27
commit 898208f425
111 changed files with 643 additions and 467 deletions

View File

@@ -58,7 +58,7 @@ class MessageBuilder:
self,
image_format: str,
image_base64: str,
support_formats: list[str] = SUPPORTED_IMAGE_FORMATS, # 默认支持格式
support_formats=None, # 默认支持格式
) -> "MessageBuilder":
"""
添加图片内容
@@ -66,6 +66,8 @@ class MessageBuilder:
:param image_base64: 图片的base64编码
:return: MessageBuilder对象
"""
if support_formats is None:
support_formats = SUPPORTED_IMAGE_FORMATS
if image_format.lower() not in support_formats:
raise ValueError("不受支持的图片格式")
if not image_base64:

View File

@@ -145,9 +145,9 @@ class LLMUsageRecorder:
LLM使用情况记录器SQLAlchemy版本
"""
@staticmethod
def record_usage_to_database(
self,
model_info: ModelInfo,
model_info: ModelInfo,
model_usage: UsageRecord,
user_id: str,
request_type: str,

View File

@@ -625,9 +625,9 @@ class LLMRequest:
logger.error(f"任务-'{task_name}' 模型-'{model_name}': 未知异常,错误信息-{str(e)}")
return -1, None # 不再重试请求该模型
@staticmethod
def _check_retry(
self,
remain_try: int,
remain_try: int,
retry_interval: int,
can_retry_msg: str,
cannot_retry_msg: str,
@@ -745,7 +745,8 @@ class LLMRequest:
)
return -1, None
def _build_tool_options(self, tools: Optional[List[Dict[str, Any]]]) -> Optional[List[ToolOption]]:
@staticmethod
def _build_tool_options(tools: Optional[List[Dict[str, Any]]]) -> Optional[List[ToolOption]]:
# sourcery skip: extract-method
"""构建工具选项列表"""
if not tools:
@@ -809,7 +810,8 @@ class LLMRequest:
return final_text
def _inject_random_noise(self, text: str, intensity: int) -> str:
@staticmethod
def _inject_random_noise(text: str, intensity: int) -> str:
"""在文本中注入随机乱码"""
import random
import string