fix(prompt): 修复抗审查指令被无条件添加的问题
在之前的提交中,抗审查指令被错误地设置为无条件添加。本次提交修正了此逻辑,将其与 `enable_prompt_perturbation` 开关关联,确保只有在启用提示词扰动时才会添加该指令,恢复了预期的行为。 此外,还简化了反截断指令的条件判断,直接访问 `model_info.anti_truncation` 属性以提高代码的可读性。
This commit is contained in:
@@ -500,7 +500,8 @@ class _PromptProcessor:
|
|||||||
final_prompt_parts = []
|
final_prompt_parts = []
|
||||||
user_prompt = prompt
|
user_prompt = prompt
|
||||||
|
|
||||||
# 步骤 A: (可选) 添加抗审查指令
|
# 步骤 A: 添加抗审查指令
|
||||||
|
if model_info.enable_prompt_perturbation:
|
||||||
final_prompt_parts.append(self.noise_instruction)
|
final_prompt_parts.append(self.noise_instruction)
|
||||||
|
|
||||||
# 步骤 B: (可选) 应用统一的提示词扰动
|
# 步骤 B: (可选) 应用统一的提示词扰动
|
||||||
@@ -515,7 +516,7 @@ class _PromptProcessor:
|
|||||||
final_prompt_parts.append(user_prompt)
|
final_prompt_parts.append(user_prompt)
|
||||||
|
|
||||||
# 步骤 C: (可选) 添加反截断指令
|
# 步骤 C: (可选) 添加反截断指令
|
||||||
if getattr(model_info, "use_anti_truncation", False):
|
if model_info.anti_truncation:
|
||||||
final_prompt_parts.append(self.anti_truncation_instruction)
|
final_prompt_parts.append(self.anti_truncation_instruction)
|
||||||
logger.info(f"模型 '{model_info.name}' (任务: '{task_name}') 已启用反截断功能。")
|
logger.info(f"模型 '{model_info.name}' (任务: '{task_name}') 已启用反截断功能。")
|
||||||
|
|
||||||
@@ -881,7 +882,7 @@ class _RequestStrategy:
|
|||||||
|
|
||||||
# --- 响应内容处理和空回复/截断检查 ---
|
# --- 响应内容处理和空回复/截断检查 ---
|
||||||
content = response.content or ""
|
content = response.content or ""
|
||||||
use_anti_truncation = getattr(model_info, "use_anti_truncation", False)
|
use_anti_truncation = model_info.anti_truncation
|
||||||
processed_content, reasoning, is_truncated = await self.prompt_processor.process_response(
|
processed_content, reasoning, is_truncated = await self.prompt_processor.process_response(
|
||||||
content, use_anti_truncation
|
content, use_anti_truncation
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user