From 38bfdfd7a0d412ba645a04f7f49e170191848f1b Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Tue, 26 Aug 2025 20:45:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor(config):=20=E5=B0=86=E5=8F=8D=E6=88=AA?= =?UTF-8?q?=E6=96=AD=E8=AE=BE=E7=BD=AE=E7=A7=BB=E8=87=B3=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20#=E7=9C=9F=E7=9A=84=E8=83=BD=E7=AE=97refac?= =?UTF-8?q?tor=E5=90=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 反截断(anti-truncation)功能与特定模型的行为和能力更为相关,而不是任务本身的属性。 此更改将该设置从 `TaskConfig` 移动到 `ModelInfo`,以实现更合理的配置分组和更精细的控制。代码逻辑和配置文件模板也已相应更新。 BREAKING CHANGE: `anti_truncation` 配置项已从 `[model_task_config]` 部分移动到 `[[models]]` 下的具体模型配置中。用户需要更新其配置文件以适配新结构。 --- src/config/api_ada_configs.py | 2 +- src/llm_models/utils_model.py | 4 ++-- template/model_config_template.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config/api_ada_configs.py b/src/config/api_ada_configs.py index 839f7ac02..e9989673b 100644 --- a/src/config/api_ada_configs.py +++ b/src/config/api_ada_configs.py @@ -47,6 +47,7 @@ class ModelInfo(ValidatedConfigBase): price_out: float = Field(default=0.0, ge=0, description="每M token输出价格") force_stream_mode: bool = Field(default=False, description="是否强制使用流式输出模式") extra_params: Dict[str, Any] = Field(default_factory=dict, description="额外参数(用于API调用时的额外配置)") + anti_truncation: bool = Field(default=False, description="是否启用反截断功能,防止模型输出被截断") @field_validator('price_in', 'price_out') @classmethod @@ -83,7 +84,6 @@ class TaskConfig(ValidatedConfigBase): max_tokens: int = Field(default=800, description="任务最大输出token数") temperature: float = Field(default=0.7, description="模型温度") concurrency_count: int = Field(default=1, description="并发请求数量") - anti_truncation: bool = Field(default=False, description="是否启用反截断功能,防止模型输出被截断") @field_validator('model_list') @classmethod diff --git a/src/llm_models/utils_model.py b/src/llm_models/utils_model.py index aa53e525f..60c291840 100644 --- a/src/llm_models/utils_model.py +++ b/src/llm_models/utils_model.py @@ -291,12 +291,12 @@ class LLMRequest: model_name = model_info.name # 检查是否启用反截断 - use_anti_truncation = getattr(self.model_for_task, "anti_truncation", False) + use_anti_truncation = getattr(api_provider, "anti_truncation", False) processed_prompt = prompt if use_anti_truncation: processed_prompt += self.anti_truncation_instruction - logger.info(f"任务 '{self.task_name}' 已启用反截断功能") + logger.info(f"{api_provider} '{self.task_name}' 已启用反截断功能") processed_prompt = self._apply_content_obfuscation(processed_prompt, api_provider) diff --git a/template/model_config_template.toml b/template/model_config_template.toml index b40f41c71..b295b9545 100644 --- a/template/model_config_template.toml +++ b/template/model_config_template.toml @@ -41,6 +41,7 @@ timeout = 30 retry_interval = 10 enable_content_obfuscation = true # 启用内容混淆功能 obfuscation_intensity = 2 # 混淆强度(1-3级,1=低强度,2=中强度,3=高强度) +anti_truncation_instruction = true # 防阶段移到了模型配置里 [[models]] # 模型(可以配置多个) @@ -125,7 +126,6 @@ model_list = ["siliconflow-deepseek-v3"] # 使用的模型列表,每个子项 temperature = 0.2 # 模型温度,新V3建议0.1-0.3 max_tokens = 800 # 最大输出token数 #concurrency_count = 2 # 并发请求数量,默认为1(不并发),设置为2或更高启用并发 -#anti_truncation = true # 启用反截断功能,防止模型输出被截断 [model_task_config.utils_small] # 在麦麦的一些组件中使用的小模型,消耗量较大,建议使用速度较快的小模型 model_list = ["qwen3-8b"]