refactor(models):统一请求处理并优化响应处理 (refactor/unified_request)

对 `utils_model.py` 中的请求处理逻辑进行重构,创建统一的请求执行方法 `_execute_request`。该方法集中处理请求构建、重试逻辑和响应处理,替代了 `generate_response`、`generate_response_for_image` 和 `generate_response_async` 中的冗余代码。

关键变更:
- 引入 `_execute_request` 作为 API 请求的单一入口
- 新增支持自定义重试策略和响应处理器
- 通过 `_build_payload` 简化图像和文本载荷构建
- 改进错误处理和日志记录
- 移除已弃用的同步方法
- 加入了`max_response_length`以兼容koboldcpp硬编码的默认值500

此次重构在保持现有功能的同时提高了代码可维护性,减少了重复代码
This commit is contained in:
KawaiiYusora
2025-03-06 23:50:14 +08:00
parent ee414eeaaf
commit 11807fda38
7 changed files with 243 additions and 623 deletions

View File

@@ -32,6 +32,8 @@ class BotConfig:
EMOJI_REGISTER_INTERVAL: int = 10 # 表情包注册间隔(分钟)
ban_words = set()
max_response_length: int = 1024 # 最大回复长度
# 模型配置
llm_reasoning: Dict[str, str] = field(default_factory=lambda: {})
@@ -113,6 +115,7 @@ class BotConfig:
config.MODEL_R1_DISTILL_PROBABILITY = response_config.get("model_r1_distill_probability", config.MODEL_R1_DISTILL_PROBABILITY)
config.API_USING = response_config.get("api_using", config.API_USING)
config.API_PAID = response_config.get("api_paid", config.API_PAID)
config.max_response_length = response_config.get("max_response_length", config.max_response_length)
# 加载模型配置
if "model" in toml_dict: