diff --git a/src/llm_models/utils_model.py b/src/llm_models/utils_model.py index d40c42ec0..c3b75d6ef 100644 --- a/src/llm_models/utils_model.py +++ b/src/llm_models/utils_model.py @@ -139,14 +139,15 @@ class LLMRequest: """ # 反截断指令 - self.anti_truncation_instruction = """ + self.end_marker = "###MAI_RESPONSE_END###" + self.anti_truncation_instruction = f""" **【输出完成信令】** -这是一个非常重要的指令,请务必遵守。在你的回复内容完全结束后,请务必在最后另起一行,只写 `[done]` 作为结束标志。 +这是一个非常重要的指令,请务必遵守。在你的回复内容完全结束后,请务必在最后另起一行,只写 `{self.end_marker}` 作为结束标志。 例如: <你的回复内容> -[done] +{self.end_marker} -这有助于我判断你的输出是否被截断。请不要在 `[done]` 前后添加任何其他文字或标点。 +这有助于我判断你的输出是否被截断。请不要在 `{self.end_marker}` 前后添加任何其他文字或标点。 """ async def generate_response_for_image( @@ -300,11 +301,12 @@ class LLMRequest: try: # 检查是否启用反截断 - use_anti_truncation = getattr(api_provider, "anti_truncation", False) + # 检查是否为该模型启用反截断 + use_anti_truncation = getattr(model_info, "use_anti_truncation", False) processed_prompt = prompt if use_anti_truncation: processed_prompt += self.anti_truncation_instruction - logger.info(f"'{model_name}' for task '{self.task_name}' 已启用反截断功能") + logger.info(f"模型 '{model_name}' (任务: '{self.task_name}') 已启用反截断功能。") processed_prompt = self._apply_content_obfuscation(processed_prompt, api_provider) @@ -341,8 +343,8 @@ class LLMRequest: is_empty_reply = not tool_calls and (not content or content.strip() == "") is_truncated = False if use_anti_truncation: - if content.endswith("[done]"): - content = content[:-6].strip() + if content.endswith(self.end_marker): + content = content[: -len(self.end_marker)].strip() else: is_truncated = True diff --git a/template/model_config_template.toml b/template/model_config_template.toml index 5a4e5b677..eadebb00c 100644 --- a/template/model_config_template.toml +++ b/template/model_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "1.2.8" +version = "1.2.9" # 配置文件版本号迭代规则同bot_config.toml @@ -41,7 +41,6 @@ timeout = 30 retry_interval = 10 enable_content_obfuscation = true # 启用内容混淆功能 obfuscation_intensity = 2 # 混淆强度(1-3级,1=低强度,2=中强度,3=高强度) -anti_truncation_instruction = true # 防阶段移到了模型配置里 [[models]] # 模型(可以配置多个) @@ -51,6 +50,7 @@ api_provider = "DeepSeek" # API服务商名称(对应在api_providers price_in = 2.0 # 输入价格(用于API调用统计,单位:元/ M token)(可选,若无该字段,默认值为0) price_out = 8.0 # 输出价格(用于API调用统计,单位:元/ M token)(可选,若无该字段,默认值为0) #force_stream_mode = true # 强制流式输出模式(若模型不支持非流式输出,请取消该注释,启用强制流式输出,若无该字段,默认值为false) +#use_anti_truncation = true # [可选] 启用反截断功能。当模型输出不完整时,系统会自动重试。建议只为有需要的模型(如Gemini)开启。 [[models]] model_identifier = "Pro/deepseek-ai/DeepSeek-V3"